@@ -19,27 +19,31 @@ glm::mat4 Camera::getViewMatrix(const World& world, Entity e) const {
1919}
2020
2121glm::mat4 Camera::getProjectionMatrix () const {
22- if (projectionType == ProjectionType::PERSPECTIVE) {
23- glm::mat4 projection = glm::perspective (glm::radians (fieldOfView), aspectRatio, nearPlane, farPlane);
24- projection[1 ][1 ] *= -1 ;
25- return projection;
26- } else {
27- const float width = orthographicSize * aspectRatio;
28- const float height = orthographicSize;
29- glm::mat4 projection = glm::ortho (-width, width, -height, height, nearPlane, farPlane);
30- projection[1 ][1 ] *= -1 ;
31- return projection;
22+ glm::mat4 projection;
23+ switch (projectionType) {
24+ case ProjectionType::PERSPECTIVE:
25+ projection = glm::perspective (glm::radians (fieldOfView), aspectRatio, nearPlane, farPlane);
26+ break ;
27+ case ProjectionType::ORTHOGRAPHIC:
28+ projection = glm::ortho (-orthographicSize * aspectRatio,
29+ orthographicSize * aspectRatio,
30+ -orthographicSize,
31+ orthographicSize,
32+ nearPlane,
33+ farPlane);
34+ break ;
3235 }
36+
37+ projection[1 ][1 ] *= -1 ;
38+ return projection;
3339}
3440
3541void Camera::updateCameraVectors () {
36- front = glm::normalize (glm::vec3 (
37- cos (glm::radians (yaw)) * cos (glm::radians (pitch)),
38- sin (glm::radians (pitch)),
39- sin (glm::radians (yaw)) * cos (glm::radians (pitch))
40- ));
42+ front = glm::normalize (glm::vec3 (cos (glm::radians (yaw)) * cos (glm::radians (pitch)),
43+ sin (glm::radians (pitch)),
44+ sin (glm::radians (yaw)) * cos (glm::radians (pitch))));
4145 right = glm::normalize (glm::cross (front, worldUp));
4246 up = glm::normalize (glm::cross (right, front));
4347}
4448
45- }
49+ } // namespace SpaceEngine
0 commit comments