zoukankan      html  css  js  c++  java
  • Camera类定义和实现

    类声明:

    #pragma once
    #ifndef __CAMERA_HEADER__
    #define __CAMERA_HEADER__
    
    #include "../utilities/geometry.h"
    
    class World;
    
    class Camera {
    public:
    	Camera();
    	Camera(const Camera& cam);
    	~Camera();
    	void set_eye(const Point3& p);
    	void set_lookat(const Point3& p);
    	void set_up(const Vector3& v);
    	void set_roll(const ldouble a);
    	void set_exposure_time(const ldouble t);
    	void compute_uvw();
    	virtual Camera* clone() const = 0;
    	virtual void render_scene(World& w) = 0;
    	Camera& operator=(const Camera& cam);
    protected:
    	Point3 eye, lookat;
    	Vector3 up, u, v, w;
    	ldouble exposure_time, ra;
    };
    
    #endif  

    类实现:

    #include "pch.h"
    #include "camera.h"
    
    Camera::Camera()
    	:eye(0, 0, 1), lookat(0), ra(0), up(0, 1, 0), u(1, 0, 0), v(0, 1, 0), w(0, 0, 1), exposure_time(1) {}
    
    Camera::Camera(const Camera& cam)
    	: eye(cam.eye), lookat(cam.lookat), ra(cam.ra), up(cam.up), 
    	u(cam.u), v(cam.v), w(cam.w), exposure_time(cam.exposure_time) {}
    
    Camera::~Camera() {}
    
    void Camera::set_eye(const Point3& p) {
    	eye = p;
    }
    
    void Camera::set_lookat(const Point3& p) {
    	lookat = p;
    }
    
    void Camera::set_up(const Vector3& v) {
    	up = v;
    }
    
    void Camera::set_roll(const ldouble a) {
    	ra = a;
    }
    
    void Camera::set_exposure_time(const ldouble t) {
    	exposure_time = t;
    }
    
    void Camera::compute_uvw() {
    	w = eye - lookat;
    	w.normalize();
    	u = up ^ w;
    	u.normalize();
    	v = w ^ u;
    	if (eye.x == lookat.x && eye.z == lookat.z && eye.y > lookat.y) { // camera looking vertically down
    		u = Vector3(0, 0, 1);
    		v = Vector3(1, 0, 0);
    		w = Vector3(0, 1, 0);
    	}
    	if (eye.x == lookat.x && eye.z == lookat.z && eye.y < lookat.y) { // camera looking vertically up
    		u = Vector3(1, 0, 0);
    		v = Vector3(0, 0, 1);
    		w = Vector3(0, -1, 0);
    	}
    }
    
    Camera& Camera::operator=(const Camera& cam) {
    	if (this == &cam)
    		return *this;
    	eye = cam.eye;
    	lookat = cam.lookat;
    	ra = cam.ra;
    	up = cam.up;
    	u = cam.u;
    	v = cam.v;
    	w = cam.w;
    	exposure_time = cam.exposure_time;
    	return *this;
    }
    

     

  • 相关阅读:
    MySQL-[--001--]-MySQL涉及的算法题
    Python3-2020-测试开发-25- 操作数据库(MySQL)
    Python3-2020-测试开发-24- os模块及os.path
    Python3-接口自动化-7-读取Excel封装方法
    Charles-2020-抓取Https包
    Python3-2020-测试开发-23- 文件操作
    Django模板(Template)系统
    Django视图系统
    Django路由系统
    Django框架
  • 原文地址:https://www.cnblogs.com/dalgleish/p/12650806.html
Copyright © 2011-2022 走看看