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());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue