llviewerjoystick.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. /**
  2. * @file llviewerjoystick.cpp
  3. * @brief Joystick / NDOF device functionality.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llviewerjoystick.h"
  34. #include "llfocusmgr.h"
  35. #include "llkeyboard.h"
  36. #include "llsys.h"
  37. #include "llagent.h"
  38. #include "llappviewer.h" // For gFrameIntervalSeconds
  39. //MK
  40. #include "mkrlinterface.h"
  41. //mk
  42. #include "llselectmgr.h"
  43. #include "lltoolmgr.h"
  44. #include "hbviewerautomation.h"
  45. #include "llviewercamera.h"
  46. #include "llviewercontrol.h"
  47. #include "llviewermenu.h"
  48. #include "llviewerwindow.h" // For gAwayTimer
  49. // Constants
  50. #define X_I 1
  51. #define Y_I 2
  52. #define Z_I 0
  53. #define RX_I 4
  54. #define RY_I 5
  55. #define RZ_I 3
  56. // Flycam translations in build mode should be reduced
  57. constexpr F32 BUILDMODE_FLYCAM_T_SCALE = 3.f;
  58. // Minimum time after setting away state before coming back
  59. constexpr F32 MIN_AFK_TIME = 2.f;
  60. F32 LLViewerJoystick::sLastDelta[] = { 0, 0, 0, 0, 0, 0, 0 };
  61. F32 LLViewerJoystick::sDelta[] = { 0, 0, 0, 0, 0, 0, 0 };
  62. // These constants specify the maximum absolute value coming in from the
  63. // device.
  64. // *HACK: the value of MAX_JOYSTICK_INPUT_VALUE is not arbitrary as it should
  65. // be. It has to be equal to 3000 because the SpaceNavigator on Windows refuses
  66. // to respond to the DirectInput SetProperty call; it always returns values in
  67. // the [-3000, 3000] range.
  68. #define MAX_SPACENAVIGATOR_INPUT 3000.0f
  69. #define MAX_JOYSTICK_INPUT_VALUE MAX_SPACENAVIGATOR_INPUT
  70. void LLViewerJoystick::updateEnabled(bool autoenable)
  71. {
  72. if (mDriverState == JDS_UNINITIALIZED)
  73. {
  74. gSavedSettings.setBool("JoystickEnabled", false);
  75. }
  76. else if (isLikeSpaceNavigator() && autoenable)
  77. {
  78. gSavedSettings.setBool("JoystickEnabled", true);
  79. }
  80. if (!mJoystickEnabled)
  81. {
  82. mOverrideCamera = false;
  83. }
  84. }
  85. void LLViewerJoystick::setOverrideCamera(bool val)
  86. {
  87. if (!mJoystickEnabled)
  88. {
  89. mOverrideCamera = false;
  90. }
  91. else
  92. {
  93. mOverrideCamera = val;
  94. }
  95. if (mOverrideCamera)
  96. {
  97. gAgent.changeCameraToDefault();
  98. }
  99. }
  100. //static
  101. NDOF_HotPlugResult LLViewerJoystick::hotPlugAddCallback(NDOF_Device* dev)
  102. {
  103. NDOF_HotPlugResult res = NDOF_DISCARD_HOTPLUGGED;
  104. LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
  105. if (joystick->mDriverState == JDS_UNINITIALIZED)
  106. {
  107. llinfos << "Will use device: " << llendl;
  108. ndof_dump(stderr, dev);
  109. joystick->mNdofDev = dev;
  110. joystick->mDriverState = JDS_INITIALIZED;
  111. res = NDOF_KEEP_HOTPLUGGED;
  112. }
  113. joystick->updateEnabled(true);
  114. return res;
  115. }
  116. //static
  117. void LLViewerJoystick::hotPlugRemovalCallback(NDOF_Device* dev)
  118. {
  119. LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
  120. if (joystick->mNdofDev == dev)
  121. {
  122. llinfos << "joystick->mNdofDev=" << joystick->mNdofDev
  123. << "; removed device:" << llendl;
  124. ndof_dump(stderr, dev);
  125. joystick->mDriverState = JDS_UNINITIALIZED;
  126. }
  127. joystick->updateEnabled(true);
  128. }
  129. LLViewerJoystick::LLViewerJoystick()
  130. : mDriverState(JDS_UNINITIALIZED),
  131. mNdofDev(NULL),
  132. mResetFlag(false),
  133. mCameraUpdated(true),
  134. mOverrideCamera(false),
  135. mJoystickRun(0),
  136. mJoystickEnabled(LLCachedControl<bool>(gSavedSettings, "JoystickEnabled")),
  137. mJoystickAvatarEnabled(LLCachedControl<bool>(gSavedSettings,
  138. "JoystickAvatarEnabled")),
  139. mJoystickFlycamEnabled(LLCachedControl<bool>(gSavedSettings,
  140. "JoystickFlycamEnabled")),
  141. mJoystickBuildEnabled(LLCachedControl<bool>(gSavedSettings,
  142. "JoystickBuildEnabled")),
  143. mCursor3D(LLCachedControl<bool>(gSavedSettings, "Cursor3D")),
  144. mJoystickAxis0(LLCachedControl<S32>(gSavedSettings, "JoystickAxis0")),
  145. mJoystickAxis1(LLCachedControl<S32>(gSavedSettings, "JoystickAxis1")),
  146. mJoystickAxis2(LLCachedControl<S32>(gSavedSettings, "JoystickAxis2")),
  147. mJoystickAxis3(LLCachedControl<S32>(gSavedSettings, "JoystickAxis3")),
  148. mJoystickAxis4(LLCachedControl<S32>(gSavedSettings, "JoystickAxis4")),
  149. mJoystickAxis5(LLCachedControl<S32>(gSavedSettings, "JoystickAxis5")),
  150. mJoystickAxis6(LLCachedControl<S32>(gSavedSettings, "JoystickAxis6"))
  151. {
  152. for (U32 i = 0; i < 6; ++i)
  153. {
  154. mAxes[i] = sDelta[i] = sLastDelta[i] = 0.f;
  155. }
  156. for (U32 i = 0; i < 16; ++i)
  157. {
  158. mBtn[i] = false;
  159. }
  160. // Factor in bandwidth ? bandwidth = gViewerStats->mKBitStat
  161. mPerfScale = 4000.f / LLCPUInfo::getInstance()->getMHz();
  162. }
  163. LLViewerJoystick::~LLViewerJoystick()
  164. {
  165. if (mDriverState == JDS_INITIALIZED)
  166. {
  167. terminate();
  168. }
  169. }
  170. void LLViewerJoystick::init(bool autoenable)
  171. {
  172. if (gSavedSettings.getBool("JoystickNeverEnable"))
  173. {
  174. return;
  175. }
  176. static bool libinit = false;
  177. mDriverState = JDS_INITIALIZING;
  178. if (!libinit)
  179. {
  180. // Note: the HotPlug callbacks are not actually getting called on
  181. // Windows
  182. if (ndof_libinit(hotPlugAddCallback,
  183. hotPlugRemovalCallback,
  184. NULL))
  185. {
  186. mDriverState = JDS_UNINITIALIZED;
  187. }
  188. else
  189. {
  190. // NB: ndof_libinit succeeds when there is no device
  191. libinit = true;
  192. // Allocate memory once for an eventual device
  193. mNdofDev = ndof_create();
  194. }
  195. }
  196. if (libinit)
  197. {
  198. if (mNdofDev)
  199. {
  200. // Different joysticks will return different ranges of raw values.
  201. // Since we want to handle every device in the same uniform way,
  202. // we initialize the mNdofDev struct and we set the range
  203. // of values we would like to receive.
  204. //
  205. // *HACK: on Windows, libndofdev passes our range to DI with a
  206. // SetProperty call. This works but with one notable exception, the
  207. // SpaceNavigator which does not seem to care about the SetProperty
  208. // call. In theory, we should handle this case inside libndofdev.
  209. // However, the range we are setting here is arbitrary anyway, so
  210. // let's just use the SpaceNavigator range for our purposes.
  211. mNdofDev->axes_min = (long)-MAX_JOYSTICK_INPUT_VALUE;
  212. mNdofDev->axes_max = (long)+MAX_JOYSTICK_INPUT_VALUE;
  213. // libndofdev could be used to return deltas. Here we choose to
  214. // just have the absolute values instead.
  215. mNdofDev->absolute = 1;
  216. // Init & use the first suitable NDOF device found on the USB chain
  217. if (ndof_init_first(mNdofDev, NULL))
  218. {
  219. mDriverState = JDS_UNINITIALIZED;
  220. if (mJoystickEnabled)
  221. {
  222. llwarns << "No NDOF device found. Joystick control unavailable."
  223. << llendl;
  224. }
  225. }
  226. else
  227. {
  228. mDriverState = JDS_INITIALIZED;
  229. }
  230. }
  231. else
  232. {
  233. mDriverState = JDS_UNINITIALIZED;
  234. }
  235. }
  236. // Autoenable the joystick for recognized devices if nothing was connected
  237. // previously
  238. if (!autoenable)
  239. {
  240. autoenable = gSavedSettings.getString("JoystickInitialized").empty();
  241. }
  242. updateEnabled(autoenable);
  243. if (mDriverState == JDS_INITIALIZED)
  244. {
  245. // A Joystick device is plugged in
  246. if (isLikeSpaceNavigator())
  247. {
  248. // It is a space navigator, we have defaults for it.
  249. if (gSavedSettings.getString("JoystickInitialized") !=
  250. "SpaceNavigator")
  251. {
  252. // Only set the defaults if we have not already (in case they
  253. // were overridden)
  254. setSNDefaults();
  255. gSavedSettings.setString("JoystickInitialized",
  256. "SpaceNavigator");
  257. }
  258. }
  259. else
  260. {
  261. std::string device = getDescription();
  262. if (device.empty())
  263. {
  264. device = "UnknownDevice";
  265. }
  266. // It is not a Space Navigator
  267. gSavedSettings.setString("JoystickInitialized", device);
  268. }
  269. }
  270. llinfos << "ndof: mDriverState=" << mDriverState << "; mNdofDev="
  271. << mNdofDev << "; libinit=" << libinit << llendl;
  272. }
  273. void LLViewerJoystick::terminate()
  274. {
  275. if (mNdofDev)
  276. {
  277. mNdofDev = NULL;
  278. llinfos << "Terminating connection with NDOF device..." << llendl;
  279. ndof_libcleanup();
  280. mDriverState = JDS_UNINITIALIZED;
  281. llinfos << "NDOF device freed." << llendl;
  282. }
  283. }
  284. void LLViewerJoystick::updateStatus()
  285. {
  286. if (!mNdofDev)
  287. {
  288. return;
  289. }
  290. ndof_update(mNdofDev);
  291. for (U32 i = 0; i < 6; ++i)
  292. {
  293. mAxes[i] = (F32)mNdofDev->axes[i] / mNdofDev->axes_max;
  294. }
  295. S32 new_state = 0; // Bitmap of the currently pressed buttons
  296. for (S32 i = 15; i >= 0; --i)
  297. {
  298. bool active = mBtn[i] = mNdofDev->buttons[i] != 0;
  299. new_state <<= 1;
  300. if (active)
  301. {
  302. ++new_state;
  303. }
  304. }
  305. static S32 old_state = 0; // Bitmap of the formerly pressed buttons
  306. if (new_state != old_state && gAutomationp)
  307. {
  308. gAutomationp->onJoystickButtons(old_state, new_state);
  309. old_state = new_state;
  310. }
  311. }
  312. F32 LLViewerJoystick::getJoystickAxis(S32 axis) const
  313. {
  314. if (axis >= 0 && axis < 6)
  315. {
  316. return mAxes[axis];
  317. }
  318. return 0.f;
  319. }
  320. bool LLViewerJoystick::getJoystickButton(S32 button) const
  321. {
  322. if (button >= 0 && button < 16)
  323. {
  324. return mBtn[button];
  325. }
  326. return false;
  327. }
  328. void LLViewerJoystick::handleRun(F32 inc)
  329. {
  330. //MK
  331. if (gRLenabled && gRLInterface.mContainsRun)
  332. {
  333. mJoystickRun = 0;
  334. if (gAgent.getRunning())
  335. {
  336. gAgent.clearRunning();
  337. gAgent.sendWalkRun(false);
  338. }
  339. return;
  340. }
  341. //mk
  342. // Decide whether to walk or run by applying a threshold, with slight
  343. // hysteresis to avoid oscillating between the two with input spikes.
  344. // Analog speed control would be better, but not likely any time soon.
  345. static LLCachedControl<F32> run_threshold(gSavedSettings,
  346. "JoystickRunThreshold");
  347. if (inc > run_threshold)
  348. {
  349. if (mJoystickRun == 1)
  350. {
  351. ++mJoystickRun;
  352. gAgent.setRunning();
  353. gAgent.sendWalkRun(true);
  354. }
  355. else if (mJoystickRun == 0)
  356. {
  357. // Hysteresis: respond NEXT frame
  358. ++mJoystickRun;
  359. }
  360. }
  361. else if (mJoystickRun > 0)
  362. {
  363. if (--mJoystickRun == 0)
  364. {
  365. gAgent.clearRunning();
  366. gAgent.sendWalkRun(false);
  367. }
  368. }
  369. }
  370. void LLViewerJoystick::agentJump()
  371. {
  372. gAgent.moveUp(1);
  373. }
  374. void LLViewerJoystick::agentSlide(F32 inc)
  375. {
  376. if (inc < 0.f)
  377. {
  378. gAgent.moveLeft(1);
  379. }
  380. else if (inc > 0.f)
  381. {
  382. gAgent.moveLeft(-1);
  383. }
  384. }
  385. void LLViewerJoystick::agentPush(F32 inc)
  386. {
  387. if (inc < 0.f) // forward
  388. {
  389. gAgent.moveAt(1, false);
  390. }
  391. else if (inc > 0.f) // backward
  392. {
  393. gAgent.moveAt(-1, false);
  394. }
  395. }
  396. void LLViewerJoystick::agentFly(F32 inc)
  397. {
  398. static LLCachedControl<bool> automatic_fly(gSavedSettings, "AutomaticFly");
  399. if (inc < 0.f)
  400. {
  401. if (automatic_fly && !gAgent.getFlying() && gAgent.canFly() &&
  402. !gAgent.upGrabbed())
  403. {
  404. gAgent.setFlying(true);
  405. }
  406. gAgent.moveUp(1);
  407. }
  408. else if (inc > 0.f)
  409. {
  410. // Crouch
  411. gAgent.moveUp(-1);
  412. }
  413. }
  414. void LLViewerJoystick::agentRotate(F32 pitch_inc, F32 yaw_inc)
  415. {
  416. LLQuaternion new_rot;
  417. pitch_inc = gAgent.clampPitchToLimits(-pitch_inc);
  418. const LLQuaternion qx(pitch_inc, gAgent.getLeftAxis());
  419. const LLQuaternion qy(-yaw_inc, gAgent.getReferenceUpVector());
  420. new_rot.set(qx * qy);
  421. gAgent.rotate(new_rot);
  422. }
  423. void LLViewerJoystick::resetDeltas(S32 axis[])
  424. {
  425. for (U32 i = 0; i < 6; ++i)
  426. {
  427. sLastDelta[i] = -mAxes[axis[i]];
  428. sDelta[i] = 0.f;
  429. }
  430. sLastDelta[6] = sDelta[6] = 0.f;
  431. mResetFlag = false;
  432. }
  433. void LLViewerJoystick::moveObjects(bool reset)
  434. {
  435. static bool toggle_send_to_sim = false;
  436. if (mDriverState != JDS_INITIALIZED || !gFocusMgr.getAppHasFocus() ||
  437. !mJoystickEnabled || !mJoystickBuildEnabled)
  438. {
  439. return;
  440. }
  441. S32 axis[] =
  442. {
  443. (S32)mJoystickAxis0,
  444. (S32)mJoystickAxis1,
  445. (S32)mJoystickAxis2,
  446. (S32)mJoystickAxis3,
  447. (S32)mJoystickAxis4,
  448. (S32)mJoystickAxis5
  449. };
  450. if (reset || mResetFlag)
  451. {
  452. resetDeltas(axis);
  453. return;
  454. }
  455. static LLCachedControl<F32> axis_scale0(gSavedSettings,
  456. "BuildAxisScale0");
  457. static LLCachedControl<F32> axis_scale1(gSavedSettings,
  458. "BuildAxisScale1");
  459. static LLCachedControl<F32> axis_scale2(gSavedSettings,
  460. "BuildAxisScale2");
  461. static LLCachedControl<F32> axis_scale3(gSavedSettings,
  462. "BuildAxisScale3");
  463. static LLCachedControl<F32> axis_scale4(gSavedSettings,
  464. "BuildAxisScale4");
  465. static LLCachedControl<F32> axis_scale5(gSavedSettings,
  466. "BuildAxisScale5");
  467. F32 axis_scale[] =
  468. {
  469. (F32)axis_scale0,
  470. (F32)axis_scale1,
  471. (F32)axis_scale2,
  472. (F32)axis_scale3,
  473. (F32)axis_scale4,
  474. (F32)axis_scale5
  475. };
  476. static LLCachedControl<F32> dead_zone0(gSavedSettings,
  477. "BuildAxisDeadZone0");
  478. static LLCachedControl<F32> dead_zone1(gSavedSettings,
  479. "BuildAxisDeadZone1");
  480. static LLCachedControl<F32> dead_zone2(gSavedSettings,
  481. "BuildAxisDeadZone2");
  482. static LLCachedControl<F32> dead_zone3(gSavedSettings,
  483. "BuildAxisDeadZone3");
  484. static LLCachedControl<F32> dead_zone4(gSavedSettings,
  485. "BuildAxisDeadZone4");
  486. static LLCachedControl<F32> dead_zone5(gSavedSettings,
  487. "BuildAxisDeadZone5");
  488. F32 dead_zone[] =
  489. {
  490. (F32)dead_zone0,
  491. (F32)dead_zone1,
  492. (F32)dead_zone2,
  493. (F32)dead_zone3,
  494. (F32)dead_zone4,
  495. (F32)dead_zone5
  496. };
  497. F32 cur_delta[6];
  498. F32 time = gFrameIntervalSeconds;
  499. // Avoid making ridicously big movements if there is a big drop in fps
  500. if (time > .2f)
  501. {
  502. time = .2f;
  503. }
  504. // Max feather is 32
  505. static LLCachedControl<F32> feather(gSavedSettings, "BuildFeathering");
  506. bool absolute = mCursor3D;
  507. bool is_zero = true;
  508. for (U32 i = 0; i < 6; ++i)
  509. {
  510. cur_delta[i] = -mAxes[axis[i]];
  511. F32 tmp = cur_delta[i];
  512. if (absolute)
  513. {
  514. cur_delta[i] = cur_delta[i] - sLastDelta[i];
  515. }
  516. sLastDelta[i] = tmp;
  517. is_zero = is_zero && (cur_delta[i] == 0.f);
  518. if (cur_delta[i] > 0)
  519. {
  520. cur_delta[i] = llmax(cur_delta[i] - dead_zone[i], 0.f);
  521. }
  522. else
  523. {
  524. cur_delta[i] = llmin(cur_delta[i] + dead_zone[i], 0.f);
  525. }
  526. cur_delta[i] *= axis_scale[i];
  527. if (!absolute)
  528. {
  529. cur_delta[i] *= time;
  530. }
  531. sDelta[i] = sDelta[i] + (cur_delta[i] - sDelta[i]) * time * feather;
  532. }
  533. U32 upd_type = UPD_NONE;
  534. LLVector3 v;
  535. if (!is_zero)
  536. {
  537. // Clear AFK state if moved beyond the deadzone
  538. if (gAwayTimer.getElapsedTimeF32() > MIN_AFK_TIME)
  539. {
  540. gAgent.clearAFK();
  541. }
  542. if (sDelta[0] || sDelta[1] || sDelta[2])
  543. {
  544. upd_type |= UPD_POSITION;
  545. v.set(sDelta[0], sDelta[1], sDelta[2]);
  546. }
  547. if (sDelta[3] || sDelta[4] || sDelta[5])
  548. {
  549. upd_type |= UPD_ROTATION;
  550. }
  551. // The selection update could fail, so we would not send
  552. if (gSelectMgr.selectionMove(v, sDelta[3],sDelta[4],sDelta[5], upd_type))
  553. {
  554. toggle_send_to_sim = true;
  555. }
  556. }
  557. else if (toggle_send_to_sim)
  558. {
  559. gSelectMgr.sendSelectionMove();
  560. toggle_send_to_sim = false;
  561. }
  562. }
  563. void LLViewerJoystick::moveAvatar(bool reset)
  564. {
  565. if (mDriverState != JDS_INITIALIZED || !gFocusMgr.getAppHasFocus() ||
  566. !mJoystickEnabled || !mJoystickAvatarEnabled)
  567. {
  568. return;
  569. }
  570. S32 axis[] =
  571. {
  572. // [1 0 2 4 3 5]
  573. // [Z X Y RZ RX RY]
  574. (S32)mJoystickAxis0,
  575. (S32)mJoystickAxis1,
  576. (S32)mJoystickAxis2,
  577. (S32)mJoystickAxis3,
  578. (S32)mJoystickAxis4,
  579. (S32)mJoystickAxis5
  580. };
  581. if (reset || mResetFlag)
  582. {
  583. resetDeltas(axis);
  584. if (reset)
  585. {
  586. // Note: moving the agent triggers agent camera mode; do not do
  587. // this every time we set mResetFlag (e.g. because we gained focus)
  588. gAgent.moveAt(0, true);
  589. }
  590. return;
  591. }
  592. bool is_zero = true;
  593. static LLCachedControl<S32> jump_button(gSavedSettings,
  594. "JoystickButtonJump");
  595. if (getJoystickButton(jump_button))
  596. {
  597. agentJump();
  598. is_zero = false;
  599. }
  600. static LLCachedControl<F32> axis_scale0(gSavedSettings,
  601. "AvatarAxisScale0");
  602. static LLCachedControl<F32> axis_scale1(gSavedSettings,
  603. "AvatarAxisScale1");
  604. static LLCachedControl<F32> axis_scale2(gSavedSettings,
  605. "AvatarAxisScale2");
  606. static LLCachedControl<F32> axis_scale3(gSavedSettings,
  607. "AvatarAxisScale3");
  608. static LLCachedControl<F32> axis_scale4(gSavedSettings,
  609. "AvatarAxisScale4");
  610. static LLCachedControl<F32> axis_scale5(gSavedSettings,
  611. "AvatarAxisScale5");
  612. F32 axis_scale[] =
  613. {
  614. (F32)axis_scale0,
  615. (F32)axis_scale1,
  616. (F32)axis_scale2,
  617. (F32)axis_scale3,
  618. (F32)axis_scale4,
  619. (F32)axis_scale5
  620. };
  621. static LLCachedControl<F32> dead_zone0(gSavedSettings,
  622. "AvatarAxisDeadZone0");
  623. static LLCachedControl<F32> dead_zone1(gSavedSettings,
  624. "AvatarAxisDeadZone1");
  625. static LLCachedControl<F32> dead_zone2(gSavedSettings,
  626. "AvatarAxisDeadZone2");
  627. static LLCachedControl<F32> dead_zone3(gSavedSettings,
  628. "AvatarAxisDeadZone3");
  629. static LLCachedControl<F32> dead_zone4(gSavedSettings,
  630. "AvatarAxisDeadZone4");
  631. static LLCachedControl<F32> dead_zone5(gSavedSettings,
  632. "AvatarAxisDeadZone5");
  633. F32 dead_zone[] =
  634. {
  635. (F32)dead_zone0,
  636. (F32)dead_zone1,
  637. (F32)dead_zone2,
  638. (F32)dead_zone3,
  639. (F32)dead_zone4,
  640. (F32)dead_zone5
  641. };
  642. // Time interval in seconds between this frame and the previous
  643. F32 time = gFrameIntervalSeconds;
  644. // Avoid making ridicously big movements if there is a big drop in fps
  645. if (time > .2f)
  646. {
  647. time = .2f;
  648. }
  649. // Note: max feather is 32.0
  650. static LLCachedControl<F32> feather(gSavedSettings, "AvatarFeathering");
  651. F32 cur_delta[6];
  652. F32 val, dom_mov = 0.f;
  653. U32 dom_axis = Z_I;
  654. bool absolute = mCursor3D && mNdofDev->absolute;
  655. // Remove dead zones and determine biggest movement on the joystick
  656. for (U32 i = 0; i < 6; ++i)
  657. {
  658. cur_delta[i] = -mAxes[axis[i]];
  659. if (absolute)
  660. {
  661. F32 tmp = cur_delta[i];
  662. cur_delta[i] = cur_delta[i] - sLastDelta[i];
  663. sLastDelta[i] = tmp;
  664. }
  665. if (cur_delta[i] > 0)
  666. {
  667. cur_delta[i] = llmax(cur_delta[i]-dead_zone[i], 0.f);
  668. }
  669. else
  670. {
  671. cur_delta[i] = llmin(cur_delta[i]+dead_zone[i], 0.f);
  672. }
  673. // We do not care about Roll (RZ) and Z is calculated after the loop
  674. if (i != Z_I && i != RZ_I)
  675. {
  676. // find out the axis with the biggest joystick motion
  677. val = fabs(cur_delta[i]);
  678. if (val > dom_mov)
  679. {
  680. dom_axis = i;
  681. dom_mov = val;
  682. }
  683. }
  684. is_zero = is_zero && (cur_delta[i] == 0.f);
  685. }
  686. if (!is_zero)
  687. {
  688. // Clear AFK state if moved beyond the deadzone
  689. if (gAwayTimer.getElapsedTimeF32() > MIN_AFK_TIME)
  690. {
  691. gAgent.clearAFK();
  692. }
  693. setCameraNeedsUpdate(true);
  694. }
  695. // Forward|backward movements overrule the real dominant movement if they
  696. // are bigger than its 20%. This is what you want 'cos moving forward is
  697. // what you do most. We also added a special (even more lenient) case for
  698. // RX|RY to allow walking while pitching and turning
  699. if (fabs(cur_delta[Z_I]) > .2f * dom_mov ||
  700. ((dom_axis == RX_I || dom_axis == RY_I) &&
  701. fabs(cur_delta[Z_I]) > .05f * dom_mov))
  702. {
  703. dom_axis = Z_I;
  704. }
  705. sDelta[X_I] = -cur_delta[X_I] * axis_scale[X_I];
  706. sDelta[Y_I] = -cur_delta[Y_I] * axis_scale[Y_I];
  707. sDelta[Z_I] = -cur_delta[Z_I] * axis_scale[Z_I];
  708. cur_delta[RX_I] *= -axis_scale[RX_I] * mPerfScale;
  709. cur_delta[RY_I] *= -axis_scale[RY_I] * mPerfScale;
  710. if (!absolute)
  711. {
  712. cur_delta[RX_I] *= time;
  713. cur_delta[RY_I] *= time;
  714. }
  715. sDelta[RX_I] += (cur_delta[RX_I] - sDelta[RX_I]) * time * feather;
  716. sDelta[RY_I] += (cur_delta[RY_I] - sDelta[RY_I]) * time * feather;
  717. handleRun(sqrtf(sDelta[Z_I] * sDelta[Z_I] + sDelta[X_I] * sDelta[X_I]));
  718. // Allow forward/backward movement some priority
  719. if (dom_axis == Z_I)
  720. {
  721. agentPush(sDelta[Z_I]); // forward/back
  722. if (fabs(sDelta[X_I]) > .1f)
  723. {
  724. agentSlide(sDelta[X_I]); // move sideways
  725. }
  726. if (fabs(sDelta[Y_I]) > .1f)
  727. {
  728. agentFly(sDelta[Y_I]); // up/down & crouch
  729. }
  730. // too many rotations during walking can be confusing, so apply
  731. // the deadzones one more time (quick & dirty), at 50%|30% power
  732. F32 eff_rx = .3f * dead_zone[RX_I];
  733. F32 eff_ry = .3f * dead_zone[RY_I];
  734. if (sDelta[RX_I] > 0)
  735. {
  736. eff_rx = llmax(sDelta[RX_I] - eff_rx, 0.f);
  737. }
  738. else
  739. {
  740. eff_rx = llmin(sDelta[RX_I] + eff_rx, 0.f);
  741. }
  742. if (sDelta[RY_I] > 0)
  743. {
  744. eff_ry = llmax(sDelta[RY_I] - eff_ry, 0.f);
  745. }
  746. else
  747. {
  748. eff_ry = llmin(sDelta[RY_I] + eff_ry, 0.f);
  749. }
  750. if (fabs(eff_rx) > 0.f || fabs(eff_ry) > 0.f)
  751. {
  752. if (gAgent.getFlying())
  753. {
  754. agentRotate(eff_rx, eff_ry);
  755. }
  756. else
  757. {
  758. agentRotate(eff_rx, 2.f * eff_ry);
  759. }
  760. }
  761. }
  762. else
  763. {
  764. agentSlide(sDelta[X_I]); // move sideways
  765. agentFly(sDelta[Y_I]); // up/down & crouch
  766. agentPush(sDelta[Z_I]); // forward/back
  767. agentRotate(sDelta[RX_I], sDelta[RY_I]); // pitch & turn
  768. }
  769. }
  770. void LLViewerJoystick::moveFlycam(bool reset)
  771. {
  772. static LLQuaternion sFlycamRotation;
  773. static LLVector3 sFlycamPosition;
  774. static F32 sFlycamZoom;
  775. if (mDriverState != JDS_INITIALIZED || !gFocusMgr.getAppHasFocus() ||
  776. !mJoystickEnabled || !mJoystickFlycamEnabled)
  777. {
  778. return;
  779. }
  780. S32 axis[] =
  781. {
  782. (S32)mJoystickAxis0,
  783. (S32)mJoystickAxis1,
  784. (S32)mJoystickAxis2,
  785. (S32)mJoystickAxis3,
  786. (S32)mJoystickAxis4,
  787. (S32)mJoystickAxis5,
  788. (S32)mJoystickAxis6
  789. };
  790. if (reset || mResetFlag)
  791. {
  792. sFlycamPosition = gViewerCamera.getOrigin();
  793. sFlycamRotation = gViewerCamera.getQuaternion();
  794. sFlycamZoom = gViewerCamera.getView();
  795. resetDeltas(axis);
  796. return;
  797. }
  798. static LLCachedControl<F32> axis_scale0(gSavedSettings,
  799. "FlycamAxisScale0");
  800. static LLCachedControl<F32> axis_scale1(gSavedSettings,
  801. "FlycamAxisScale1");
  802. static LLCachedControl<F32> axis_scale2(gSavedSettings,
  803. "FlycamAxisScale2");
  804. static LLCachedControl<F32> axis_scale3(gSavedSettings,
  805. "FlycamAxisScale3");
  806. static LLCachedControl<F32> axis_scale4(gSavedSettings,
  807. "FlycamAxisScale4");
  808. static LLCachedControl<F32> axis_scale5(gSavedSettings,
  809. "FlycamAxisScale5");
  810. static LLCachedControl<F32> axis_scale6(gSavedSettings,
  811. "FlycamAxisScale6");
  812. F32 axis_scale[] =
  813. {
  814. (F32)axis_scale0,
  815. (F32)axis_scale1,
  816. (F32)axis_scale2,
  817. (F32)axis_scale3,
  818. (F32)axis_scale4,
  819. (F32)axis_scale5,
  820. (F32)axis_scale6
  821. };
  822. static LLCachedControl<F32> dead_zone0(gSavedSettings,
  823. "FlycamAxisDeadZone0");
  824. static LLCachedControl<F32> dead_zone1(gSavedSettings,
  825. "FlycamAxisDeadZone1");
  826. static LLCachedControl<F32> dead_zone2(gSavedSettings,
  827. "FlycamAxisDeadZone2");
  828. static LLCachedControl<F32> dead_zone3(gSavedSettings,
  829. "FlycamAxisDeadZone3");
  830. static LLCachedControl<F32> dead_zone4(gSavedSettings,
  831. "FlycamAxisDeadZone4");
  832. static LLCachedControl<F32> dead_zone5(gSavedSettings,
  833. "FlycamAxisDeadZone5");
  834. static LLCachedControl<F32> dead_zone6(gSavedSettings,
  835. "FlycamAxisDeadZone6");
  836. F32 dead_zone[] =
  837. {
  838. (F32)dead_zone0,
  839. (F32)dead_zone1,
  840. (F32)dead_zone2,
  841. (F32)dead_zone3,
  842. (F32)dead_zone4,
  843. (F32)dead_zone5,
  844. (F32)dead_zone6
  845. };
  846. F32 time = gFrameIntervalSeconds;
  847. // Avoid making ridiculously big movements if there is a big drop in fps
  848. if (time > .2f)
  849. {
  850. time = .2f;
  851. }
  852. F32 cur_delta[7];
  853. static LLCachedControl<F32> feather(gSavedSettings, "FlycamFeathering");
  854. bool absolute = mCursor3D;
  855. bool is_zero = true;
  856. for (U32 i = 0; i < 7; ++i)
  857. {
  858. cur_delta[i] = -getJoystickAxis(axis[i]);
  859. F32 tmp = cur_delta[i];
  860. if (absolute)
  861. {
  862. cur_delta[i] = cur_delta[i] - sLastDelta[i];
  863. }
  864. sLastDelta[i] = tmp;
  865. if (cur_delta[i] > 0)
  866. {
  867. cur_delta[i] = llmax(cur_delta[i]-dead_zone[i], 0.f);
  868. }
  869. else
  870. {
  871. cur_delta[i] = llmin(cur_delta[i]+dead_zone[i], 0.f);
  872. }
  873. // We need smaller camera movements in build mode.
  874. // NOTE: this needs to remain after the deadzone calculation, otherwise
  875. // we have issues with flycam "jumping" when the build dialog is
  876. // opened/closed. -Nyx
  877. if (gToolMgr.inBuildMode())
  878. {
  879. if (i == X_I || i == Y_I || i == Z_I)
  880. {
  881. cur_delta[i] /= BUILDMODE_FLYCAM_T_SCALE;
  882. }
  883. }
  884. cur_delta[i] *= axis_scale[i];
  885. if (!absolute)
  886. {
  887. cur_delta[i] *= time;
  888. }
  889. sDelta[i] = sDelta[i] + (cur_delta[i] - sDelta[i]) * time * feather;
  890. is_zero = is_zero && (cur_delta[i] == 0.f);
  891. }
  892. // Clear AFK state if moved beyond the deadzone
  893. if (!is_zero && gAwayTimer.getElapsedTimeF32() > MIN_AFK_TIME)
  894. {
  895. gAgent.clearAFK();
  896. }
  897. sFlycamPosition += LLVector3(sDelta) * sFlycamRotation;
  898. LLMatrix3 rot_mat(sDelta[3], sDelta[4], sDelta[5]);
  899. sFlycamRotation = LLQuaternion(rot_mat) * sFlycamRotation;
  900. static LLCachedControl<bool> auto_leveling(gSavedSettings, "AutoLeveling");
  901. if (auto_leveling)
  902. {
  903. LLMatrix3 level(sFlycamRotation);
  904. LLVector3 x = LLVector3(level.mMatrix[0]);
  905. LLVector3 y = LLVector3(level.mMatrix[1]);
  906. LLVector3 z = LLVector3(level.mMatrix[2]);
  907. y.mV[2] = 0.f;
  908. y.normalize();
  909. level.setRows(x,y,z);
  910. level.orthogonalize();
  911. LLQuaternion quat(level);
  912. sFlycamRotation = nlerp(llmin(feather * time, 1.f), sFlycamRotation,
  913. quat);
  914. }
  915. static LLCachedControl<bool> zoom_direct(gSavedSettings, "ZoomDirect");
  916. if (zoom_direct)
  917. {
  918. sFlycamZoom = sLastDelta[6] * axis_scale[6] + dead_zone[6];
  919. }
  920. else
  921. {
  922. sFlycamZoom += sDelta[6];
  923. }
  924. LLMatrix3 mat(sFlycamRotation);
  925. gViewerCamera.setView(sFlycamZoom);
  926. gViewerCamera.setOrigin(sFlycamPosition);
  927. gViewerCamera.mXAxis = LLVector3(mat.mMatrix[0]);
  928. gViewerCamera.mYAxis = LLVector3(mat.mMatrix[1]);
  929. gViewerCamera.mZAxis = LLVector3(mat.mMatrix[2]);
  930. }
  931. bool LLViewerJoystick::toggleFlycam()
  932. {
  933. if (!mJoystickEnabled || !mJoystickFlycamEnabled)
  934. {
  935. mOverrideCamera = false;
  936. return false;
  937. }
  938. if (!mOverrideCamera)
  939. {
  940. gAgent.changeCameraToDefault();
  941. }
  942. if (gAwayTimer.getElapsedTimeF32() > MIN_AFK_TIME)
  943. {
  944. gAgent.clearAFK();
  945. }
  946. mOverrideCamera = !mOverrideCamera;
  947. if (mOverrideCamera)
  948. {
  949. moveFlycam(true);
  950. }
  951. else if (!gToolMgr.inBuildMode())
  952. {
  953. moveAvatar(true);
  954. }
  955. else
  956. {
  957. // We are in build mode, exiting from the flycam mode: since we are
  958. // going to keep the flycam POV for the main camera until the avatar
  959. // moves, we need to track this situation.
  960. setCameraNeedsUpdate(false);
  961. setNeedsReset(true);
  962. }
  963. return true;
  964. }
  965. void LLViewerJoystick::scanJoystick()
  966. {
  967. if (mDriverState != JDS_INITIALIZED || !mJoystickEnabled)
  968. {
  969. return;
  970. }
  971. #if LL_WINDOWS
  972. // On windows, the flycam is updated syncronously with a timer, so there is
  973. // no need to update the status of the joystick here.
  974. if (!mOverrideCamera)
  975. #endif
  976. {
  977. updateStatus();
  978. }
  979. static bool toggle_flycam = false;
  980. static LLCachedControl<S32> fly_cam_button(gSavedSettings,
  981. "JoystickButtonFlyCam");
  982. bool fly_cam = getJoystickButton(fly_cam_button);
  983. if (fly_cam)
  984. {
  985. if (fly_cam != toggle_flycam)
  986. {
  987. toggle_flycam = toggleFlycam();
  988. }
  989. }
  990. else
  991. {
  992. toggle_flycam = false;
  993. }
  994. if (!mOverrideCamera &&
  995. !(gToolMgr.inBuildMode() && mJoystickBuildEnabled))
  996. {
  997. moveAvatar();
  998. }
  999. }
  1000. std::string LLViewerJoystick::getDescription()
  1001. {
  1002. std::string res;
  1003. if (mDriverState == JDS_INITIALIZED && mNdofDev)
  1004. {
  1005. res = ll_safe_string(mNdofDev->product);
  1006. LLStringUtil::replaceNonstandardASCII(res, ' ');
  1007. LLStringUtil::replaceChar(res, '\n', ' ');
  1008. LLStringUtil::trim(res);
  1009. }
  1010. return res;
  1011. }
  1012. bool LLViewerJoystick::isLikeSpaceNavigator() const
  1013. {
  1014. return isJoystickInitialized() && strlen(mNdofDev->product) > 5 &&
  1015. strncmp(mNdofDev->product, "Space", 5) == 0;
  1016. }
  1017. void LLViewerJoystick::setToDefaults()
  1018. {
  1019. llinfos << "Restoring defaults." << llendl;
  1020. LLControlVariable* controlp = gSavedSettings.getControl("JoystickAxis0");
  1021. controlp->resetToDefault(true);
  1022. controlp = gSavedSettings.getControl("JoystickAxis1");
  1023. controlp->resetToDefault(true);
  1024. controlp = gSavedSettings.getControl("JoystickAxis2");
  1025. controlp->resetToDefault(true);
  1026. controlp = gSavedSettings.getControl("JoystickAxis3");
  1027. controlp->resetToDefault(true);
  1028. controlp = gSavedSettings.getControl("JoystickAxis4");
  1029. controlp->resetToDefault(true);
  1030. controlp = gSavedSettings.getControl("JoystickAxis5");
  1031. controlp->resetToDefault(true);
  1032. controlp = gSavedSettings.getControl("JoystickAxis6");
  1033. controlp->resetToDefault(true);
  1034. controlp = gSavedSettings.getControl("Cursor3D");
  1035. controlp->resetToDefault(true);
  1036. controlp = gSavedSettings.getControl("AutoLeveling");
  1037. controlp->resetToDefault(true);
  1038. controlp = gSavedSettings.getControl("ZoomDirect");
  1039. controlp->resetToDefault(true);
  1040. controlp = gSavedSettings.getControl("AvatarAxisScale0");
  1041. controlp->resetToDefault(true);
  1042. controlp = gSavedSettings.getControl("AvatarAxisScale1");
  1043. controlp->resetToDefault(true);
  1044. controlp = gSavedSettings.getControl("AvatarAxisScale2");
  1045. controlp->resetToDefault(true);
  1046. controlp = gSavedSettings.getControl("AvatarAxisScale3");
  1047. controlp->resetToDefault(true);
  1048. controlp = gSavedSettings.getControl("AvatarAxisScale4");
  1049. controlp->resetToDefault(true);
  1050. controlp = gSavedSettings.getControl("AvatarAxisScale5");
  1051. controlp->resetToDefault(true);
  1052. controlp = gSavedSettings.getControl("BuildAxisScale0");
  1053. controlp->resetToDefault(true);
  1054. controlp = gSavedSettings.getControl("BuildAxisScale1");
  1055. controlp->resetToDefault(true);
  1056. controlp = gSavedSettings.getControl("BuildAxisScale2");
  1057. controlp->resetToDefault(true);
  1058. controlp = gSavedSettings.getControl("BuildAxisScale3");
  1059. controlp->resetToDefault(true);
  1060. controlp = gSavedSettings.getControl("BuildAxisScale4");
  1061. controlp->resetToDefault(true);
  1062. controlp = gSavedSettings.getControl("BuildAxisScale5");
  1063. controlp->resetToDefault(true);
  1064. controlp = gSavedSettings.getControl("FlycamAxisScale0");
  1065. controlp->resetToDefault(true);
  1066. controlp = gSavedSettings.getControl("FlycamAxisScale1");
  1067. controlp->resetToDefault(true);
  1068. controlp = gSavedSettings.getControl("FlycamAxisScale2");
  1069. controlp->resetToDefault(true);
  1070. controlp = gSavedSettings.getControl("FlycamAxisScale3");
  1071. controlp->resetToDefault(true);
  1072. controlp = gSavedSettings.getControl("FlycamAxisScale4");
  1073. controlp->resetToDefault(true);
  1074. controlp = gSavedSettings.getControl("FlycamAxisScale5");
  1075. controlp->resetToDefault(true);
  1076. controlp = gSavedSettings.getControl("AvatarAxisDeadZone0");
  1077. controlp->resetToDefault(true);
  1078. controlp = gSavedSettings.getControl("AvatarAxisDeadZone1");
  1079. controlp->resetToDefault(true);
  1080. controlp = gSavedSettings.getControl("AvatarAxisDeadZone2");
  1081. controlp->resetToDefault(true);
  1082. controlp = gSavedSettings.getControl("AvatarAxisDeadZone3");
  1083. controlp->resetToDefault(true);
  1084. controlp = gSavedSettings.getControl("AvatarAxisDeadZone4");
  1085. controlp->resetToDefault(true);
  1086. controlp = gSavedSettings.getControl("AvatarAxisDeadZone5");
  1087. controlp->resetToDefault(true);
  1088. controlp = gSavedSettings.getControl("BuildAxisDeadZone0");
  1089. controlp->resetToDefault(true);
  1090. controlp = gSavedSettings.getControl("BuildAxisDeadZone1");
  1091. controlp->resetToDefault(true);
  1092. controlp = gSavedSettings.getControl("BuildAxisDeadZone2");
  1093. controlp->resetToDefault(true);
  1094. controlp = gSavedSettings.getControl("BuildAxisDeadZone3");
  1095. controlp->resetToDefault(true);
  1096. controlp = gSavedSettings.getControl("BuildAxisDeadZone4");
  1097. controlp->resetToDefault(true);
  1098. controlp = gSavedSettings.getControl("BuildAxisDeadZone5");
  1099. controlp->resetToDefault(true);
  1100. controlp = gSavedSettings.getControl("FlycamAxisDeadZone0");
  1101. controlp->resetToDefault(true);
  1102. controlp = gSavedSettings.getControl("FlycamAxisDeadZone1");
  1103. controlp->resetToDefault(true);
  1104. controlp = gSavedSettings.getControl("FlycamAxisDeadZone2");
  1105. controlp->resetToDefault(true);
  1106. controlp = gSavedSettings.getControl("FlycamAxisDeadZone3");
  1107. controlp->resetToDefault(true);
  1108. controlp = gSavedSettings.getControl("FlycamAxisDeadZone4");
  1109. controlp->resetToDefault(true);
  1110. controlp = gSavedSettings.getControl("FlycamAxisDeadZone5");
  1111. controlp->resetToDefault(true);
  1112. controlp = gSavedSettings.getControl("FlycamAxisDeadZone6");
  1113. controlp->resetToDefault(true);
  1114. controlp = gSavedSettings.getControl("AvatarFeathering");
  1115. controlp->resetToDefault(true);
  1116. controlp = gSavedSettings.getControl("BuildFeathering");
  1117. controlp->resetToDefault(true);
  1118. controlp = gSavedSettings.getControl("FlycamFeathering");
  1119. controlp->resetToDefault(true);
  1120. controlp = gSavedSettings.getControl("JoystickButtonFlyCam");
  1121. controlp->resetToDefault(true);
  1122. controlp = gSavedSettings.getControl("JoystickButtonJump");
  1123. controlp->resetToDefault(true);
  1124. }
  1125. void LLViewerJoystick::setSNDefaults()
  1126. {
  1127. #if LL_DARWIN || LL_LINUX
  1128. constexpr float platform_scale = 20.f;
  1129. constexpr float platform_scale_av_xz = 1.f;
  1130. // The SpaceNavigator does not act as a 3D cursor on OS X / Linux.
  1131. constexpr bool is_3d_cursor = false;
  1132. #else
  1133. constexpr float platform_scale = 1.f;
  1134. constexpr float platform_scale_av_xz = 2.f;
  1135. constexpr bool is_3d_cursor = true;
  1136. #endif
  1137. llinfos << "Setting to SpaceNavigator defaults." << llendl;
  1138. gSavedSettings.setS32("JoystickAxis0", 1); // z (at)
  1139. gSavedSettings.setS32("JoystickAxis1", 0); // x (slide)
  1140. gSavedSettings.setS32("JoystickAxis2", 2); // y (up)
  1141. gSavedSettings.setS32("JoystickAxis3", 4); // pitch
  1142. gSavedSettings.setS32("JoystickAxis4", 3); // roll
  1143. gSavedSettings.setS32("JoystickAxis5", 5); // yaw
  1144. gSavedSettings.setS32("JoystickAxis6", -1);
  1145. gSavedSettings.setBool("Cursor3D", is_3d_cursor);
  1146. gSavedSettings.setBool("AutoLeveling", true);
  1147. gSavedSettings.setBool("ZoomDirect", false);
  1148. gSavedSettings.setF32("AvatarAxisScale0", 1.f * platform_scale_av_xz);
  1149. gSavedSettings.setF32("AvatarAxisScale1", 1.f * platform_scale_av_xz);
  1150. gSavedSettings.setF32("AvatarAxisScale2", 1.f);
  1151. gSavedSettings.setF32("AvatarAxisScale4", 0.1f * platform_scale);
  1152. gSavedSettings.setF32("AvatarAxisScale5", 0.1f * platform_scale);
  1153. gSavedSettings.setF32("AvatarAxisScale3", 0.f * platform_scale);
  1154. gSavedSettings.setF32("BuildAxisScale1", 0.3f * platform_scale);
  1155. gSavedSettings.setF32("BuildAxisScale2", 0.3f * platform_scale);
  1156. gSavedSettings.setF32("BuildAxisScale0", 0.3f * platform_scale);
  1157. gSavedSettings.setF32("BuildAxisScale4", 0.3f * platform_scale);
  1158. gSavedSettings.setF32("BuildAxisScale5", 0.3f * platform_scale);
  1159. gSavedSettings.setF32("BuildAxisScale3", 0.3f * platform_scale);
  1160. gSavedSettings.setF32("FlycamAxisScale1", 2.f * platform_scale);
  1161. gSavedSettings.setF32("FlycamAxisScale2", 2.f * platform_scale);
  1162. gSavedSettings.setF32("FlycamAxisScale0", 2.1f * platform_scale);
  1163. gSavedSettings.setF32("FlycamAxisScale4", 0.1f * platform_scale);
  1164. gSavedSettings.setF32("FlycamAxisScale5", 0.15f * platform_scale);
  1165. gSavedSettings.setF32("FlycamAxisScale3", 0.f * platform_scale);
  1166. gSavedSettings.setF32("FlycamAxisScale6", 0.f * platform_scale);
  1167. gSavedSettings.setF32("AvatarAxisDeadZone0", 0.1f);
  1168. gSavedSettings.setF32("AvatarAxisDeadZone1", 0.1f);
  1169. gSavedSettings.setF32("AvatarAxisDeadZone2", 0.1f);
  1170. gSavedSettings.setF32("AvatarAxisDeadZone3", 1.f);
  1171. gSavedSettings.setF32("AvatarAxisDeadZone4", 0.02f);
  1172. gSavedSettings.setF32("AvatarAxisDeadZone5", 0.01f);
  1173. gSavedSettings.setF32("BuildAxisDeadZone0", 0.01f);
  1174. gSavedSettings.setF32("BuildAxisDeadZone1", 0.01f);
  1175. gSavedSettings.setF32("BuildAxisDeadZone2", 0.01f);
  1176. gSavedSettings.setF32("BuildAxisDeadZone3", 0.01f);
  1177. gSavedSettings.setF32("BuildAxisDeadZone4", 0.01f);
  1178. gSavedSettings.setF32("BuildAxisDeadZone5", 0.01f);
  1179. gSavedSettings.setF32("FlycamAxisDeadZone0", 0.01f);
  1180. gSavedSettings.setF32("FlycamAxisDeadZone1", 0.01f);
  1181. gSavedSettings.setF32("FlycamAxisDeadZone2", 0.01f);
  1182. gSavedSettings.setF32("FlycamAxisDeadZone3", 0.01f);
  1183. gSavedSettings.setF32("FlycamAxisDeadZone4", 0.01f);
  1184. gSavedSettings.setF32("FlycamAxisDeadZone5", 0.01f);
  1185. gSavedSettings.setF32("FlycamAxisDeadZone6", 1.f);
  1186. gSavedSettings.setF32("AvatarFeathering", 6.f);
  1187. gSavedSettings.setF32("BuildFeathering", 12.f);
  1188. gSavedSettings.setF32("FlycamFeathering", 5.f);
  1189. gSavedSettings.setS32("JoystickButtonFlyCam", 0);
  1190. gSavedSettings.setS32("JoystickButtonJump", 1);
  1191. }