Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created November 15, 2016 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmwaffles/eb9e70c2718a50c4fb119861cb493e0b to your computer and use it in GitHub Desktop.
Save warmwaffles/eb9e70c2718a50c4fb119861cb493e0b to your computer and use it in GitHub Desktop.
struct mat4f
gfx_camera_get_combined(struct gfx_camera* camera)
{
assert(camera);
struct mat4f ortho;
struct mat4f translation;
struct mat4f zoom;
float vw = camera->viewport.width;
float vh = camera->viewport.height;
float x = camera->position.x;
float y = camera->position.y;
float z = camera->position.z;
ortho = mat4f_ortho(
-vw / 2,
vw / 2,
-vh / 2,
vh / 2,
camera->near,
camera->far
);
translation = mat4f_translation(-x, -y, -z);
zoom = mat4f_zoom(camera->zoom, camera->zoom, camera->zoom);
return mat4f_mul(ortho, mat4f_mul(zoom, translation));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment