aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llviewerjoystick.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llviewerjoystick.cpp')
-rw-r--r--linden/indra/newview/llviewerjoystick.cpp272
1 files changed, 272 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewerjoystick.cpp b/linden/indra/newview/llviewerjoystick.cpp
new file mode 100644
index 0000000..bef769e
--- /dev/null
+++ b/linden/indra/newview/llviewerjoystick.cpp
@@ -0,0 +1,272 @@
1/**
2 * @file llviewerjoystick.cpp
3 * @brief Joystick functionality.
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * Second Life Viewer Source Code
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#include "llviewerprecompiledheaders.h"
30#include "llviewercontrol.h"
31#include "llviewerwindow.h"
32#include "llviewercamera.h"
33#include "llviewerjoystick.h"
34#include "viewer.h"
35#include "llkeyboard.h"
36
37static LLQuaternion sFlycamRotation;
38static LLVector3 sFlycamPosition;
39static F32 sFlycamZoom;
40
41BOOL LLViewerJoystick::sOverrideCamera = FALSE;
42
43void LLViewerJoystick::updateCamera(BOOL reset)
44{
45 static F32 last_delta[] = {0,0,0,0,0,0,0};
46 static F32 delta[] = { 0,0,0,0,0,0,0 };
47
48 LLWindow* window = gViewerWindow->getWindow();
49
50 F32 time = gFrameIntervalSeconds;
51
52 S32 axis[] =
53 {
54 gSavedSettings.getS32("FlycamAxis0"),
55 gSavedSettings.getS32("FlycamAxis1"),
56 gSavedSettings.getS32("FlycamAxis2"),
57 gSavedSettings.getS32("FlycamAxis3"),
58 gSavedSettings.getS32("FlycamAxis4"),
59 gSavedSettings.getS32("FlycamAxis5"),
60 gSavedSettings.getS32("FlycamAxis6")
61 };
62
63 F32 axis_scale[] =
64 {
65 gSavedSettings.getF32("FlycamAxisScale0"),
66 gSavedSettings.getF32("FlycamAxisScale1"),
67 gSavedSettings.getF32("FlycamAxisScale2"),
68 gSavedSettings.getF32("FlycamAxisScale3"),
69 gSavedSettings.getF32("FlycamAxisScale4"),
70 gSavedSettings.getF32("FlycamAxisScale5"),
71 gSavedSettings.getF32("FlycamAxisScale6")
72 };
73
74 F32 dead_zone[] =
75 {
76 gSavedSettings.getF32("FlycamAxisDeadZone0"),
77 gSavedSettings.getF32("FlycamAxisDeadZone1"),
78 gSavedSettings.getF32("FlycamAxisDeadZone2"),
79 gSavedSettings.getF32("FlycamAxisDeadZone3"),
80 gSavedSettings.getF32("FlycamAxisDeadZone4"),
81 gSavedSettings.getF32("FlycamAxisDeadZone5"),
82 gSavedSettings.getF32("FlycamAxisDeadZone6")
83 };
84
85 if (reset)
86 {
87 sFlycamPosition = gCamera->getOrigin();
88 sFlycamRotation = gCamera->getQuaternion();
89 sFlycamZoom = gCamera->getView();
90
91 for (U32 i = 0; i < 7; i++)
92 {
93 last_delta[i] = -window->getJoystickAxis(axis[i]);
94 delta[i] = 0.f;
95 }
96 return;
97 }
98
99 F32 cur_delta[7];
100 F32 feather = gSavedSettings.getF32("FlycamFeathering");
101 BOOL absolute = gSavedSettings.getBOOL("FlycamAbsolute");
102
103 for (U32 i = 0; i < 7; i++)
104 {
105 cur_delta[i] = -window->getJoystickAxis(axis[i]);
106 F32 tmp = cur_delta[i];
107 if (absolute)
108 {
109 cur_delta[i] = cur_delta[i] - last_delta[i];
110 }
111 last_delta[i] = tmp;
112
113 if (cur_delta[i] > 0)
114 {
115 cur_delta[i] = llmax(cur_delta[i]-dead_zone[i], 0.f);
116 }
117 else
118 {
119 cur_delta[i] = llmin(cur_delta[i]+dead_zone[i], 0.f);
120 }
121 cur_delta[i] *= axis_scale[i];
122
123 if (!absolute)
124 {
125 cur_delta[i] *= time;
126 }
127
128 delta[i] = delta[i] + (cur_delta[i]-delta[i])*time*feather;
129 }
130
131 sFlycamPosition += LLVector3(delta) * sFlycamRotation;
132
133 LLMatrix3 rot_mat(delta[3],
134 delta[4],
135 delta[5]);
136
137 sFlycamRotation = LLQuaternion(rot_mat)*sFlycamRotation;
138
139 if (gSavedSettings.getBOOL("FlycamAutoLeveling"))
140 {
141 LLMatrix3 level(sFlycamRotation);
142
143 LLVector3 x = LLVector3(level.mMatrix[0]);
144 LLVector3 y = LLVector3(level.mMatrix[1]);
145 LLVector3 z = LLVector3(level.mMatrix[2]);
146
147 y.mV[2] = 0.f;
148 y.normVec();
149
150 level.setRows(x,y,z);
151 level.orthogonalize();
152
153 LLQuaternion quat = LLQuaternion(level);
154 sFlycamRotation = nlerp(llmin(feather*time,1.f), sFlycamRotation, quat);
155 }
156
157 if (gSavedSettings.getBOOL("FlycamZoomDirect"))
158 {
159 sFlycamZoom = last_delta[6]*axis_scale[6]+dead_zone[6];
160 }
161 else
162 {
163 sFlycamZoom += delta[6];
164 }
165
166 LLMatrix3 mat(sFlycamRotation);
167
168 gCamera->setView(sFlycamZoom);
169 gCamera->setOrigin(sFlycamPosition);
170 gCamera->mXAxis = LLVector3(mat.mMatrix[0]);
171 gCamera->mYAxis = LLVector3(mat.mMatrix[1]);
172 gCamera->mZAxis = LLVector3(mat.mMatrix[2]);
173}
174
175
176void LLViewerJoystick::scanJoystick()
177{
178 if (!sOverrideCamera)
179 {
180 static U32 joystick_state = 0;
181 static U32 button_state = 0;
182
183 F32 xval = gViewerWindow->getWindow()->getJoystickAxis(0);
184 F32 yval = gViewerWindow->getWindow()->getJoystickAxis(1);
185
186 if (xval <= -0.5f)
187 {
188 if (!(joystick_state & 0x1))
189 {
190 gKeyboard->handleTranslatedKeyDown(KEY_PAD_LEFT, 0);
191 joystick_state |= 0x1;
192 }
193 }
194 else
195 {
196 if (joystick_state & 0x1)
197 {
198 gKeyboard->handleTranslatedKeyUp(KEY_PAD_LEFT, 0);
199 joystick_state &= ~0x1;
200 }
201 }
202 if (xval >= 0.5f)
203 {
204 if (!(joystick_state & 0x2))
205 {
206 gKeyboard->handleTranslatedKeyDown(KEY_PAD_RIGHT, 0);
207 joystick_state |= 0x2;
208 }
209 }
210 else
211 {
212 if (joystick_state & 0x2)
213 {
214 gKeyboard->handleTranslatedKeyUp(KEY_PAD_RIGHT, 0);
215 joystick_state &= ~0x2;
216 }
217 }
218 if (yval <= -0.5f)
219 {
220 if (!(joystick_state & 0x4))
221 {
222 gKeyboard->handleTranslatedKeyDown(KEY_PAD_UP, 0);
223 joystick_state |= 0x4;
224 }
225 }
226 else
227 {
228 if (joystick_state & 0x4)
229 {
230 gKeyboard->handleTranslatedKeyUp(KEY_PAD_UP, 0);
231 joystick_state &= ~0x4;
232 }
233 }
234 if (yval >= 0.5f)
235 {
236 if (!(joystick_state & 0x8))
237 {
238 gKeyboard->handleTranslatedKeyDown(KEY_PAD_DOWN, 0);
239 joystick_state |= 0x8;
240 }
241 }
242 else
243 {
244 if (joystick_state & 0x8)
245 {
246 gKeyboard->handleTranslatedKeyUp(KEY_PAD_DOWN, 0);
247 joystick_state &= ~0x8;
248 }
249 }
250
251 for( int i = 0; i < 15; i++ )
252 {
253 if ( gViewerWindow->getWindow()->getJoystickButton(i) & 0x80 )
254 {
255 if (!(button_state & (1<<i)))
256 {
257 gKeyboard->handleTranslatedKeyDown(KEY_BUTTON1+i, 0);
258 button_state |= (1<<i);
259 }
260 }
261 else
262 {
263 if (button_state & (1<<i))
264 {
265 gKeyboard->handleTranslatedKeyUp(KEY_BUTTON1+i, 0);
266 button_state &= ~(1<<i);
267 }
268 }
269 }
270 }
271}
272