-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperspective_camera.cpp
37 lines (31 loc) · 1.43 KB
/
perspective_camera.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "perspective_camera.h"
PerspectiveCamera::PerspectiveCamera( void )
{}
PerspectiveCamera::PerspectiveCamera( const float min_x,
const float max_x,
const float min_y,
const float max_y,
const float distance, //distance to viewport
const glm::ivec2 &resolution,
const glm::vec3 &position,
const glm::vec3 &up_vector,
const glm::vec3 &look_at ) :
Camera::Camera{ resolution,
position,
up_vector,
look_at },
min_x_{ min_x },
max_x_{ max_x },
min_y_{ min_y },
max_y_{ max_y },
distance_{ distance }
{}
Ray PerspectiveCamera::getWorldSpaceRay( const glm::vec2 &pixel_coord ) const
{
float width = max_x_ - min_x_;
float height = max_y_ - min_y_;
glm::vec3 screen_point{ ( pixel_coord[0]+0.5f )/ static_cast< float >( resolution_[0] ) * width + min_x_,
( pixel_coord[1]+0.5f )/ static_cast< float >( resolution_[1] ) * -height + max_y_,
-distance_ };
return Ray{ position_, glm::normalize( onb_.getBasisMatrix() * screen_point ) };
}