17 #include "PerspectiveCamera.h" 18 #include "linmath/float3x3.h" 20 PerspectiveCamera::PerspectiveCamera(chag::float3 position, chag::float3 lookAt, chag::float3 up,
21 float fov,
float ratio,
float nearPlane,
float farPlane)
22 :
Camera(position, lookAt, up, fov, ratio, nearPlane, farPlane)
27 PerspectiveCamera::~PerspectiveCamera() {
30 chag::float4x4 PerspectiveCamera::getViewMatrix() {
31 return lookAt(m_vPosition, m_vLookAt, m_vUp);
34 void PerspectiveCamera::update(
float dt) { }
36 chag::float4x4 PerspectiveCamera::lookAt(
const chag::float3 &eye,
37 const chag::float3 ¢er,
38 const chag::float3 &up)
40 chag::float3 dir = chag::normalize(eye - center);
41 chag::float3 right = chag::normalize(chag::cross(up, chag::normalize(dir)));
42 chag::float3 newup = chag::normalize(chag::cross(dir, right));
44 chag::float3x3 R = chag::make_matrix(right, newup, dir);
45 chag::float4x4 invrot = chag::make_matrix(chag::transpose(R), chag::make_vector(0.0f,0.0f,0.0f));
47 return invrot * chag::make_translation(-eye);
50 chag::float4x4 PerspectiveCamera::getProjectionMatrix() {
51 return perspectiveMatrix(m_fFov, m_fRatio, m_fNearPlane, m_fFarPlane);
54 chag::float4x4 PerspectiveCamera::perspectiveMatrix(
float fov,
float aspectRatio,
float n,
float f) {
55 return chag::make_perspective(fov, aspectRatio, n, f);
58 void PerspectiveCamera::setPosition(chag::float3 position) {
59 this->m_vPosition = position;
62 void PerspectiveCamera::setLookAt(chag::float3 lookAt){
63 this->m_vLookAt = lookAt;
66 void PerspectiveCamera::setUpVector(chag::float3 up){