MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / RenderViewCamera

Method RenderViewCamera

TombEngine/Renderer/RenderView.cpp:60–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58 }
59
60 RenderViewCamera::RenderViewCamera(CAMERA_INFO* cam, float roll, float fov, float n, float f, int w, int h)
61 {
62 RoomNumber = cam->pos.RoomNumber;
63 WorldPosition = Vector3(cam->pos.x, cam->pos.y, cam->pos.z);
64
65 auto target = Vector3(cam->target.x, cam->target.y, cam->target.z);
66
67 // Safety clamps to avoid NaNs in view direction calculation.
68 auto rawDirection = target - WorldPosition;
69
70 if (rawDirection == Vector3::Zero)
71 target.y -= 10;
72
73 if (std::abs(rawDirection.x) < EPSILON && std::abs(rawDirection.z) < EPSILON)
74 target.x -= 1;
75
76 WorldDirection = target - WorldPosition;
77 WorldDirection.Normalize();
78
79 Vector3 up = -Vector3::UnitY;
80 Matrix upRotation = Matrix::CreateFromAxisAngle(WorldDirection, roll);
81 up = Vector3::Transform(up, upRotation);
82 up.Normalize();
83
84 View = Matrix::CreateLookAt(WorldPosition, target, up);
85 Projection = Matrix::CreatePerspectiveFieldOfView(fov, w / (float)h, n, f);
86 ViewProjection = View * Projection;
87 ViewSize = { (float)w, (float)h };
88 InvViewSize = { 1.0f / w, 1.0f / h };
89 Frustum.Update(View, Projection);
90 NearPlane = n;
91 FarPlane = f;
92 FOV = fov;
93 }
94
95 RenderViewCamera::RenderViewCamera(const Vector3& pos, const Vector3& dir, const Vector3& up, int room, int width, int height, float fov, float n, float f)
96 {

Callers

nothing calls this directly

Calls 3

Vector3Function · 0.50
NormalizeMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected