Camera doesn't inherit from Object; defines its own origin.

This commit is contained in:
Eryn Wells 2014-07-20 12:37:04 -07:00
parent 709453adcb
commit c564791d1a
3 changed files with 36 additions and 9 deletions

View file

@ -29,6 +29,27 @@ Camera::~Camera()
{ }
/*
* Camera::GetOrigin --
*/
const Vector3&
Camera::GetOrigin()
const
{
return mOrigin;
}
/*
* Camera::SetOrigin --
*/
void
Camera::SetOrigin(const Vector3 &origin)
{
mOrigin = origin;
}
const Vector3&
Camera::get_direction()
const
@ -101,7 +122,7 @@ PerspectiveCamera::compute_primary_ray(const int x,
Vector3 direction = LinearCombination(1.0, get_direction(),
x0, GetRight(),
y0, GetUp());
return Ray(get_origin(), direction);
return Ray(GetOrigin(), direction);
}
#pragma mark - Orthographic Camera
@ -139,7 +160,7 @@ OrthographicCamera::compute_primary_ray(const int x,
double x0 = (x + 0.5) / width + 0.5;
double y0 = ((height - 1.0) - (y - 0.5)) / height - 0.5;
Vector3 origin = LinearCombination(1.0, get_origin(),
Vector3 origin = LinearCombination(1.0, GetOrigin(),
x0, GetRight(),
y0, GetUp());
return Ray(origin, get_direction());

View file

@ -11,23 +11,23 @@
#define __CAMERA_H__
#include "basics.h"
#include "object.h"
struct Camera
: public Object
{
public:
Camera();
Camera(const Camera& other);
virtual ~Camera();
const Vector3 &get_direction() const;
void set_direction(const Vector3 &d);
float get_angle() const;
const Vector3& GetOrigin() const;
void SetOrigin(const Vector3& origin);
const Vector3& get_direction() const;
void set_direction(const Vector3& direction);
const Vector3& GetRight() const;
void SetRight(const Vector3& right);
const Vector3& GetUp() const;
void SetUp(const Vector3& up);
@ -35,6 +35,12 @@ public:
const int y, const int height) const = 0;
private:
/**
* The location of the camera in the scene. Depending on the type of camera,
* this is the point from which rays will be emitted.
*/
Vector3 mOrigin;
/** A normalized vector defining where the camera is pointed. */
Vector3 mDirection;

View file

@ -102,7 +102,7 @@ CameraParser::HandleOriginEvent(yaml_event_t& event)
}
auto onDone = [this](Vector3 origin) {
mCamera->set_origin(origin);
mCamera->SetOrigin(origin);
mSection = NoSection;
SetShouldExpectKey(true);
};