Add camera module
This commit is contained in:
parent
9cc9626146
commit
87b3ca0efc
3 changed files with 70 additions and 0 deletions
|
@ -6,6 +6,7 @@ Import('env')
|
|||
|
||||
files = Split("""
|
||||
basics.c
|
||||
camera.c
|
||||
charles.c
|
||||
scene.c
|
||||
""")
|
||||
|
|
38
src/camera.c
Normal file
38
src/camera.c
Normal 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
31
src/camera.h
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue