GameDevTecnico / cubos

A still very barebones game engine focused on voxels and data-oriented programming
https://gamedevtecnico.github.io/cubos/
MIT License
83 stars 23 forks source link

Add Camera component which holds projection matrix #1181

Open RiscadoA opened 3 months ago

RiscadoA commented 3 months ago

Problem

Currently, we only have the PerspectiveCamera component which holds parameters such as the field of view. This means that all code which depends on camera projection matrices needs to recalculate the camera's projection matrix, which leads to a lot of code duplication. Eventually we'll also want to provide an OrtographicCamera, and thus this coupling would really be a problem.

Solution

We should have a Camera component, which holds only the projection matrix of a camera. Then, when a PerspectiveCamera is added to an entity, a Camera component is automatically inserted. Then, every frame, a system updates the Camera's projection matrix to reflect the current fields in the PerspectiveCamera.

We should search for all places accessing the PerspectiveCamera component and switch them for the generic Camera component where possible.