cleaned more stuff
This commit is contained in:
@@ -6,6 +6,78 @@
|
||||
*/
|
||||
|
||||
#include "camera.h"
|
||||
#include "display/display.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
camera_t CAMERA_DATA[ECS_ENTITY_COUNT_MAX] = { 0 };
|
||||
ecscomponent_t CAMERA_COMPONENT = ecsComponentInit(CAMERA_DATA, NULL);
|
||||
ecscomponent_t CAMERA_COMPONENT = ecsComponentInit(
|
||||
CAMERA_DATA,
|
||||
((ecscomponentcallbacks_t){
|
||||
.init = NULL,
|
||||
.entityAdd = cameraEntityAdded
|
||||
})
|
||||
);
|
||||
|
||||
ecsid_t CAMERA_MAIN = -1;
|
||||
|
||||
void cameraEntityAdded(const ecsid_t id) {
|
||||
if(CAMERA_MAIN == -1) CAMERA_MAIN = id;
|
||||
|
||||
camera_t *cam = cameraGet(id);
|
||||
cam->type = CAMERA_TYPE_ORTHOGRAPHIC;
|
||||
cam->perspective.fov = glm_rad(75.0f);
|
||||
cam->nearClip = 0.1f;
|
||||
cam->farClip = 1000.0f;
|
||||
cam->clearColor = COLOR_CORNFLOWER_BLUE;
|
||||
}
|
||||
|
||||
void cameraPush(const ecsid_t id) {
|
||||
assertTrue(cameraHas(id), "Not a camera component");
|
||||
|
||||
camera_t *cam = cameraGet(id);
|
||||
|
||||
mat4 projection;
|
||||
switch(cam->type) {
|
||||
case CAMERA_TYPE_ORTHOGRAPHIC:
|
||||
glm_ortho(
|
||||
cam->orthographic.left,
|
||||
cam->orthographic.right,
|
||||
cam->orthographic.bottom,
|
||||
cam->orthographic.top,
|
||||
cam->nearClip,
|
||||
cam->farClip,
|
||||
projection
|
||||
);
|
||||
break;
|
||||
|
||||
case CAMERA_TYPE_PERSPECTIVE:
|
||||
glm_perspective(
|
||||
cam->perspective.fov,
|
||||
4.0f / 3.0f,
|
||||
cam->nearClip,
|
||||
cam->farClip,
|
||||
projection
|
||||
);
|
||||
}
|
||||
|
||||
#if DUSK_DISPLAY_SDL2
|
||||
glPushMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glLoadMatrixf((const GLfloat*)projection);
|
||||
|
||||
glClearColor(
|
||||
cam->clearColor.r / 255.0f,
|
||||
cam->clearColor.g / 255.0f,
|
||||
cam->clearColor.b / 255.0f,
|
||||
cam->clearColor.a / 255.0f
|
||||
);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cameraPop(void) {
|
||||
#if DUSK_DISPLAY_SDL2
|
||||
glPopMatrix();
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user