annotate LightClone/Source/CameraController.cpp @ 38:2caa7c7e2cb5

Refactored program; Added dialog
author koryspansel
date Wed, 21 Sep 2011 21:40:19 -0700
parents 292e534f00c2
children 91e927584f92
rev   line source
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
1 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
2 * CameraController
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
3 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
4
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
5 #include "CameraController.h"
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
6
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
7 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
8 * CameraController
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
9 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
10 CameraController::CameraController(float fInitialDistance, float fInitialYaw, float fInitialPitch)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
11 {
10
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
12 nMode = CameraMode_3D;
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
13 fCameraDistance = fInitialDistance;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
14 fCameraYaw = fInitialYaw;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
15 fCameraPitch = fInitialPitch;
10
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
16 fViewAngle = D3DX_PI / 4.0f;
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
17 fMinimumZ = 1.0f;
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
18 fMaximumZ = 1024.0f;
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
19 }
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
20
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
21 /*
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
22 * SetMode
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
23 */
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
24 void CameraController::SetMode(uint32 nCameraMode)
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
25 {
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
26 nMode = nCameraMode;
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
27 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
28
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
29 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
30 * Render
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
31 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
32 void CameraController::Update(float fElapsed)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
33 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
34 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
35
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
36 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
37 * Yaw
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
38 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
39 void CameraController::Yaw(float fAmount)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
40 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
41 fCameraYaw += fAmount;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
42 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
43
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
44 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
45 * Pitch
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
46 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
47 void CameraController::Pitch(float fAmount)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
48 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
49 fCameraPitch += fAmount;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
50 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
51
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
52 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
53 * Move
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
54 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
55 void CameraController::Move(float fAmount)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
56 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
57 fCameraDistance += fAmount;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
58 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
59
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
60 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
61 * GetLocation
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
62 */
9
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
63 const D3DXVECTOR3 CameraController::GetLocation() const
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
64 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
65 const float fOffsetX = fCameraDistance * sinf(0.5f * D3DX_PI - fCameraPitch) * cosf(fCameraYaw);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
66 const float fOffsetY = fCameraDistance * cosf(0.5f * D3DX_PI - fCameraPitch);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
67 const float fOffsetZ = fCameraDistance * sinf(0.5f * D3DX_PI - fCameraPitch) * sinf(fCameraYaw);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
68
9
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
69 return D3DXVECTOR3(fOffsetX, fOffsetY, fOffsetZ);
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
70 }
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
71
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
72 /*
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
73 * GetDirection
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
74 */
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
75 const D3DXVECTOR3 CameraController::GetDirection() const
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
76 {
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
77 return D3DXVECTOR3(0.0f, 0.0f, 1.0f);
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
78 }
9
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
79
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
80 /*
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
81 * GetRight
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
82 */
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
83 const D3DXVECTOR3 CameraController::GetRight() const
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
84 {
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
85 return D3DXVECTOR3(1.0f, 0.0f, 0.0f);
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
86 }
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
87
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
88 /*
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
89 * GetUp
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
90 */
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
91 const D3DXVECTOR3 CameraController::GetUp() const
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
92 {
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
93 return D3DXVECTOR3(0.0f, 1.0f, 0.0f);
e494c4295dba Conversion to World architecture
koryspansel
parents: 0
diff changeset
94 }
10
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
95
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
96 /*
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
97 * GetProjection
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
98 */
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
99 const D3DXMATRIX CameraController::GetProjection(const D3DVIEWPORT9& kViewport) const
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
100 {
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
101 D3DXMATRIX kProjection;
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
102
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
103 if(nMode == CameraMode_2D)
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
104 {
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
105 D3DXMatrixOrthoLH(&kProjection, (float)kViewport.Width, (float)kViewport.Height, fMinimumZ, fMaximumZ);
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
106 }
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
107 else
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
108
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
109 if(nMode == CameraMode_3D)
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
110 {
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
111 D3DXMatrixPerspectiveFovLH(&kProjection, fViewAngle, (float)kViewport.Width / (float)kViewport.Height, fMinimumZ, fMaximumZ);
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
112 }
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
113
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
114 return kProjection;
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
115 }
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
116
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
117 /*
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
118 * GetView
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
119 */
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
120 const D3DXMATRIX CameraController::GetView() const
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
121 {
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
122 D3DXMATRIX kView;
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
123
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
124 if(nMode == CameraMode_2D)
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
125 {
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
126 D3DXMatrixIdentity(&kView);
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
127 }
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
128 else
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
129
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
130 if(nMode == CameraMode_3D)
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
131 {
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
132 const D3DXVECTOR3& kLocation = GetLocation();
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
133 const D3DXVECTOR3& kUp = GetUp();
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
134
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
135 D3DXMatrixLookAtLH(&kView, &kLocation, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &kUp);
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
136 }
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
137
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
138 return kView;
292e534f00c2 Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents: 9
diff changeset
139 }