Made a big mess of the codebase
This commit is contained in:
@@ -8,67 +8,63 @@
|
||||
#include "camera.h"
|
||||
#include "display/display.h"
|
||||
#include "assert/assert.h"
|
||||
#include "scene/node.h"
|
||||
#include "display/framebuffer/framebuffer.h"
|
||||
|
||||
camera_t CAMERA_DATA[ECS_ENTITY_COUNT_MAX] = { 0 };
|
||||
ecscomponent_t CAMERA_COMPONENT = ecsComponentInit(
|
||||
CAMERA_DATA,
|
||||
((ecscomponentcallbacks_t){
|
||||
.init = NULL,
|
||||
.entityAdd = cameraEntityAdded
|
||||
})
|
||||
);
|
||||
camera_t CAMERA_DATA[CAMERA_COUNT_MAX] = { 0 };
|
||||
camera_t *CAMERA_MAIN = NULL;
|
||||
|
||||
ecsid_t CAMERA_MAIN = -1;
|
||||
void cameraInit(camera_t *camera) {
|
||||
assertNotNull(camera, "Not a camera component");
|
||||
|
||||
void cameraEntityAdded(const ecsid_t id) {
|
||||
if(CAMERA_MAIN == -1) CAMERA_MAIN = id;
|
||||
camera->type = CAMERA_TYPE_PERSPECTIVE
|
||||
;
|
||||
glm_mat4_identity(camera->transform);
|
||||
camera->perspective.fov = 45.0f;
|
||||
|
||||
camera_t *cam = cameraGet(id);
|
||||
cam->type = CAMERA_TYPE_PERSPECTIVE;
|
||||
cam->perspective.fov = glm_rad(90.0f);
|
||||
cam->nearClip = 0.1f;
|
||||
cam->farClip = 1000.0f;
|
||||
camera->nearClip = 0.1f;
|
||||
camera->farClip = 100.0f;
|
||||
glm_look(
|
||||
(vec3){ 3.0f, 3.0f, 3.0f },
|
||||
(vec3){ 0.0f, 0.0f, 0.0f },
|
||||
(vec3){ 0.0f, 1.0f, 0.0f },
|
||||
camera->transform
|
||||
);
|
||||
}
|
||||
|
||||
void cameraPush(const ecsid_t id) {
|
||||
assertTrue(cameraHas(id), "Not a camera component");
|
||||
void cameraPush(camera_t *camera) {
|
||||
assertNotNull(camera, "Not a camera component");
|
||||
|
||||
camera_t *cam = cameraGet(id);
|
||||
mat4 projection;
|
||||
|
||||
mat4 projection, view;
|
||||
nodeMatrixGet(id, view);
|
||||
|
||||
switch(cam->type) {
|
||||
switch(camera->type) {
|
||||
case CAMERA_TYPE_ORTHOGRAPHIC:
|
||||
glm_ortho(
|
||||
cam->orthographic.left,
|
||||
cam->orthographic.right,
|
||||
cam->orthographic.bottom,
|
||||
cam->orthographic.top,
|
||||
cam->nearClip,
|
||||
cam->farClip,
|
||||
camera->orthographic.left,
|
||||
camera->orthographic.right,
|
||||
camera->orthographic.bottom,
|
||||
camera->orthographic.top,
|
||||
camera->nearClip,
|
||||
camera->farClip,
|
||||
projection
|
||||
);
|
||||
break;
|
||||
|
||||
case CAMERA_TYPE_PERSPECTIVE:
|
||||
glm_perspective(
|
||||
cam->perspective.fov,
|
||||
camera->perspective.fov,
|
||||
(
|
||||
(float_t)frameBufferGetWidth(FRAMEBUFFER_BOUND) /
|
||||
(float_t)frameBufferGetHeight(FRAMEBUFFER_BOUND)
|
||||
),
|
||||
cam->nearClip,
|
||||
cam->farClip,
|
||||
camera->nearClip,
|
||||
camera->farClip,
|
||||
projection
|
||||
);
|
||||
}
|
||||
|
||||
#if DISPLAY_SDL2
|
||||
mat4 pv;
|
||||
glm_mat4_mul(projection, view, pv);
|
||||
glm_mat4_mul(projection, camera->transform, pv);
|
||||
|
||||
glPushMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
Reference in New Issue
Block a user