Camera API¶
Zest provides some simple camera utilities and frustum culling. You can use these or create your own with your own libraries.
Camera Creation¶
zest_CreateCamera¶
Camera Movement¶
Moves the camera in a specific direction based on the speed value you pass in to the function.
zest_CameraMoveForward / zest_CameraMoveBackward¶
void zest_CameraMoveForward(zest_camera_t *camera, float speed);
void zest_CameraMoveBackward(zest_camera_t *camera, float speed);
zest_CameraMoveUp / zest_CameraMoveDown¶
void zest_CameraMoveUp(zest_camera_t *camera, float speed);
void zest_CameraMoveDown(zest_camera_t *camera, float speed);
zest_CameraStrafLeft / zest_CameraStrafRight¶
void zest_CameraStrafLeft(zest_camera_t *camera, float speed);
void zest_CameraStrafRight(zest_camera_t *camera, float speed);
Camera Rotation¶
zest_TurnCamera¶
Turn the camera by a given amount of degrees (gets converted to radians internally) scaled by the sensitivity that you pass into the function.
zest_CameraUpdateFront¶
Recalculate front vector from yaw/pitch.
Camera Setup¶
zest_CameraPosition¶
Position the camera by passing in a float array of 3 elements.
zest_CameraSetFoV¶
Sets the Field of View for the camera in degrees.
zest_CameraSetPitch / zest_CameraSetYaw¶
Set the pitch and yaw of the camera in degrees.
void zest_CameraSetPitch(zest_camera_t *camera, float pitch);
void zest_CameraSetYaw(zest_camera_t *camera, float yaw);
Screen/World Conversion¶
zest_ScreenRay¶
Get ray from screen position. You pass in the screen pixel coordinates (xpos and ypos), the size of the screen and the view and projection matrices which you will often have stored in a uniform buffer.
zest_vec3 zest_ScreenRay(
float xpos,
float ypos,
float view_width,
float view_height,
zest_matrix4 *projection,
zest_matrix4 *view
);
A typical usage might be something like:
zest_uniform_buffer uniform_buffer = zest_GetUniformBuffer(buffer_handle);
uniform_buffer_data_t *data = (uniform_buffer_data_t *)zest_GetUniformBufferData(uniform_buffer);
zest_vec3 camera_last_ray = zest_ScreenRay(x, y, zest_ScreenWidthf(context), zest_ScreenHeightf(context), &data->proj, &data->view);
zest_WorldToScreen¶
zest_vec2 zest_WorldToScreen(
const float point[3],
float view_width,
float view_height,
zest_matrix4* projection,
zest_matrix4* view
);
zest_WorldToScreenOrtho¶
Convert a 3D world position to 2D screen coordinates using an orthographic projection. Useful for 2D games or isometric views where perspective distortion is not desired.
zest_vec2 zest_WorldToScreenOrtho(
const float point[3],
float view_width,
float view_height,
zest_matrix4* projection,
zest_matrix4* view
);
Frustum Culling¶
zest_CalculateFrustumPlanes¶
void zest_CalculateFrustumPlanes(
zest_matrix4 *view_matrix,
zest_matrix4 *proj_matrix,
zest_vec4 planes[6]);
zest_IsPointInFrustum¶
zest_IsSphereInFrustum¶
zest_RayIntersectPlane¶
zest_bool zest_RayIntersectPlane(
zest_vec3 ray_origin,
zest_vec3 ray_direction,
zest_vec3 plane,
zest_vec3 plane_normal,
float *distance,
zest_vec3 *intersection
);