Camera
Typedefs
-
typedef struct binocle_camera binocle_camera
2D Camera
-
typedef struct binocle_camera_3d binocle_camera_3d
Functions
-
binocle_camera binocle_camera_new(struct binocle_viewport_adapter *adapter)
Creates a new camera instance.
- Parameters:
adapter – The viewport adapter to apply to this camera
- Returns:
The camera
-
kmVec2 binocle_camera_screen_to_world_point(binocle_camera camera, kmVec2 screen_position)
Converts a point from screen coordinates to world coordinates.
- Parameters:
camera – The camera
screen_position – The position in screen coordinates
- Returns:
The world point
-
void binocle_camera_update_matrixes(binocle_camera *camera)
Updates the camera matrixes This does the actual calculations to update the internal matrixes.
- Parameters:
camera – The camera
-
void binocle_camera_force_matrix_update(binocle_camera *camera)
Force updating the camera matrixes as soon as we access any of them This sets the matrixes and bounds flags as dirty so that as soon as we need to access any of the matrixes we recalculate them right away.
- Parameters:
camera – The camera
-
kmMat4 *binocle_camera_get_transform_matrix(binocle_camera *camera)
Gets the transform matrix of the camera.
- Parameters:
camera – The camera
- Returns:
The transform matrix
-
kmMat4 *binocle_camera_get_inverse_transform_matrix(binocle_camera *camera)
Gets the inverse transform matrix of the camera.
- Parameters:
camera – The camera
- Returns:
The inverse transform matrix
-
struct binocle_viewport_adapter *binocle_camera_get_viewport_adapter(binocle_camera camera)
Gets the viewport adapter associated to the camera.
- Parameters:
camera – The camera
- Returns:
Teh viewport adapter associated to the camera
-
kmAABB2 binocle_camera_get_viewport(binocle_camera camera)
Helper to get the viewport of the camera It actually gets the viewport of the viewport adapter associated to the camera.
- Parameters:
camera – The camera
- Returns:
the viewport of the camera
-
void binocle_camera_set_position(binocle_camera *camera, float x, float y)
Sets the camera position in world coordinates.
- Parameters:
camera – The camera
x – X position
y – Y position
-
kmVec2 binocle_camera_world_to_screen_point(binocle_camera camera, kmVec2 world_position)
Converts a point from world coordinates to screen coordinates.
- Parameters:
camera – The camera
world_position – The position in world coordinates
- Returns:
The screen point
-
kmMat4 binocle_camera_get_projection_matrix(binocle_camera camera)
Gets the camera projection matrix.
- Parameters:
camera – The camera
- Returns:
The projection matrix
-
kmMat4 binocle_camera_get_view_projection_matrix(binocle_camera camera)
Get the view projection matrix of the given camera Gets the view-projection matrix which is the transformMatrix * the projection matrix.
- Parameters:
camera – The camera
- Returns:
The view projection matrix
-
binocle_camera_3d binocle_camera_3d_new(kmVec3 position, float near, float far, float fov_y)
Creates a new 3D camera instance.
- Parameters:
position – the position of the camera in world coordinates
near – the near plane distance
far – the far plane distance
fov_y – the vertical field of view
- Returns:
an instance of binocle_camera_3d
-
void binocle_camera_3d_update_matrixes(binocle_camera_3d *camera)
Updates the transform and inverse_transform matrices.
- Parameters:
camera – the instance of binocle_camera_3d to update
-
void binocle_camera_3d_set_position(binocle_camera_3d *camera, kmVec3 position)
Sets the camera position in world coordinates and updates the underlying matrices.
- Parameters:
camera – the instance of binocle_camera_3d
position – the position in world coordinates
-
void binocle_camera_3d_set_rotation(binocle_camera_3d *camera, float pitch, float yaw, float roll)
Sets the orientation of the camera and updates the underlying matrices.
- Parameters:
camera – the instance of the binocle_camera_3d
pitch – the pitch in degrees
yaw – the yaw in degrees
roll – the roll in degrees
-
void binocle_camera_3d_set_near(binocle_camera_3d *camera, float near)
Sets the camera near plane distance.
- Parameters:
camera – the instance of the binocle_camera_3d
near – the distance of the near plane
-
void binocle_camera_3d_set_far(binocle_camera_3d *camera, float far)
Sets the camera far plane distance.
- Parameters:
camera – the instance of the binocle_camera_3d
far – the distance of the far plane
-
kmMat4 *binocle_camera_3d_get_transform_matrix(binocle_camera_3d *camera)
Returns the transform matrix of the camera.
- Parameters:
camera – the instance of the binocle_camera_3d
- Returns:
the transform matrix of the camera
-
void binocle_camera_3d_translate(binocle_camera_3d *camera, float x, float y, float z)
Translates the camera in the world.
- Parameters:
camera – the instance of the binocle_camera_3d
x – the amount to move on the X direction (positive is right)
y – the amount to move on the Y direction (positive is up)
z – the amount to move on the Z direction (positive is into the scene)
-
void binocle_camera_3d_rotate(binocle_camera_3d *camera, float pitch, float yaw, float roll)
Rotates the camera by the given amount on the different axes.
- Parameters:
camera – the instance of binocle_camera_3d
pitch – the pitch in degrees
yaw – the yaw in degrees
roll – the roll in degrees
-
kmMat4 *binocle_camera_3d_get_inverse_transform_matrix(binocle_camera_3d *camera)
Returns the inverse transform matrix.
- Parameters:
camera – the instance of binocle_camera_3d
- Returns:
the inverse transform matrix
-
void binocle_camera_3d_screen_to_world_ray_internal(int mouse_x, int mouse_y, int screen_width, int screen_height, kmMat4 view_matrix, kmMat4 projection_matrix, kmVec3 *out_direction)
Internal function to transform an X,Y screen space coordinate to world space and get the direction ray from it.
- Parameters:
mouse_x – the X coordinate in screen space
mouse_y – the Y coordinate in screen space
screen_width – the window width in pixels
screen_height – the window height in pixels
view_matrix – camera position and orientation
projection_matrix – camera parameters (ratio, field of view, near and far plane)
out_direction – the direction, in world space, of the ray that goes “through” the mouse position
-
void binocle_camera_3d_screen_to_world_ray(binocle_camera_3d *camera, int mouse_x, int mouse_y, kmAABB2 viewport, kmVec3 *out_direction)
Transforms an X,Y screen space coordinate into a direction ray in world space.
- Parameters:
camera – an instance of binocle_camera_3d
mouse_x – the X coordinate in screen space
mouse_y – the Y coordinate in screen space
viewport – the camera/window viewport
out_direction – the direction, in world space, of the ray that goes “through” the mouse position
-
struct binocle_camera
- #include <binocle_camera.h>
2D Camera
Public Members
-
kmMat4 transform_matrix
-
kmMat4 inverse_transform_matrix
-
kmVec2 position
-
kmVec2 origin
-
float rotation
-
float zoom
-
float min_zoom
-
float max_zoom
-
bool are_matrixes_dirty
-
bool are_bounds_dirty
-
kmAABB2 bounds
-
struct binocle_viewport_adapter *viewport_adapter
-
float near_distance
-
float far_distance
-
kmMat4 transform_matrix
-
struct binocle_camera_3d