PeriDyno 1.0.0
Loading...
Searching...
No Matches
Camera.cpp
Go to the documentation of this file.
1#include "Camera.h"
2
3namespace dyno
4{
6 {
7 float width = this->viewportWidth();
8 float height = this->viewportHeight();
9
10 glm::mat4 projMat = this->getProjMat();
11 glm::mat4 viewMat = this->getViewMat();
12 float dx = (2.0f * x) / width - 1.0f;
13 float dy = 1.0f - (2.0f * y) / height;
14 float dz = 0.95;
15
16 glm::mat4 mv = glm::inverse(projMat*viewMat);
17
18 glm::vec4 near = glm::vec4(dx, dy, -1, 1.0);
19 glm::vec4 far = glm::vec4(dx, dy, 1, 1.0);
20
21 glm::vec4 near_world = mv * near;
22 glm::vec4 far_world = mv * far;
23
24 if (near_world.w != 0.0)
25 {
26 near_world /= near_world.w;
27 }
28
29 if (far_world.w != 0.0)
30 {
31 far_world /= far_world.w;
32 }
33
34 TRay3D<float> ray;
35 ray.origin = Vec3f(near_world.x, near_world.y, near_world.z);
36 ray.direction = Vec3f(far_world.x - near_world.x, far_world.y - near_world.y, far_world.z - near_world.z).normalize();
37
38 return ray;
39 }
40}
TRay3D< float > castRayInWorldSpace(float x, float y)
Definition Camera.cpp:5
int viewportHeight() const
Definition Camera.h:42
virtual glm::mat4 getProjMat()=0
int viewportWidth() const
Definition Camera.h:41
virtual glm::mat4 getViewMat()=0
Coord3D origin
Coord3D direction
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Vector< float, 3 > Vec3f
Definition Vector3D.h:93