-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCamera.cpp
110 lines (85 loc) · 2.65 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "pch.h"
#include "Camera.h"
//camera for our app simple directX application. While it performs some basic functionality its incomplete.
//
Camera::Camera()
{
//initalise values.
//Orientation and Position are how we control the camera.
m_orientation.x = -90.0f; //rotation around x - pitch
m_orientation.y = 0.0f; //rotation around y - yaw
m_orientation.z = 0.0f; //rotation around z - roll //we tend to not use roll a lot in first person
m_position.x = 0.0f; //camera position in space.
m_position.y = 0.0f;
m_position.z = 0.0f;
//These variables are used for internal calculations and not set. but we may want to queary what they
//externally at points
m_lookat.x = 0.0f; //Look target point
m_lookat.y = 0.0f;
m_lookat.z = 0.0f;
m_forward.x = 0.0f; //forward/look direction
m_forward.y = 0.0f;
m_forward.z = 0.0f;
m_right.x = 0.0f;
m_right.y = 0.0f;
m_right.z = 0.0f;
m_movespeed = 0.05;
m_camRotRate = 1.5;
//force update with initial values to generate other camera data correctly for first update.
Update();
}
Camera::~Camera()
{
}
void Camera::Update()
{
/* Original Code */
/*
//rotation in yaw - using the paramateric equation of a circle
m_forward.x = sin((m_orientation.y)*3.1415f / 180.0f);
m_forward.z = cos((m_orientation.y)*3.1415f / 180.0f);
*/
/* Code from CMP502 */
m_forward.x = cos((m_orientation.y) * 3.1415f / 180.0f) * sin((m_orientation.x) * 3.1415f / 180.0f);
m_forward.z = sin((m_orientation.y) * 3.1415f / 180.0f) * sin((m_orientation.x) * 3.1415f / 180.0f);
m_forward.y = cos((m_orientation.x) * 3.1415f / 180.0f);
m_forward.Normalize();
//create right vector from look Direction
m_forward.Cross(DirectX::SimpleMath::Vector3::UnitY, m_right);
//update lookat point
m_lookat = m_position + m_forward;
//apply camera vectors and create camera matrix
m_cameraMatrix = (DirectX::SimpleMath::Matrix::CreateLookAt(m_position, m_lookat, DirectX::SimpleMath::Vector3::UnitY));
}
DirectX::SimpleMath::Matrix Camera::getCameraMatrix()
{
return m_cameraMatrix;
}
void Camera::setPosition(DirectX::SimpleMath::Vector3 newPosition)
{
m_position = newPosition;
}
DirectX::SimpleMath::Vector3 Camera::getPosition()
{
return m_position;
}
DirectX::SimpleMath::Vector3 Camera::getForward()
{
return m_forward;
}
void Camera::setRotation(DirectX::SimpleMath::Vector3 newRotation)
{
m_orientation = newRotation;
}
DirectX::SimpleMath::Vector3 Camera::getRotation()
{
return m_orientation;
}
float Camera::getMoveSpeed()
{
return m_movespeed;
}
float Camera::getRotationSpeed()
{
return m_camRotRate;
}