Mercurial > LightClone
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 | 1 /* |
2 * CameraController | |
3 */ | |
4 | |
5 #include "CameraController.h" | |
6 | |
7 /* | |
8 * CameraController | |
9 */ | |
10 CameraController::CameraController(float fInitialDistance, float fInitialYaw, float fInitialPitch) | |
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 | 13 fCameraDistance = fInitialDistance; |
14 fCameraYaw = fInitialYaw; | |
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 | 27 } |
28 | |
29 /* | |
30 * Render | |
31 */ | |
32 void CameraController::Update(float fElapsed) | |
33 { | |
34 } | |
35 | |
36 /* | |
37 * Yaw | |
38 */ | |
39 void CameraController::Yaw(float fAmount) | |
40 { | |
41 fCameraYaw += fAmount; | |
42 } | |
43 | |
44 /* | |
45 * Pitch | |
46 */ | |
47 void CameraController::Pitch(float fAmount) | |
48 { | |
49 fCameraPitch += fAmount; | |
50 } | |
51 | |
52 /* | |
53 * Move | |
54 */ | |
55 void CameraController::Move(float fAmount) | |
56 { | |
57 fCameraDistance += fAmount; | |
58 } | |
59 | |
60 /* | |
61 * GetLocation | |
62 */ | |
9 | 63 const D3DXVECTOR3 CameraController::GetLocation() const |
0 | 64 { |
65 const float fOffsetX = fCameraDistance * sinf(0.5f * D3DX_PI - fCameraPitch) * cosf(fCameraYaw); | |
66 const float fOffsetY = fCameraDistance * cosf(0.5f * D3DX_PI - fCameraPitch); | |
67 const float fOffsetZ = fCameraDistance * sinf(0.5f * D3DX_PI - fCameraPitch) * sinf(fCameraYaw); | |
68 | |
9 | 69 return D3DXVECTOR3(fOffsetX, fOffsetY, fOffsetZ); |
70 } | |
71 | |
72 /* | |
73 * GetDirection | |
74 */ | |
75 const D3DXVECTOR3 CameraController::GetDirection() const | |
76 { | |
77 return D3DXVECTOR3(0.0f, 0.0f, 1.0f); | |
0 | 78 } |
9 | 79 |
80 /* | |
81 * GetRight | |
82 */ | |
83 const D3DXVECTOR3 CameraController::GetRight() const | |
84 { | |
85 return D3DXVECTOR3(1.0f, 0.0f, 0.0f); | |
86 } | |
87 | |
88 /* | |
89 * GetUp | |
90 */ | |
91 const D3DXVECTOR3 CameraController::GetUp() const | |
92 { | |
93 return D3DXVECTOR3(0.0f, 1.0f, 0.0f); | |
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 } |