-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
53 lines (45 loc) · 1.22 KB
/
Camera.cpp
File metadata and controls
53 lines (45 loc) · 1.22 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Camera.h"
#include <iostream>
Camera::Camera()
{
c.identity();
e.set(0.0, 0.5, 2.0);
d.set(0.0, 0.0, 0.0);
up.set(0.0, 1.0, 0.0);
//Pre-define a camera matrix (and its inverse) that are shifted 'e' from the origin
//This is used as a default camera position for Project 1
c.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, e[0], e[1], e[2], 1);
ci.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -e[0], -e[1], -e[2], 1);
update();
}
Camera::~Camera()
{
//Delete and dynamically allocated memory/objects here
}
Matrix4& Camera::getMatrix()
{
return c;
}
Matrix4& Camera::getInverseMatrix()
{
return ci;
}
void Camera::update()
{
//Update the Camera Matrix using d, e, and up
//Solve for the z, x, and y axes of the camera matrix
//Use these axes and the e vector to create a camera matrix c
//Use c to solve for an inverse camera matrix ci
Vector3 z = (e - d).normalize();
Vector3 x = up.cross(z).normalize();
Vector3 y = z.cross(x);
c.set(x[0], x[1], x[2], 0, y[0], y[1], y[2], 0, z[0], z[1], z[2], 0, e[0], e[1], e[2], 1);
ci = c.rigidInverse();
}
void Camera::set(Vector3& e, Vector3& d, Vector3& up)
{
this->e = e;
this->d = d;
this->up = up;
update();
}