-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.h
53 lines (46 loc) · 1.29 KB
/
camera.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef RENDER_CAMERA_H
#define RENDER_CAMERA_H
#include "common.h"
#include "matrix.h"
#include "vector.h"
/**
* eye: Represent "camera position" in world space
* at: Represent "target position" in world space
* up_v: Represent "up direction" (unit vector)
*
* forward -> (z axis) = (eye - at) / |eye - at|
* right -> (x axis) = (up_v x forward) / |up_v x forward|
* up -> (y axis) = forward x right
* NOTE: x is cross product operator in these formula.
*
* Rotation matrix -> r
* | xx yx zx 0 |
* | xy yy zy 0 |
* | xz yz zz 0 |
* | 0 0 0 1 |
*
* Translation matrix -> t
* | 1 0 0 0 |
* | 0 1 0 0 |
* | 0 0 1 0 |
* | -eye.x -eye.y -eye.z 1 |
*
* world2eye = (r.t)^-1
*/
typedef struct tagCamera {
Vector eye;
Vector at;
Vector up_v;
uint16_t image_width;
uint16_t image_height;
Real fov; // perspective projection
Real near, far;
Matrix *world2camera;
Matrix *camera2ndc;
Matrix *world2ndc;
Matrix *ndc2world;
} Camera;
Camera *CameraPerspectiveProjection(Vector eye, Vector at, Vector up_v, uint16_t image_width, uint16_t image_height, Real near, Real far, Real fov);
bool CameraDestroy(Camera *camera);
Vector CameraGetDirection(const Camera *camera, Vector position);
#endif // RENDER_CAMERA_H