forked from derandark/DungeonViewerAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelScene.cpp
82 lines (57 loc) · 1.95 KB
/
ModelScene.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
#include "StdAfx.h"
#include "PartArray.h"
#include "Render.h"
#include "RenderScene.h"
ModelScene::ModelScene()
{
m_LastCamUpdate = 0;
memset(&m_Keys, 0, sizeof(m_Keys));
}
ModelScene::~ModelScene()
{
}
void ModelScene::Input_KeyDown(BYTE bKey)
{
m_Keys[ bKey ] = TRUE;
}
void ModelScene::Input_KeyUp(BYTE bKey)
{
m_Keys[ bKey ] = FALSE;
}
void ModelScene::MoveCameraWithInput(float FrameTime, BOOL *Keys)
{
float MoveSpeed = 3.0f;
float TurnSpeed = D3DXToRadian(80.0);
Vector MoveDirection(0, 0, 0);
Vector RotateAngles(0, 0, 0);
// Move Forward/backward
if (Keys['W']) MoveDirection.y += FrameTime * MoveSpeed;
if (Keys['S']) MoveDirection.y -= FrameTime * MoveSpeed;
// Move Left/Right (straf)
if (Keys['A']) MoveDirection.x -= FrameTime * MoveSpeed;
if (Keys['D']) MoveDirection.x += FrameTime * MoveSpeed;
// Move Up/Down
if (Keys['R']) MoveDirection.z += FrameTime * MoveSpeed;
if (Keys['F']) MoveDirection.z -= FrameTime * MoveSpeed;
// Look Up/Down
if (Keys[VK_UP]) RotateAngles.x += TurnSpeed * FrameTime;
if (Keys[VK_DOWN]) RotateAngles.x -= TurnSpeed * FrameTime;
// Look Left/Right
if (Keys[VK_LEFT]) RotateAngles.z += TurnSpeed * FrameTime;
if (Keys[VK_RIGHT]) RotateAngles.z -= TurnSpeed * FrameTime;
// Adjust Tilt/Roll
if (Keys['Q']) RotateAngles.y -= TurnSpeed * FrameTime;
if (Keys['E']) RotateAngles.y += TurnSpeed * FrameTime;
// Apply rotation.
if (RotateAngles.x || RotateAngles.y || RotateAngles.z)
m_Camera.Rotate(RotateAngles);
// Apply movement.
if (MoveDirection.x || MoveDirection.y || MoveDirection.z)
m_Camera.Move(MoveDirection);
}
void ModelScene::UpdateCamera()
{
float FrameTime = (float)(Time::GetTimeElapsed() - m_LastCamUpdate);
MoveCameraWithInput(FrameTime, m_Keys);
m_LastCamUpdate = Time::GetTimeElapsed();
}