summaryrefslogtreecommitdiff
path: root/prge_camera.c
diff options
context:
space:
mode:
Diffstat (limited to 'prge_camera.c')
-rw-r--r--prge_camera.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/prge_camera.c b/prge_camera.c
index 242b33d..0a79a74 100644
--- a/prge_camera.c
+++ b/prge_camera.c
@@ -1,30 +1,26 @@
-Camera camera_init(V3 pos, F32 fov, F32 near, F32 far,
- F32 yaw, F32 pitch, F32 roll)
+Camera initcam(V3 pos, F32 fov, F32 near, F32 far, F32 yaw, F32 pitch, F32 roll)
{
- Camera c;
-
- c.pos = pos;
- c.fov = fov;
- c.near = near;
- c.far = far;
- c.yaw = yaw;
- c.pitch = pitch;
- c.roll = roll;
-
+ Camera c = {
+ .pos = pos,
+ .fov = fov,
+ .near = near,
+ .far = far,
+ .yaw = yaw,
+ .pitch = pitch,
+ .roll = roll,
+ };
return c;
}
-MAT4 camera_get_view_matrix_first_person(Camera *c)
+MAT4 getfpviewmat(Camera *c)
{
MAT4 v;
-
- v = mat4transl(MAT4_IDENTITY, v3inv(c->pos));
- v = mat4rotate(v, v3(c->pitch, c->yaw, c->roll));
-
+ v = translmat4(MAT4_IDENTITY, invv3(c->pos));
+ v = rotatemat4(v, v3(c->pitch, c->yaw, c->roll));
return v;
}
-void camera_get_vectors_first_person(Camera *c, V3 *r, V3 *u, V3 *f)
+void getfpvecs(Camera *c, V3 *l, V3 *u, V3 *f)
{
F32 angle, cp, sp, cy, sy, cr, sr;
@@ -38,23 +34,23 @@ void camera_get_vectors_first_person(Camera *c, V3 *r, V3 *u, V3 *f)
cr = f32cos(angle);
sr = f32sin(angle);
- *r = v3(cy*cr, -cy*sr, sy);
+ *l = v3(cy*cr, -cy*sr, sy);
*u = v3(sp*sy*cr+cp*sr, -sp*sy*sr+cp*cr, -sp*cy);
*f = v3(-cp*sy*cr+sp*sr, cp*sy*sr+sp*cr, cp*cy);
}
-MAT4 camera_look_at(Camera c, V3 t, V3 wup)
+MAT4 lookat(Camera c, V3 t, V3 wup)
{
V3 f, r, u;
MAT4 transl, rotate, res;
- f = v3norm(v3sub(c.pos, t));
- r = v3norm(v3cross(wup, f));
- u = v3cross(f, r);
+ f = normv3(subv3(c.pos, t));
+ r = normv3(crossv3(wup, f));
+ u = crossv3(f, r);
- transl = mat4transl(MAT4_IDENTITY, v3inv(c.pos));
- rotate = mat4transp(mat4_change_basis(r, u, f));
- res = mat4mul(rotate, transl);
+ transl = translmat4(MAT4_IDENTITY, invv3(c.pos));
+ rotate = transpmat4(rotateaxismat4(r, u, f));
+ res = mulmat4(rotate, transl);
return res;
}