Khaotic Engine Reborn
Loading...
Searching...
No Matches
position_class Class Reference

Public Member Functions

 position_class (const position_class &)
 
void SetFrameTime (float)
 
void GetRotation (float &, float &) const
 
void GetPosition (float &, float &, float &) const
 
void TurnLeft (bool)
 
void TurnRight (bool)
 
void TurnMouse (float, float, float, bool)
 
void MoveCamera (bool, bool, bool, bool, bool, bool, bool, bool, bool)
 

Detailed Description

Definition at line 14 of file position_class.h.

Constructor & Destructor Documentation

◆ position_class() [1/2]

position_class::position_class ( )

Definition at line 3 of file position_class.cpp.

4{
5 m_frameTime = 0.0f;
6 m_rotationY = 0.0f;
7 m_rotationX = 0.0f;
8 m_positionX = 0.0f;
9 m_positionY = 0.0f;
10 m_positionZ = 0.0f;
11 m_leftTurnSpeed = 0.0f;
12 m_rightTurnSpeed = 0.0f;
13 m_horizontalTurnSpeed = 0.0f;
14 m_verticalTurnSpeed = 0.0f;
15 m_cameraSpeed = 4.0f;
16 m_speed = m_cameraSpeed;
17}

◆ position_class() [2/2]

position_class::position_class ( const position_class & other)

Definition at line 20 of file position_class.cpp.

21{
22}

◆ ~position_class()

position_class::~position_class ( )

Definition at line 25 of file position_class.cpp.

26{
27}

Member Function Documentation

◆ GetPosition()

void position_class::GetPosition ( float & x,
float & y,
float & z ) const

Definition at line 42 of file position_class.cpp.

43{
44 x = m_positionX;
45 y = m_positionY;
46 z = m_positionZ;
47 return;
48}

◆ GetRotation()

void position_class::GetRotation ( float & y,
float & x ) const

Definition at line 35 of file position_class.cpp.

36{
37 y = m_rotationY;
38 x = m_rotationX;
39 return;
40}

◆ MoveCamera()

void position_class::MoveCamera ( bool forward,
bool backward,
bool left,
bool right,
bool up,
bool down,
bool scrollUp,
bool scrollDown,
bool rightClick )

Definition at line 150 of file position_class.cpp.

151{
152 float radiansY, radiansX, speed;
153
154 // Set the speed of the camera if the right click is down.
155 if (scrollUp && rightClick)
156 {
157 m_cameraSpeed *= 1.1f;
158 }
159 if (scrollDown && rightClick)
160 {
161 m_cameraSpeed *= 0.9f;
162
163 if (m_cameraSpeed < 0.25f) // Minimum speed.
164 {
165 m_cameraSpeed = 0.25f;
166 }
167 }
168
169 // Convert degrees to radians.
170 radiansY = m_rotationY * 0.0174532925f;
171 radiansX = m_rotationX * 0.0174532925f;
172
174 // Update the position. //
176
177 // Moves the camera forward on a greater scale than the arrows.
178 if (scrollUp && !rightClick)
179 {
180 speed = m_speed * 20 * m_frameTime;
181 m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
182 m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
183 m_positionY -= sinf(radiansX) * speed;
184 }
185
186 // Moves the camera backward on a greater scale than the arrows.
187 if (scrollDown && !rightClick)
188 {
189 speed = m_speed * 20 * m_frameTime;
190 m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
191 m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
192 m_positionY += sinf(radiansX) * speed;
193 }
194
195 // Set the speed of the camera.
196 speed = m_cameraSpeed * m_frameTime;
197
198 // If moving forward, the position moves in the direction of the camera and accordingly to its angle.
199 if (forward)
200 {
201 m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
202 m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
203 m_positionY -= sinf(radiansX) * speed;
204 }
205
206 // If moving backward, the position moves in the opposite direction of the camera and accordingly to its angle.
207 if (backward)
208 {
209 m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
210 m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
211 m_positionY += sinf(radiansX) * speed;
212 }
213
214 // If moving left, the position moves to the left of the camera and accordingly to its angle.
215 if (left)
216 {
217 m_positionX -= cosf(radiansY) * speed;
218 m_positionZ += sinf(radiansY) * speed;
219 }
220
221 // If moving right, the position moves to the right of the camera and accordingly to its angle.
222 if (right)
223 {
224 m_positionX += cosf(radiansY) * speed;
225 m_positionZ -= sinf(radiansY) * speed;
226 }
227
228 // If moving up, the position moves up.
229 if (up)
230 {
231 m_positionY += speed;
232 }
233
234 // If moving down, the position moves down.
235 if (down)
236 {
237 m_positionY -= speed;
238 }
239
240 return;
241}

◆ SetFrameTime()

void position_class::SetFrameTime ( float time)

Definition at line 29 of file position_class.cpp.

30{
31 m_frameTime = time;
32 return;
33}

◆ TurnLeft()

void position_class::TurnLeft ( bool keydown)

Definition at line 50 of file position_class.cpp.

51{
52 // If the key is pressed increase the speed at which the camera turns left. If not slow down the turn speed.
53 if (keydown)
54 {
55 m_leftTurnSpeed += m_frameTime * 1.5f;
56
57 if (m_leftTurnSpeed > (m_frameTime * 200.0f))
58 {
59 m_leftTurnSpeed = m_frameTime * 200.0f;
60 }
61 }
62 else
63 {
64 m_leftTurnSpeed -= m_frameTime * 1.0f;
65
66 if (m_leftTurnSpeed < 0.0f)
67 {
68 m_leftTurnSpeed = 0.0f;
69 }
70 }
71
72 // Update the rotation using the turning speed.
73 m_rotationY -= m_leftTurnSpeed;
74 if (m_rotationY < 0.0f)
75 {
76 m_rotationY += 360.0f;
77 }
78
79 return;
80}

◆ TurnMouse()

void position_class::TurnMouse ( float deltaX,
float deltaY,
float sensitivity,
bool rightMouseDown )

Definition at line 115 of file position_class.cpp.

116{
117 // The turning speed is proportional to the horizontal mouse movement
118 m_horizontalTurnSpeed = deltaX * sensitivity;
119
120 if (rightMouseDown)
121 {
122 // Update the rotation using the turning speed
123 m_rotationY += m_horizontalTurnSpeed;
124 if (m_rotationY < 0.0f)
125 {
126 m_rotationY += 360.0f;
127 }
128 else if (m_rotationY > 360.0f)
129 {
130 m_rotationY -= 360.0f;
131 }
132
133 // The turning speed is proportional to the vertical mouse movement
134 m_verticalTurnSpeed = deltaY * sensitivity;
135
136 // Update the rotation using the turning speed
137 m_rotationX += m_verticalTurnSpeed;
138 if (m_rotationX < -90.0f)
139 {
140 m_rotationX = -90.0f;
141 }
142 else if (m_rotationX > 90.0f)
143 {
144 m_rotationX = 90.0f;
145 }
146 }
147 return;
148}

◆ TurnRight()

void position_class::TurnRight ( bool keydown)

Definition at line 83 of file position_class.cpp.

84{
85 // If the key is pressed increase the speed at which the camera turns right. If not slow down the turn speed.
86 if (keydown)
87 {
88 m_rightTurnSpeed += m_frameTime * 1.5f;
89
90 if (m_rightTurnSpeed > (m_frameTime * 200.0f))
91 {
92 m_rightTurnSpeed = m_frameTime * 200.0f;
93 }
94 }
95 else
96 {
97 m_rightTurnSpeed -= m_frameTime * 1.0f;
98
99 if (m_rightTurnSpeed < 0.0f)
100 {
101 m_rightTurnSpeed = 0.0f;
102 }
103 }
104
105 // Update the rotation using the turning speed.
106 m_rotationY += m_rightTurnSpeed;
107 if (m_rotationY > 360.0f)
108 {
109 m_rotationY -= 360.0f;
110 }
111
112 return;
113}

The documentation for this class was generated from the following files: