Skip to content

rtm/camera_utilsd.h

#include "rtm/camera_utilsd.h"

matrix_look_to

matrix3x4d matrix_look_to(vector4d position, vector4d direction, vector4d up)

Returns a left-handed affine 3x4 matrix representing a camera transform. A camera transform multiplied by a point3 transforms a point3 local to the camera into world space. The camera transform is located at the specified position, looking towards the specified direction, and using the specified up direction.

The look to direction and up inputs do not need to be normalized.

In this frame of reference:

  • X axis: right direction
  • Y axis: up direction
  • Z axis: forward/look direction

matrix_look_at

matrix3x4d matrix_look_at(vector4d position, vector4d location, vector4d up)

Returns a left-handed affine 3x4 matrix representing a camera transform. A camera transform multiplied by a point3 transforms a point3 local to the camera into world space. The camera transform is located at the specified position, looking towards the specified location, and using the specified up direction.

The up input does not need to be normalized.

In this frame of reference:

  • X axis: right direction
  • Y axis: up direction
  • Z axis: forward/look direction

view_look_to

matrix3x4d view_look_to(vector4d position, vector4d direction, vector4d up)

Returns a left-handed affine 3x4 matrix representing a camera view transform. A camera view transform is the inverse of a camera transform. A camera transform multiplied by a point3 transforms a point3 local to the camera into world space while a camera view transform multiplied by a point3 does the opposite: it transforms a world space point3 into local space of the camera. This is typically used before applying a projection matrix. The camera transform is located at the specified position, looking towards the specified direction, and using the specified up direction. The camera view transform is then constructed from its inverse.

The look to direction and up inputs do not need to be normalized.

In this frame of reference:

  • X axis: right direction
  • Y axis: up direction
  • Z axis: forward/look direction

view_look_at

matrix3x4d view_look_at(vector4d position, vector4d location, vector4d up)

Returns a left-handed affine 3x4 matrix representing a camera view transform. A camera view transform is the inverse of a camera transform. A camera transform multiplied by a point3 transforms a point3 local to the camera into world space while a camera view transform multiplied by a point3 does the opposite: it transforms a world space point3 into local space of the camera. This is typically used before applying a projection matrix. The camera transform is located at the specified position, looking towards the specified location, and using the specified up direction. The camera view transform is then constructed from its inverse.

The look to direction and up inputs do not need to be normalized.

In this frame of reference:

  • X axis: right direction
  • Y axis: up direction
  • Z axis: forward/look direction

proj_perspective

matrix4x4d proj_perspective(double view_width, double view_height, double near_distance, double far_distance)

Returns a left-handed 4x4 perspective projection matrix using the screen dimensions.

In this frame of reference:

  • X axis: right direction
  • Y axis: up direction
  • Z axis: forward/look direction

proj_perspective_fov

matrix4x4d proj_perspective_fov(double fov_angle_y, double aspect_ratio, double near_distance, double far_distance)

Returns a left-handed 4x4 perspective projection matrix using the screen field of view.

In this frame of reference:

  • X axis: right direction
  • Y axis: up direction
  • Z axis: forward/look direction

proj_orthographic

matrix4x4d proj_orthographic(double view_width, double view_height, double near_distance, double far_distance)

Returns a left-handed 4x4 orthographic projection matrix.

In this frame of reference:

  • X axis: right direction
  • Y axis: up direction
  • Z axis: forward/look direction