Fixed camera
This commit is contained in:
@@ -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){
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user