@@ -22,9 +22,22 @@ namespace cage
2222 Real px = p[0 ], py = -p[1 ];
2323 const TransformComponent &ts = camera->value <TransformComponent>();
2424 const CameraComponent &cs = camera->value <CameraComponent>();
25- CAGE_ASSERT (cs.cameraType == CameraTypeEnum::Perspective);
2625 const Mat4 view = inverse (Mat4 (ts.position , ts.orientation , Vec3 (ts.scale )));
27- const Mat4 proj = perspectiveProjection (cs.perspectiveFov , Real (res[0 ]) / Real (res[1 ]), cs.near , cs.far );
26+ const Mat4 proj = [&]() -> Mat4
27+ {
28+ switch (cs.cameraType )
29+ {
30+ case CameraTypeEnum::Orthographic:
31+ {
32+ const Vec2 os = cs.orthographicSize * 0.5 ;
33+ return orthographicProjection (-os[0 ], os[0 ], -os[1 ], os[1 ], cs.near , cs.far );
34+ }
35+ case CameraTypeEnum::Perspective:
36+ return perspectiveProjection (cs.perspectiveFov , Real (res[0 ]) / Real (res[1 ]), cs.near , cs.far );
37+ default :
38+ CAGE_THROW_ERROR (Exception, " invalid camera type" );
39+ }
40+ }();
2841 const Mat4 inv = inverse (proj * view);
2942 const Vec4 pn = inv * Vec4 (px, py, -1 , 1 );
3043 const Vec4 pf = inv * Vec4 (px, py, 1 , 1 );
0 commit comments