From 764afab8acb1ac86654e3def4db63599ede4817e Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 16 Sep 2013 16:34:48 -0700 Subject: [PATCH] Camera stuff -- empty implementations of compute_primary_ray --- src/SConscript | 1 + src/camera.c | 38 -------------------------------------- src/camera.cc | 39 +++++++++++++++++++++++++++++++++++++++ src/camera.h | 43 ++++++++++++++++++++++++++++--------------- 4 files changed, 68 insertions(+), 53 deletions(-) delete mode 100644 src/camera.c create mode 100644 src/camera.cc diff --git a/src/SConscript b/src/SConscript index 0305912..adc0480 100644 --- a/src/SConscript +++ b/src/SConscript @@ -6,6 +6,7 @@ Import('env') files = Split(""" basics.cc + camera.cc light.cc material.cc object.cc diff --git a/src/camera.c b/src/camera.c deleted file mode 100644 index 2a454ef..0000000 --- a/src/camera.c +++ /dev/null @@ -1,38 +0,0 @@ -/* camera.c - * - * Camera definitions. - * - * Eryn Wells - */ - -#include -#include "camera.h" - - -Camera * -camera_init() -{ - Camera *new_camera = malloc(sizeof(Camera)); - if (new_camera == NULL) { - return NULL; - } - - // Set some useful defaults. - new_camera->projection = CameraProjectionOrthographic; - new_camera->location = vector_init(0, 0, 0); - // The default image plane is a rectangle from (-1, 1) to (1, -1). - new_camera->image_plane = rect_init(-1, 1, 2, 2); - - return new_camera; -} - - -void -camera_destroy(Camera *camera) -{ - if (camera == NULL) { - return; - } - - free(camera); -} diff --git a/src/camera.cc b/src/camera.cc new file mode 100644 index 0000000..52873b0 --- /dev/null +++ b/src/camera.cc @@ -0,0 +1,39 @@ +/* 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. + * + * Eryn Wells + */ + +#include "camera.h" + + +#pragma mark - Generic Camera + +Camera::Camera() + : height(Vector3::Y), + width(4.0 / 3.0 * Vector3::X), + direction(Vector3::Z) +{ } + + +Camera::~Camera() +{ } + +#pragma mark - Orthographic Camera + +/* + * OrthographicCamera::compute_primary_ray -- + * + * Compute a primary ray given an (x,y) coordinate pair. The orthographic camera projects rays parallel to the viewing + * direction through the (x,y) coordinate given. Thus, the size of the orthographic camera should be set to the size of + * the view into the scene. + */ +Ray +OrthographicCamera::compute_primary_ray(const int &x, + const int &y) + const +{ + return 0; +} diff --git a/src/camera.h b/src/camera.h index 0fd6f32..82ec091 100644 --- a/src/camera.h +++ b/src/camera.h @@ -1,31 +1,44 @@ /* camera.h * - * Camera type and related functions. + * 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 */ -#ifndef __CAMERA_H -#define __CAMERA_H +#ifndef __CAMERA_H__ +#define __CAMERA_H__ #include "basics.h" +#include "object.h" -typedef enum { - CameraProjectionOrthographic = 1, -} CameraProjection; - - -typedef struct _Camera +class Camera + : public Object { - CameraProjection projection; - Vector3 location; - Rect image_plane; -} Camera; +public: + Camera(); + ~Camera(); + + virtual Ray compute_primary_ray(const int &x, const int &y) const = 0; + +private: + // Size of the image plane. + Vector3 height, width; + + // Direction. A unit vector defining where the camera is pointed. + Vector3 direction; + + // Horizontal viewing angle. + float angle; +}; -Camera *camera_init(); -void camera_destroy(Camera *camera); +class OrthographicCamera +{ +public: + Ray compute_primary_ray(const int &x, const int &y) const; +}; #endif