Added camera orbit controls.

This commit is contained in:
2021-08-24 22:04:01 -07:00
parent 02a485860f
commit eed325d702
9 changed files with 61 additions and 23 deletions

View File

@ -35,4 +35,15 @@ void cameraOrtho(camera_t *camera,
) {
matrixIdentity(&camera->projection);
matrixOrtho(&camera->projection, left, right, bottom, top, camNear, camFar);
}
void cameraOrbit(camera_t *camera,
float distance, float yaw, float pitch,
float targetX, float targetY, float targetZ
) {
float cy = cos(pitch);
float x = distance * sin(yaw) * cy;
float y = distance * sin(pitch);
float z = distance * cos(yaw) * cy;
cameraLookAt(camera, x, y, z, targetX, targetY, targetZ);
}

View File

@ -65,4 +65,20 @@ void cameraPerspective(camera_t *camera,
*/
void cameraOrtho(camera_t *camera,
float left, float right, float bottom, float top, float camNear, float camFar
);
/**
* Update a camera to orbit around a point.
*
* @param camera Camera to update
* @param distance Distance from the point
* @param yaw Yaw (Y axis) rotation.
* @param pitch Pitch (X/Z axis) rotation.
* @param targetX X point to orbit around.
* @param targetY Y point to orbit around.
* @param targetZ Z point to orbit around.
*/
void cameraOrbit(camera_t *camera,
float distance, float yaw, float pitch,
float targetX, float targetY, float targetZ
);