Clean up camera module
This commit is contained in:
parent
41327c92fd
commit
daf5c7d8a6
2 changed files with 25 additions and 56 deletions
|
@ -12,9 +12,7 @@
|
|||
#pragma mark - Generic Camera
|
||||
|
||||
Camera::Camera()
|
||||
: height(Vector3::Y),
|
||||
width(4.0 / 3.0 * Vector3::X),
|
||||
direction(Vector3::Z),
|
||||
: direction(Vector3::Z),
|
||||
mRight(1.33, 0, 0),
|
||||
mUp(Vector3::Y)
|
||||
{ }
|
||||
|
@ -24,41 +22,6 @@ Camera::~Camera()
|
|||
{ }
|
||||
|
||||
|
||||
/*
|
||||
* Camera::get_width --
|
||||
* Camera::set_width --
|
||||
* Camera::get_height --
|
||||
* Camera::set_height --
|
||||
*
|
||||
* Get and set width and height vectors.
|
||||
*/
|
||||
const Vector3 &
|
||||
Camera::get_width()
|
||||
const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
void
|
||||
Camera::set_width(const Vector3 &w)
|
||||
{
|
||||
width = w;
|
||||
}
|
||||
|
||||
const Vector3 &
|
||||
Camera::get_height()
|
||||
const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
void
|
||||
Camera::set_height(const Vector3 &h)
|
||||
{
|
||||
height = h;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Camera::get_direction --
|
||||
* Camera::set_direction --
|
||||
|
@ -148,13 +111,15 @@ OrthographicCamera::compute_primary_ray(const int x,
|
|||
const int height)
|
||||
const
|
||||
{
|
||||
// Calculate the point on the image plane that the given (x,y) coordinate pair corresponds to.
|
||||
float dir_x = (x / width) + 0.5;
|
||||
float dir_y = (y / height) + 0.5;
|
||||
Vector3 ray_origin = (dir_x * get_width()) + (dir_y * get_height()) + get_direction();
|
||||
/*
|
||||
* Center x and y in the pixel and convert them to be coordinates between
|
||||
* -0.5 and 0.5.
|
||||
*/
|
||||
double x0 = (x + 0.5) / width + 0.5;
|
||||
double y0 = ((height - 1.0) - (y - 0.5)) / height - 0.5;
|
||||
|
||||
// Calculate the direction of the ray, given the camera's origin and normalize that vector.
|
||||
Vector3 ray_direction = (ray_origin - get_origin()).normalize();
|
||||
|
||||
return Ray(ray_origin, ray_direction);
|
||||
Vector3 origin = LinearCombination(1.0, get_origin(),
|
||||
x0, GetRight(),
|
||||
y0, GetUp());
|
||||
return Ray(origin, get_direction());
|
||||
}
|
||||
|
|
24
src/camera.h
24
src/camera.h
|
@ -1,7 +1,8 @@
|
|||
/* camera.h
|
||||
*
|
||||
* The Camera is the eye into the scene. It defines several parameters and a single compute_primary_ray method
|
||||
* that generates rays with which the ray tracer draws the scene.
|
||||
* The Camera is the eye into the scene. It defines several parameters and a
|
||||
* single compute_primary_ray method that generates rays with which the ray
|
||||
* tracer draws the scene.
|
||||
*
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
@ -20,10 +21,6 @@ public:
|
|||
Camera();
|
||||
virtual ~Camera();
|
||||
|
||||
const Vector3 &get_width() const;
|
||||
void set_width(const Vector3 &w);
|
||||
const Vector3 &get_height() const;
|
||||
void set_height(const Vector3 &h);
|
||||
const Vector3 &get_direction() const;
|
||||
void set_direction(const Vector3 &d);
|
||||
float get_angle() const;
|
||||
|
@ -37,12 +34,19 @@ public:
|
|||
const int y, const int height) const = 0;
|
||||
|
||||
private:
|
||||
// Size of the image plane.
|
||||
Vector3 height, width;
|
||||
|
||||
// Direction. A normalized vector defining where the camera is pointed.
|
||||
/** A normalized vector defining where the camera is pointed. */
|
||||
Vector3 direction;
|
||||
|
||||
/**
|
||||
* A vector defining the width of the camera's image plane. The ratio of
|
||||
* this and mUp determine the aspect ratio of the image.
|
||||
*/
|
||||
Vector3 mRight;
|
||||
|
||||
/**
|
||||
* A vector defining the height of the camera's image plane. The ratio of
|
||||
* this and mUp determine the aspect ratio of the image.
|
||||
*/
|
||||
Vector3 mUp;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue