From c564791d1a73a0305173cf9de91ef1f222666630 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 20 Jul 2014 12:37:04 -0700 Subject: [PATCH] Camera doesn't inherit from Object; defines its own origin. --- src/camera.cc | 25 +++++++++++++++++++++++-- src/camera.h | 18 ++++++++++++------ src/yaml/cameraParser.cc | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/camera.cc b/src/camera.cc index 111223f..0617f46 100644 --- a/src/camera.cc +++ b/src/camera.cc @@ -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()); diff --git a/src/camera.h b/src/camera.h index 462a1b6..1cf73e2 100644 --- a/src/camera.h +++ b/src/camera.h @@ -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; diff --git a/src/yaml/cameraParser.cc b/src/yaml/cameraParser.cc index 6e2b925..9b9086e 100644 --- a/src/yaml/cameraParser.cc +++ b/src/yaml/cameraParser.cc @@ -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); };