Fixed camera

This commit is contained in:
2025-10-13 12:26:59 -05:00
parent 2c0fd84c72
commit 0c0650a2c3
6 changed files with 82 additions and 66 deletions

View File

@@ -98,6 +98,34 @@ void cameraPushMatrix(camera_t *camera) {
);
break;
case CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT:
assertTrue(
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE ||
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED,
"Pixel perfect camera view requires perspective projection"
);
const float_t viewportHeight = (
(float_t)frameBufferGetHeight(FRAMEBUFFER_BOUND)
);
const float_t z = (viewportHeight / 2.0f) / (
camera->lookatPixelPerfect.pixelsPerUnit *
tanf(camera->perspective.fov / 2.0f)
);
vec3 position;
glm_vec3_copy(camera->lookatPixelPerfect.target, position);
glm_vec3_add(position, camera->lookatPixelPerfect.offset, position);
position[2] += z;
glm_lookat(
position,
camera->lookatPixelPerfect.target,
camera->lookatPixelPerfect.up,
view
);
break;
case CAMERA_VIEW_TYPE_2D:
glm_mat4_identity(view);
glm_translate(view, (vec3){

View File

@@ -20,7 +20,8 @@ typedef enum {
typedef enum {
CAMERA_VIEW_TYPE_MATRIX,
CAMERA_VIEW_TYPE_LOOKAT,
CAMERA_VIEW_TYPE_2D
CAMERA_VIEW_TYPE_2D,
CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT
} cameraviewtype_t;
typedef struct {
@@ -36,6 +37,13 @@ typedef struct {
float_t up[3];
} lookat;
struct {
float_t offset[3];
float_t target[3];
float_t up[3];
float_t pixelsPerUnit;
} lookatPixelPerfect;
struct {
float_t position[2];
float_t zoom;