-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorthographic_camera.cpp
36 lines (30 loc) · 1.36 KB
/
orthographic_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
#include "orthographic_camera.h"
OrthographicCamera::OrthographicCamera( void )
{}
OrthographicCamera::OrthographicCamera( const float min_x,
const float max_x,
const float min_y,
const float max_y,
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 }
{}
Ray OrthographicCamera::getWorldSpaceRay( const glm::vec2 &pixel_coord ) const
{
float width = max_x_ - min_x_;
float height = max_y_ - min_y_;
glm::vec3 origin{ ( 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_,
0.0f };
return Ray{ onb_.getBasisMatrix() * origin + position_,
glm::normalize( onb_.getBasisMatrix() * glm::vec3{ 0.0f, 0.0f, -1.0f } ) };
}