Camera stuff -- empty implementations of compute_primary_ray
This commit is contained in:
		
							parent
							
								
									fb6920e923
								
							
						
					
					
						commit
						764afab8ac
					
				
					 4 changed files with 68 additions and 53 deletions
				
			
		|  | @ -6,6 +6,7 @@ Import('env') | ||||||
| 
 | 
 | ||||||
| files = Split(""" | files = Split(""" | ||||||
|     basics.cc |     basics.cc | ||||||
|  |     camera.cc | ||||||
|     light.cc |     light.cc | ||||||
|     material.cc |     material.cc | ||||||
|     object.cc |     object.cc | ||||||
|  |  | ||||||
							
								
								
									
										38
									
								
								src/camera.c
									
										
									
									
									
								
							
							
						
						
									
										38
									
								
								src/camera.c
									
										
									
									
									
								
							|  | @ -1,38 +0,0 @@ | ||||||
| /* camera.c
 |  | ||||||
|  * |  | ||||||
|  * Camera definitions. |  | ||||||
|  * |  | ||||||
|  * Eryn Wells <eryn@erynwells.me> |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| #include <stdlib.h> |  | ||||||
| #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); |  | ||||||
| } |  | ||||||
							
								
								
									
										39
									
								
								src/camera.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/camera.cc
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 <eryn@erynwells.me> | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #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; | ||||||
|  | } | ||||||
							
								
								
									
										43
									
								
								src/camera.h
									
										
									
									
									
								
							
							
						
						
									
										43
									
								
								src/camera.h
									
										
									
									
									
								
							|  | @ -1,31 +1,44 @@ | ||||||
| /* camera.h
 | /* 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 <eryn@erynwells.me> |  * Eryn Wells <eryn@erynwells.me> | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #ifndef __CAMERA_H | #ifndef __CAMERA_H__ | ||||||
| #define __CAMERA_H | #define __CAMERA_H__ | ||||||
| 
 | 
 | ||||||
| #include "basics.h" | #include "basics.h" | ||||||
|  | #include "object.h" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| typedef enum { | class Camera | ||||||
|     CameraProjectionOrthographic = 1, |     : public Object | ||||||
| } CameraProjection; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| typedef struct _Camera |  | ||||||
| { | { | ||||||
|     CameraProjection projection; | public: | ||||||
|     Vector3 location; |     Camera(); | ||||||
|     Rect image_plane; |     ~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(); | class OrthographicCamera | ||||||
| void camera_destroy(Camera *camera); | { | ||||||
|  | public: | ||||||
|  |     Ray compute_primary_ray(const int &x, const int &y) const; | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue