Add camera module

This commit is contained in:
Eryn Wells 2013-09-06 19:00:28 -07:00
parent 9cc9626146
commit 87b3ca0efc
3 changed files with 70 additions and 0 deletions

View file

@ -6,6 +6,7 @@ Import('env')
files = Split("""
basics.c
camera.c
charles.c
scene.c
""")

38
src/camera.c Normal file
View file

@ -0,0 +1,38 @@
/* 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);
}

31
src/camera.h Normal file
View file

@ -0,0 +1,31 @@
/* camera.h
*
* Camera type and related functions.
*
* Eryn Wells <eryn@erynwells.me>
*/
#ifndef __CAMERA_H
#define __CAMERA_H
#include "basics.h"
typedef enum {
CameraProjectionOrthographic = 1,
} CameraProjection;
typedef struct _Camera
{
CameraProjection projection;
Vector3 location;
Rect image_plane;
} Camera;
Camera *camera_init();
void camera_destroy(Camera *camera);
#endif