Skip to content

Commit c1e0be6

Browse files
committed
camera ray with orthographic camera
1 parent 44efab7 commit c1e0be6

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

sources/include/cage-core/files.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace cage
5353
virtual bool readLine(String &line); // non blocking
5454

5555
virtual void write(PointerRange<const char> buffer);
56-
virtual void writeLine(const String &line);
56+
virtual void writeLine(const String &line = "");
5757

5858
virtual void seek(uint64 position);
5959
virtual uint64 tell();

sources/libsimple/cameraRay.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

sources/libsimple/graphics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace cage
9797
{
9898
case CameraTypeEnum::Orthographic:
9999
{
100-
const Vec2 &os = data.orthographicSize;
100+
const Vec2 os = data.orthographicSize * 0.5;
101101
return orthographicProjection(-os[0], os[0], -os[1], os[1], data.near, data.far);
102102
}
103103
case CameraTypeEnum::Perspective:

0 commit comments

Comments
 (0)