gunship-rs
gunship-rs copied to clipboard
Add Support for Orthographic Camera
This feature would be useful for working on the grid collision system since I'm testing it in a 2D plane and the perspective makes it hard to visually verify that a collision took place. Orthographic projection is also needed for better 2D support down the line, so it's worth getting in now.
Some notes for anyone looking to complete this task: The camera code can be found in lib/polygon_rs/src/camera.rs
. Currently there is a single Camera
struct that represents a perspective camera. The Camera
type should be turned into a enum with variants Perspective
and Orthographic
. The current Camera
type should be renamed PerspectiveCamera
and a new type OrthographicCamera
should be added. Camera::Perspective
should contain a PerspectiveCamera
object and Camera::Orthographic
should contain an OrthographicCamera
object. The new Camera
enum should have three functions implemented for it: view_matrix()
, inverse_view_matrix()
, and projection_matrix()
which should return the specified matrix based on the camera variant (either perspective or orthographic). In terms of the rendering system things should just work with those changes as the renderer only accesses the camera's matrices through those three public methods.
~~This change will require some slight reworking within the component system as well. In src/component/camera.rs
gunship defines a custom camera type that removes the redundant position
and orientation
members from polygon's Camera
. The Camera
component will need to be reworked in the same way that polygon's Camera
was, making it into an enum with two variants.~~
The hardest part is likely going to be getting the math right, however there are plenty of tutorials and documents online that explain the math needed to complete this task. If you don't have an understanding of linear algebra and projection matrices you might be able to still complete this task but it will take much longer.