PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llagent.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 2290 lines | 1520 code | 359 blank | 411 comment | 278 complexity | bfe4cf9f8dd32ace522c7ee9a89474c4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llagent.cpp
  3. * @brief LLAgent class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llagent.h"
  28. #include "pipeline.h"
  29. #include "llagentaccess.h"
  30. #include "llagentcamera.h"
  31. #include "llagentlistener.h"
  32. #include "llagentwearables.h"
  33. #include "llagentui.h"
  34. #include "llanimationstates.h"
  35. #include "llcallingcard.h"
  36. #include "llcapabilitylistener.h"
  37. #include "llchannelmanager.h"
  38. #include "llchicletbar.h"
  39. #include "llconsole.h"
  40. #include "llenvmanager.h"
  41. #include "llfirstuse.h"
  42. #include "llfloatercamera.h"
  43. #include "llfloaterreg.h"
  44. #include "llfloatertools.h"
  45. #include "llgroupactions.h"
  46. #include "llgroupmgr.h"
  47. #include "llhomelocationresponder.h"
  48. #include "llhudmanager.h"
  49. #include "lljoystickbutton.h"
  50. #include "llmorphview.h"
  51. #include "llmoveview.h"
  52. #include "llnavigationbar.h" // to show/hide navigation bar when changing mouse look state
  53. #include "llnearbychatbar.h"
  54. #include "llnotificationsutil.h"
  55. #include "llpaneltopinfobar.h"
  56. #include "llparcel.h"
  57. #include "llrendersphere.h"
  58. #include "llsdmessage.h"
  59. #include "llsdutil.h"
  60. #include "llsky.h"
  61. #include "llslurl.h"
  62. #include "llsmoothstep.h"
  63. #include "llstartup.h"
  64. #include "llstatusbar.h"
  65. #include "llteleportflags.h"
  66. #include "lltool.h"
  67. #include "lltoolbarview.h"
  68. #include "lltoolpie.h"
  69. #include "lltoolmgr.h"
  70. #include "lltrans.h"
  71. #include "lluictrl.h"
  72. #include "llurlentry.h"
  73. #include "llviewercontrol.h"
  74. #include "llviewerdisplay.h"
  75. #include "llviewerjoystick.h"
  76. #include "llviewermediafocus.h"
  77. #include "llviewermenu.h"
  78. #include "llviewerobjectlist.h"
  79. #include "llviewerparcelmgr.h"
  80. #include "llviewerstats.h"
  81. #include "llviewerwindow.h"
  82. #include "llvoavatarself.h"
  83. #include "llwindow.h"
  84. #include "llworld.h"
  85. #include "llworldmap.h"
  86. #include "stringize.h"
  87. using namespace LLVOAvatarDefines;
  88. extern LLMenuBarGL* gMenuBarView;
  89. const BOOL ANIMATE = TRUE;
  90. const U8 AGENT_STATE_TYPING = 0x04;
  91. const U8 AGENT_STATE_EDITING = 0x10;
  92. // Autopilot constants
  93. const F32 AUTOPILOT_HEIGHT_ADJUST_DISTANCE = 8.f; // meters
  94. const F32 AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND = 1.f; // meters
  95. const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS = 1.5f; // seconds
  96. const F32 MAX_VELOCITY_AUTO_LAND_SQUARED = 4.f * 4.f;
  97. const F64 CHAT_AGE_FAST_RATE = 3.0;
  98. // fidget constants
  99. const F32 MIN_FIDGET_TIME = 8.f; // seconds
  100. const F32 MAX_FIDGET_TIME = 20.f; // seconds
  101. // The agent instance.
  102. LLAgent gAgent;
  103. //--------------------------------------------------------------------
  104. // Statics
  105. //
  106. /// minimum time after setting away state before coming back based on movement
  107. const F32 LLAgent::MIN_AFK_TIME = 10.0f;
  108. const F32 LLAgent::TYPING_TIMEOUT_SECS = 5.f;
  109. std::map<std::string, std::string> LLAgent::sTeleportErrorMessages;
  110. std::map<std::string, std::string> LLAgent::sTeleportProgressMessages;
  111. class LLAgentFriendObserver : public LLFriendObserver
  112. {
  113. public:
  114. LLAgentFriendObserver() {}
  115. virtual ~LLAgentFriendObserver() {}
  116. virtual void changed(U32 mask);
  117. };
  118. void LLAgentFriendObserver::changed(U32 mask)
  119. {
  120. // if there's a change we're interested in.
  121. if((mask & (LLFriendObserver::POWERS)) != 0)
  122. {
  123. gAgent.friendsChanged();
  124. }
  125. }
  126. bool handleSlowMotionAnimation(const LLSD& newvalue)
  127. {
  128. if (newvalue.asBoolean())
  129. {
  130. gAgentAvatarp->setAnimTimeFactor(0.2f);
  131. }
  132. else
  133. {
  134. gAgentAvatarp->setAnimTimeFactor(1.0f);
  135. }
  136. return true;
  137. }
  138. // static
  139. void LLAgent::parcelChangedCallback()
  140. {
  141. bool can_edit = LLToolMgr::getInstance()->canEdit();
  142. gAgent.mCanEditParcel = can_edit;
  143. }
  144. // static
  145. bool LLAgent::isActionAllowed(const LLSD& sdname)
  146. {
  147. bool retval = false;
  148. const std::string& param = sdname.asString();
  149. if (param == "build")
  150. {
  151. retval = gAgent.canEditParcel();
  152. }
  153. else if (param == "speak")
  154. {
  155. if ( gAgent.isVoiceConnected() &&
  156. LLViewerParcelMgr::getInstance()->allowAgentVoice() &&
  157. ! LLVoiceClient::getInstance()->inTuningMode() )
  158. {
  159. retval = true;
  160. }
  161. else
  162. {
  163. retval = false;
  164. }
  165. }
  166. return retval;
  167. }
  168. // static
  169. void LLAgent::pressMicrophone(const LLSD& name)
  170. {
  171. LLFirstUse::speak(false);
  172. LLVoiceClient::getInstance()->inputUserControlState(true);
  173. }
  174. // static
  175. void LLAgent::releaseMicrophone(const LLSD& name)
  176. {
  177. LLVoiceClient::getInstance()->inputUserControlState(false);
  178. }
  179. // static
  180. void LLAgent::toggleMicrophone(const LLSD& name)
  181. {
  182. LLVoiceClient::getInstance()->toggleUserPTTState();
  183. }
  184. // static
  185. bool LLAgent::isMicrophoneOn(const LLSD& sdname)
  186. {
  187. return LLVoiceClient::getInstance()->getUserPTTState();
  188. }
  189. // ************************************************************
  190. // Enabled this definition to compile a 'hacked' viewer that
  191. // locally believes the end user has godlike powers.
  192. // #define HACKED_GODLIKE_VIEWER
  193. // For a toggled version, see viewer.h for the
  194. // TOGGLE_HACKED_GODLIKE_VIEWER define, instead.
  195. // ************************************************************
  196. // Constructors and Destructors
  197. // JC - Please try to make this order match the order in the header
  198. // file. Otherwise it's hard to find variables that aren't initialized.
  199. //-----------------------------------------------------------------------------
  200. // LLAgent()
  201. //-----------------------------------------------------------------------------
  202. LLAgent::LLAgent() :
  203. mGroupPowers(0),
  204. mHideGroupTitle(FALSE),
  205. mGroupID(),
  206. mInitialized(FALSE),
  207. mListener(),
  208. mDoubleTapRunTimer(),
  209. mDoubleTapRunMode(DOUBLETAP_NONE),
  210. mbAlwaysRun(false),
  211. mbRunning(false),
  212. mbTeleportKeepsLookAt(false),
  213. mAgentAccess(new LLAgentAccess(gSavedSettings)),
  214. mCanEditParcel(false),
  215. mTeleportSourceSLURL(new LLSLURL),
  216. mTeleportState( TELEPORT_NONE ),
  217. mRegionp(NULL),
  218. mAgentOriginGlobal(),
  219. mPositionGlobal(),
  220. mDistanceTraveled(0.F),
  221. mLastPositionGlobal(LLVector3d::zero),
  222. mRenderState(0),
  223. mTypingTimer(),
  224. mViewsPushed(FALSE),
  225. mCustomAnim(FALSE),
  226. mShowAvatar(TRUE),
  227. mFrameAgent(),
  228. mIsBusy(FALSE),
  229. mControlFlags(0x00000000),
  230. mbFlagsDirty(FALSE),
  231. mbFlagsNeedReset(FALSE),
  232. mAutoPilot(FALSE),
  233. mAutoPilotFlyOnStop(FALSE),
  234. mAutoPilotAllowFlying(TRUE),
  235. mAutoPilotTargetGlobal(),
  236. mAutoPilotStopDistance(1.f),
  237. mAutoPilotUseRotation(FALSE),
  238. mAutoPilotTargetFacing(LLVector3::zero),
  239. mAutoPilotTargetDist(0.f),
  240. mAutoPilotNoProgressFrameCount(0),
  241. mAutoPilotRotationThreshold(0.f),
  242. mAutoPilotFinishedCallback(NULL),
  243. mAutoPilotCallbackData(NULL),
  244. mEffectColor(new LLUIColor(LLColor4(0.f, 1.f, 1.f, 1.f))),
  245. mHaveHomePosition(FALSE),
  246. mHomeRegionHandle( 0 ),
  247. mNearChatRadius(CHAT_NORMAL_RADIUS / 2.f),
  248. mNextFidgetTime(0.f),
  249. mCurrentFidget(0),
  250. mFirstLogin(FALSE),
  251. mGenderChosen(FALSE),
  252. mVoiceConnected(false),
  253. mAppearanceSerialNum(0),
  254. mMouselookModeInSignal(NULL),
  255. mMouselookModeOutSignal(NULL)
  256. {
  257. for (U32 i = 0; i < TOTAL_CONTROLS; i++)
  258. {
  259. mControlsTakenCount[i] = 0;
  260. mControlsTakenPassedOnCount[i] = 0;
  261. }
  262. mListener.reset(new LLAgentListener(*this));
  263. mMoveTimer.stop();
  264. }
  265. // Requires gSavedSettings to be initialized.
  266. //-----------------------------------------------------------------------------
  267. // init()
  268. //-----------------------------------------------------------------------------
  269. void LLAgent::init()
  270. {
  271. mMoveTimer.start();
  272. gSavedSettings.declareBOOL("SlowMotionAnimation", FALSE, "Declared in code", FALSE);
  273. gSavedSettings.getControl("SlowMotionAnimation")->getSignal()->connect(boost::bind(&handleSlowMotionAnimation, _2));
  274. // *Note: this is where LLViewerCamera::getInstance() used to be constructed.
  275. setFlying( gSavedSettings.getBOOL("FlyingAtExit") );
  276. *mEffectColor = LLUIColorTable::instance().getColor("EffectColor");
  277. gSavedSettings.getControl("PreferredMaturity")->getValidateSignal()->connect(boost::bind(&LLAgent::validateMaturity, this, _2));
  278. gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLAgent::handleMaturity, this, _2));
  279. LLViewerParcelMgr::getInstance()->addAgentParcelChangedCallback(boost::bind(&LLAgent::parcelChangedCallback));
  280. mInitialized = TRUE;
  281. }
  282. //-----------------------------------------------------------------------------
  283. // cleanup()
  284. //-----------------------------------------------------------------------------
  285. void LLAgent::cleanup()
  286. {
  287. mRegionp = NULL;
  288. }
  289. //-----------------------------------------------------------------------------
  290. // LLAgent()
  291. //-----------------------------------------------------------------------------
  292. LLAgent::~LLAgent()
  293. {
  294. cleanup();
  295. delete mMouselookModeInSignal;
  296. mMouselookModeInSignal = NULL;
  297. delete mMouselookModeOutSignal;
  298. mMouselookModeOutSignal = NULL;
  299. delete mAgentAccess;
  300. mAgentAccess = NULL;
  301. delete mEffectColor;
  302. mEffectColor = NULL;
  303. delete mTeleportSourceSLURL;
  304. mTeleportSourceSLURL = NULL;
  305. }
  306. // Handle any actions that need to be performed when the main app gains focus
  307. // (such as through alt-tab).
  308. //-----------------------------------------------------------------------------
  309. // onAppFocusGained()
  310. //-----------------------------------------------------------------------------
  311. void LLAgent::onAppFocusGained()
  312. {
  313. if (CAMERA_MODE_MOUSELOOK == gAgentCamera.getCameraMode())
  314. {
  315. gAgentCamera.changeCameraToDefault();
  316. LLToolMgr::getInstance()->clearSavedTool();
  317. }
  318. }
  319. void LLAgent::ageChat()
  320. {
  321. if (isAgentAvatarValid())
  322. {
  323. // get amount of time since I last chatted
  324. F64 elapsed_time = (F64)gAgentAvatarp->mChatTimer.getElapsedTimeF32();
  325. // add in frame time * 3 (so it ages 4x)
  326. gAgentAvatarp->mChatTimer.setAge(elapsed_time + (F64)gFrameDTClamped * (CHAT_AGE_FAST_RATE - 1.0));
  327. }
  328. }
  329. //-----------------------------------------------------------------------------
  330. // moveAt()
  331. //-----------------------------------------------------------------------------
  332. void LLAgent::moveAt(S32 direction, bool reset)
  333. {
  334. mMoveTimer.reset();
  335. LLFirstUse::notMoving(false);
  336. // age chat timer so it fades more quickly when you are intentionally moving
  337. ageChat();
  338. gAgentCamera.setAtKey(LLAgentCamera::directionToKey(direction));
  339. if (direction > 0)
  340. {
  341. setControlFlags(AGENT_CONTROL_AT_POS | AGENT_CONTROL_FAST_AT);
  342. }
  343. else if (direction < 0)
  344. {
  345. setControlFlags(AGENT_CONTROL_AT_NEG | AGENT_CONTROL_FAST_AT);
  346. }
  347. if (reset)
  348. {
  349. gAgentCamera.resetView();
  350. }
  351. }
  352. //-----------------------------------------------------------------------------
  353. // moveAtNudge()
  354. //-----------------------------------------------------------------------------
  355. void LLAgent::moveAtNudge(S32 direction)
  356. {
  357. mMoveTimer.reset();
  358. LLFirstUse::notMoving(false);
  359. // age chat timer so it fades more quickly when you are intentionally moving
  360. ageChat();
  361. gAgentCamera.setWalkKey(LLAgentCamera::directionToKey(direction));
  362. if (direction > 0)
  363. {
  364. setControlFlags(AGENT_CONTROL_NUDGE_AT_POS);
  365. }
  366. else if (direction < 0)
  367. {
  368. setControlFlags(AGENT_CONTROL_NUDGE_AT_NEG);
  369. }
  370. gAgentCamera.resetView();
  371. }
  372. //-----------------------------------------------------------------------------
  373. // moveLeft()
  374. //-----------------------------------------------------------------------------
  375. void LLAgent::moveLeft(S32 direction)
  376. {
  377. mMoveTimer.reset();
  378. LLFirstUse::notMoving(false);
  379. // age chat timer so it fades more quickly when you are intentionally moving
  380. ageChat();
  381. gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
  382. if (direction > 0)
  383. {
  384. setControlFlags(AGENT_CONTROL_LEFT_POS | AGENT_CONTROL_FAST_LEFT);
  385. }
  386. else if (direction < 0)
  387. {
  388. setControlFlags(AGENT_CONTROL_LEFT_NEG | AGENT_CONTROL_FAST_LEFT);
  389. }
  390. gAgentCamera.resetView();
  391. }
  392. //-----------------------------------------------------------------------------
  393. // moveLeftNudge()
  394. //-----------------------------------------------------------------------------
  395. void LLAgent::moveLeftNudge(S32 direction)
  396. {
  397. mMoveTimer.reset();
  398. LLFirstUse::notMoving(false);
  399. // age chat timer so it fades more quickly when you are intentionally moving
  400. ageChat();
  401. gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
  402. if (direction > 0)
  403. {
  404. setControlFlags(AGENT_CONTROL_NUDGE_LEFT_POS);
  405. }
  406. else if (direction < 0)
  407. {
  408. setControlFlags(AGENT_CONTROL_NUDGE_LEFT_NEG);
  409. }
  410. gAgentCamera.resetView();
  411. }
  412. //-----------------------------------------------------------------------------
  413. // moveUp()
  414. //-----------------------------------------------------------------------------
  415. void LLAgent::moveUp(S32 direction)
  416. {
  417. mMoveTimer.reset();
  418. LLFirstUse::notMoving(false);
  419. // age chat timer so it fades more quickly when you are intentionally moving
  420. ageChat();
  421. gAgentCamera.setUpKey(LLAgentCamera::directionToKey(direction));
  422. if (direction > 0)
  423. {
  424. setControlFlags(AGENT_CONTROL_UP_POS | AGENT_CONTROL_FAST_UP);
  425. }
  426. else if (direction < 0)
  427. {
  428. setControlFlags(AGENT_CONTROL_UP_NEG | AGENT_CONTROL_FAST_UP);
  429. }
  430. gAgentCamera.resetView();
  431. }
  432. //-----------------------------------------------------------------------------
  433. // moveYaw()
  434. //-----------------------------------------------------------------------------
  435. void LLAgent::moveYaw(F32 mag, bool reset_view)
  436. {
  437. gAgentCamera.setYawKey(mag);
  438. if (mag > 0)
  439. {
  440. setControlFlags(AGENT_CONTROL_YAW_POS);
  441. }
  442. else if (mag < 0)
  443. {
  444. setControlFlags(AGENT_CONTROL_YAW_NEG);
  445. }
  446. if (reset_view)
  447. {
  448. gAgentCamera.resetView();
  449. }
  450. }
  451. //-----------------------------------------------------------------------------
  452. // movePitch()
  453. //-----------------------------------------------------------------------------
  454. void LLAgent::movePitch(F32 mag)
  455. {
  456. gAgentCamera.setPitchKey(mag);
  457. if (mag > 0)
  458. {
  459. setControlFlags(AGENT_CONTROL_PITCH_POS);
  460. }
  461. else if (mag < 0)
  462. {
  463. setControlFlags(AGENT_CONTROL_PITCH_NEG);
  464. }
  465. }
  466. // Does this parcel allow you to fly?
  467. BOOL LLAgent::canFly()
  468. {
  469. if (isGodlike()) return TRUE;
  470. LLViewerRegion* regionp = getRegion();
  471. if (regionp && regionp->getBlockFly()) return FALSE;
  472. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  473. if (!parcel) return FALSE;
  474. // Allow owners to fly on their own land.
  475. if (LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_ALLOW_FLY))
  476. {
  477. return TRUE;
  478. }
  479. return parcel->getAllowFly();
  480. }
  481. BOOL LLAgent::getFlying() const
  482. {
  483. return mControlFlags & AGENT_CONTROL_FLY;
  484. }
  485. //-----------------------------------------------------------------------------
  486. // setFlying()
  487. //-----------------------------------------------------------------------------
  488. void LLAgent::setFlying(BOOL fly)
  489. {
  490. if (isAgentAvatarValid())
  491. {
  492. // *HACK: Don't allow to start the flying mode if we got ANIM_AGENT_STANDUP signal
  493. // because in this case we won't get a signal to start avatar flying animation and
  494. // it will be walking with flying mode "ON" indication. However we allow to switch
  495. // the flying mode off if we get ANIM_AGENT_STANDUP signal. See process_avatar_animation().
  496. // See EXT-2781.
  497. if(fly && gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_STANDUP) != gAgentAvatarp->mSignaledAnimations.end())
  498. {
  499. return;
  500. }
  501. // don't allow taking off while sitting
  502. if (fly && gAgentAvatarp->isSitting())
  503. {
  504. return;
  505. }
  506. }
  507. if (fly)
  508. {
  509. BOOL was_flying = getFlying();
  510. if (!canFly() && !was_flying)
  511. {
  512. // parcel doesn't let you start fly
  513. // gods can always fly
  514. // and it's OK if you're already flying
  515. make_ui_sound("UISndBadKeystroke");
  516. return;
  517. }
  518. if( !was_flying )
  519. {
  520. LLViewerStats::getInstance()->incStat(LLViewerStats::ST_FLY_COUNT);
  521. }
  522. setControlFlags(AGENT_CONTROL_FLY);
  523. }
  524. else
  525. {
  526. clearControlFlags(AGENT_CONTROL_FLY);
  527. }
  528. // Update Movement Controls according to Fly mode
  529. LLFloaterMove::setFlyingMode(fly);
  530. mbFlagsDirty = TRUE;
  531. }
  532. // UI based mechanism of setting fly state
  533. //-----------------------------------------------------------------------------
  534. // toggleFlying()
  535. //-----------------------------------------------------------------------------
  536. // static
  537. void LLAgent::toggleFlying()
  538. {
  539. if ( gAgent.mAutoPilot )
  540. {
  541. LLToolPie::instance().stopClickToWalk();
  542. }
  543. BOOL fly = !gAgent.getFlying();
  544. gAgent.mMoveTimer.reset();
  545. LLFirstUse::notMoving(false);
  546. gAgent.setFlying( fly );
  547. gAgentCamera.resetView();
  548. }
  549. // static
  550. bool LLAgent::enableFlying()
  551. {
  552. BOOL sitting = FALSE;
  553. if (isAgentAvatarValid())
  554. {
  555. sitting = gAgentAvatarp->isSitting();
  556. }
  557. return !sitting;
  558. }
  559. void LLAgent::standUp()
  560. {
  561. setControlFlags(AGENT_CONTROL_STAND_UP);
  562. }
  563. //-----------------------------------------------------------------------------
  564. // setRegion()
  565. //-----------------------------------------------------------------------------
  566. void LLAgent::setRegion(LLViewerRegion *regionp)
  567. {
  568. bool teleport = true;
  569. llassert(regionp);
  570. if (mRegionp != regionp)
  571. {
  572. // std::string host_name;
  573. // host_name = regionp->getHost().getHostName();
  574. std::string ip = regionp->getHost().getString();
  575. llinfos << "Moving agent into region: " << regionp->getName()
  576. << " located at " << ip << llendl;
  577. if (mRegionp)
  578. {
  579. // We've changed regions, we're now going to change our agent coordinate frame.
  580. mAgentOriginGlobal = regionp->getOriginGlobal();
  581. LLVector3d agent_offset_global = mRegionp->getOriginGlobal();
  582. LLVector3 delta;
  583. delta.setVec(regionp->getOriginGlobal() - mRegionp->getOriginGlobal());
  584. setPositionAgent(getPositionAgent() - delta);
  585. LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin();
  586. LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta);
  587. // Update all of the regions.
  588. LLWorld::getInstance()->updateAgentOffset(agent_offset_global);
  589. // Hack to keep sky in the agent's region, otherwise it may get deleted - DJS 08/02/02
  590. // *TODO: possibly refactor into gSky->setAgentRegion(regionp)? -Brad
  591. if (gSky.mVOSkyp)
  592. {
  593. gSky.mVOSkyp->setRegion(regionp);
  594. }
  595. if (gSky.mVOGroundp)
  596. {
  597. gSky.mVOGroundp->setRegion(regionp);
  598. }
  599. // Notify windlight managers
  600. teleport = (gAgent.getTeleportState() != LLAgent::TELEPORT_NONE);
  601. }
  602. else
  603. {
  604. // First time initialization.
  605. // We've changed regions, we're now going to change our agent coordinate frame.
  606. mAgentOriginGlobal = regionp->getOriginGlobal();
  607. LLVector3 delta;
  608. delta.setVec(regionp->getOriginGlobal());
  609. setPositionAgent(getPositionAgent() - delta);
  610. LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin();
  611. LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta);
  612. // Update all of the regions.
  613. LLWorld::getInstance()->updateAgentOffset(mAgentOriginGlobal);
  614. }
  615. // Pass new region along to metrics components that care about this level of detail.
  616. LLAppViewer::metricsUpdateRegion(regionp->getHandle());
  617. }
  618. mRegionp = regionp;
  619. // Pass the region host to LLUrlEntryParcel to resolve parcel name
  620. // with a server request.
  621. LLUrlEntryParcel::setRegionHost(getRegionHost());
  622. // Must shift hole-covering water object locations because local
  623. // coordinate frame changed.
  624. LLWorld::getInstance()->updateWaterObjects();
  625. // keep a list of regions we've been too
  626. // this is just an interesting stat, logged at the dataserver
  627. // we could trake this at the dataserver side, but that's harder
  628. U64 handle = regionp->getHandle();
  629. mRegionsVisited.insert(handle);
  630. LLSelectMgr::getInstance()->updateSelectionCenter();
  631. LLFloaterMove::sUpdateFlyingStatus();
  632. if (teleport)
  633. {
  634. LLEnvManagerNew::instance().onTeleport();
  635. }
  636. else
  637. {
  638. LLEnvManagerNew::instance().onRegionCrossing();
  639. }
  640. }
  641. //-----------------------------------------------------------------------------
  642. // getRegion()
  643. //-----------------------------------------------------------------------------
  644. LLViewerRegion *LLAgent::getRegion() const
  645. {
  646. return mRegionp;
  647. }
  648. LLHost LLAgent::getRegionHost() const
  649. {
  650. if (mRegionp)
  651. {
  652. return mRegionp->getHost();
  653. }
  654. else
  655. {
  656. return LLHost::invalid;
  657. }
  658. }
  659. //-----------------------------------------------------------------------------
  660. // inPrelude()
  661. //-----------------------------------------------------------------------------
  662. BOOL LLAgent::inPrelude()
  663. {
  664. return mRegionp && mRegionp->isPrelude();
  665. }
  666. //-----------------------------------------------------------------------------
  667. // canManageEstate()
  668. //-----------------------------------------------------------------------------
  669. BOOL LLAgent::canManageEstate() const
  670. {
  671. return mRegionp && mRegionp->canManageEstate();
  672. }
  673. //-----------------------------------------------------------------------------
  674. // sendMessage()
  675. //-----------------------------------------------------------------------------
  676. void LLAgent::sendMessage()
  677. {
  678. if (gDisconnected)
  679. {
  680. llwarns << "Trying to send message when disconnected!" << llendl;
  681. return;
  682. }
  683. if (!mRegionp)
  684. {
  685. llerrs << "No region for agent yet!" << llendl;
  686. return;
  687. }
  688. gMessageSystem->sendMessage(mRegionp->getHost());
  689. }
  690. //-----------------------------------------------------------------------------
  691. // sendReliableMessage()
  692. //-----------------------------------------------------------------------------
  693. void LLAgent::sendReliableMessage()
  694. {
  695. if (gDisconnected)
  696. {
  697. lldebugs << "Trying to send message when disconnected!" << llendl;
  698. return;
  699. }
  700. if (!mRegionp)
  701. {
  702. lldebugs << "LLAgent::sendReliableMessage No region for agent yet, not sending message!" << llendl;
  703. return;
  704. }
  705. gMessageSystem->sendReliable(mRegionp->getHost());
  706. }
  707. //-----------------------------------------------------------------------------
  708. // getVelocity()
  709. //-----------------------------------------------------------------------------
  710. LLVector3 LLAgent::getVelocity() const
  711. {
  712. if (isAgentAvatarValid())
  713. {
  714. return gAgentAvatarp->getVelocity();
  715. }
  716. else
  717. {
  718. return LLVector3::zero;
  719. }
  720. }
  721. //-----------------------------------------------------------------------------
  722. // setPositionAgent()
  723. //-----------------------------------------------------------------------------
  724. void LLAgent::setPositionAgent(const LLVector3 &pos_agent)
  725. {
  726. if (!pos_agent.isFinite())
  727. {
  728. llerrs << "setPositionAgent is not a number" << llendl;
  729. }
  730. if (isAgentAvatarValid() && gAgentAvatarp->getParent())
  731. {
  732. LLVector3 pos_agent_sitting;
  733. LLVector3d pos_agent_d;
  734. LLViewerObject *parent = (LLViewerObject*)gAgentAvatarp->getParent();
  735. pos_agent_sitting = gAgentAvatarp->getPosition() * parent->getRotation() + parent->getPositionAgent();
  736. pos_agent_d.setVec(pos_agent_sitting);
  737. mFrameAgent.setOrigin(pos_agent_sitting);
  738. mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
  739. }
  740. else
  741. {
  742. mFrameAgent.setOrigin(pos_agent);
  743. LLVector3d pos_agent_d;
  744. pos_agent_d.setVec(pos_agent);
  745. mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
  746. }
  747. }
  748. //-----------------------------------------------------------------------------
  749. // getPositionGlobal()
  750. //-----------------------------------------------------------------------------
  751. const LLVector3d &LLAgent::getPositionGlobal() const
  752. {
  753. if (isAgentAvatarValid() && !gAgentAvatarp->mDrawable.isNull())
  754. {
  755. mPositionGlobal = getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition());
  756. }
  757. else
  758. {
  759. mPositionGlobal = getPosGlobalFromAgent(mFrameAgent.getOrigin());
  760. }
  761. return mPositionGlobal;
  762. }
  763. //-----------------------------------------------------------------------------
  764. // getPositionAgent()
  765. //-----------------------------------------------------------------------------
  766. const LLVector3 &LLAgent::getPositionAgent()
  767. {
  768. if (isAgentAvatarValid() && !gAgentAvatarp->mDrawable.isNull())
  769. {
  770. mFrameAgent.setOrigin(gAgentAvatarp->getRenderPosition());
  771. }
  772. return mFrameAgent.getOrigin();
  773. }
  774. //-----------------------------------------------------------------------------
  775. // getRegionsVisited()
  776. //-----------------------------------------------------------------------------
  777. S32 LLAgent::getRegionsVisited() const
  778. {
  779. return mRegionsVisited.size();
  780. }
  781. //-----------------------------------------------------------------------------
  782. // getDistanceTraveled()
  783. //-----------------------------------------------------------------------------
  784. F64 LLAgent::getDistanceTraveled() const
  785. {
  786. return mDistanceTraveled;
  787. }
  788. //-----------------------------------------------------------------------------
  789. // getPosAgentFromGlobal()
  790. //-----------------------------------------------------------------------------
  791. LLVector3 LLAgent::getPosAgentFromGlobal(const LLVector3d &pos_global) const
  792. {
  793. LLVector3 pos_agent;
  794. pos_agent.setVec(pos_global - mAgentOriginGlobal);
  795. return pos_agent;
  796. }
  797. //-----------------------------------------------------------------------------
  798. // getPosGlobalFromAgent()
  799. //-----------------------------------------------------------------------------
  800. LLVector3d LLAgent::getPosGlobalFromAgent(const LLVector3 &pos_agent) const
  801. {
  802. LLVector3d pos_agent_d;
  803. pos_agent_d.setVec(pos_agent);
  804. return pos_agent_d + mAgentOriginGlobal;
  805. }
  806. void LLAgent::sitDown()
  807. {
  808. setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
  809. }
  810. //-----------------------------------------------------------------------------
  811. // resetAxes()
  812. //-----------------------------------------------------------------------------
  813. void LLAgent::resetAxes()
  814. {
  815. mFrameAgent.resetAxes();
  816. }
  817. // Copied from LLCamera::setOriginAndLookAt
  818. // Look_at must be unit vector
  819. //-----------------------------------------------------------------------------
  820. // resetAxes()
  821. //-----------------------------------------------------------------------------
  822. void LLAgent::resetAxes(const LLVector3 &look_at)
  823. {
  824. LLVector3 skyward = getReferenceUpVector();
  825. // if look_at has zero length, fail
  826. // if look_at and skyward are parallel, fail
  827. //
  828. // Test both of these conditions with a cross product.
  829. LLVector3 cross(look_at % skyward);
  830. if (cross.isNull())
  831. {
  832. llinfos << "LLAgent::resetAxes cross-product is zero" << llendl;
  833. return;
  834. }
  835. // Make sure look_at and skyward are not parallel
  836. // and neither are zero length
  837. LLVector3 left(skyward % look_at);
  838. LLVector3 up(look_at % left);
  839. mFrameAgent.setAxes(look_at, left, up);
  840. }
  841. //-----------------------------------------------------------------------------
  842. // rotate()
  843. //-----------------------------------------------------------------------------
  844. void LLAgent::rotate(F32 angle, const LLVector3 &axis)
  845. {
  846. mFrameAgent.rotate(angle, axis);
  847. }
  848. //-----------------------------------------------------------------------------
  849. // rotate()
  850. //-----------------------------------------------------------------------------
  851. void LLAgent::rotate(F32 angle, F32 x, F32 y, F32 z)
  852. {
  853. mFrameAgent.rotate(angle, x, y, z);
  854. }
  855. //-----------------------------------------------------------------------------
  856. // rotate()
  857. //-----------------------------------------------------------------------------
  858. void LLAgent::rotate(const LLMatrix3 &matrix)
  859. {
  860. mFrameAgent.rotate(matrix);
  861. }
  862. //-----------------------------------------------------------------------------
  863. // rotate()
  864. //-----------------------------------------------------------------------------
  865. void LLAgent::rotate(const LLQuaternion &quaternion)
  866. {
  867. mFrameAgent.rotate(quaternion);
  868. }
  869. //-----------------------------------------------------------------------------
  870. // getReferenceUpVector()
  871. //-----------------------------------------------------------------------------
  872. LLVector3 LLAgent::getReferenceUpVector()
  873. {
  874. // this vector is in the coordinate frame of the avatar's parent object, or the world if none
  875. LLVector3 up_vector = LLVector3::z_axis;
  876. if (isAgentAvatarValid() &&
  877. gAgentAvatarp->getParent() &&
  878. gAgentAvatarp->mDrawable.notNull())
  879. {
  880. U32 camera_mode = gAgentCamera.getCameraAnimating() ? gAgentCamera.getLastCameraMode() : gAgentCamera.getCameraMode();
  881. // and in third person...
  882. if (camera_mode == CAMERA_MODE_THIRD_PERSON)
  883. {
  884. // make the up vector point to the absolute +z axis
  885. up_vector = up_vector * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
  886. }
  887. else if (camera_mode == CAMERA_MODE_MOUSELOOK)
  888. {
  889. // make the up vector point to the avatar's +z axis
  890. up_vector = up_vector * gAgentAvatarp->mDrawable->getRotation();
  891. }
  892. }
  893. return up_vector;
  894. }
  895. // Radians, positive is forward into ground
  896. //-----------------------------------------------------------------------------
  897. // pitch()
  898. //-----------------------------------------------------------------------------
  899. void LLAgent::pitch(F32 angle)
  900. {
  901. // don't let user pitch if pointed almost all the way down or up
  902. mFrameAgent.pitch(clampPitchToLimits(angle));
  903. }
  904. // Radians, positive is forward into ground
  905. //-----------------------------------------------------------------------------
  906. // clampPitchToLimits()
  907. //-----------------------------------------------------------------------------
  908. F32 LLAgent::clampPitchToLimits(F32 angle)
  909. {
  910. // A dot B = mag(A) * mag(B) * cos(angle between A and B)
  911. // so... cos(angle between A and B) = A dot B / mag(A) / mag(B)
  912. // = A dot B for unit vectors
  913. LLVector3 skyward = getReferenceUpVector();
  914. const F32 look_down_limit = 179.f * DEG_TO_RAD;;
  915. const F32 look_up_limit = 1.f * DEG_TO_RAD;
  916. F32 angle_from_skyward = acos( mFrameAgent.getAtAxis() * skyward );
  917. // clamp pitch to limits
  918. if ((angle >= 0.f) && (angle_from_skyward + angle > look_down_limit))
  919. {
  920. angle = look_down_limit - angle_from_skyward;
  921. }
  922. else if ((angle < 0.f) && (angle_from_skyward + angle < look_up_limit))
  923. {
  924. angle = look_up_limit - angle_from_skyward;
  925. }
  926. return angle;
  927. }
  928. //-----------------------------------------------------------------------------
  929. // roll()
  930. //-----------------------------------------------------------------------------
  931. void LLAgent::roll(F32 angle)
  932. {
  933. mFrameAgent.roll(angle);
  934. }
  935. //-----------------------------------------------------------------------------
  936. // yaw()
  937. //-----------------------------------------------------------------------------
  938. void LLAgent::yaw(F32 angle)
  939. {
  940. if (!rotateGrabbed())
  941. {
  942. mFrameAgent.rotate(angle, getReferenceUpVector());
  943. }
  944. }
  945. // Returns a quat that represents the rotation of the agent in the absolute frame
  946. //-----------------------------------------------------------------------------
  947. // getQuat()
  948. //-----------------------------------------------------------------------------
  949. LLQuaternion LLAgent::getQuat() const
  950. {
  951. return mFrameAgent.getQuaternion();
  952. }
  953. //-----------------------------------------------------------------------------
  954. // getControlFlags()
  955. //-----------------------------------------------------------------------------
  956. U32 LLAgent::getControlFlags()
  957. {
  958. return mControlFlags;
  959. }
  960. //-----------------------------------------------------------------------------
  961. // setControlFlags()
  962. //-----------------------------------------------------------------------------
  963. void LLAgent::setControlFlags(U32 mask)
  964. {
  965. mControlFlags |= mask;
  966. mbFlagsDirty = TRUE;
  967. }
  968. //-----------------------------------------------------------------------------
  969. // clearControlFlags()
  970. //-----------------------------------------------------------------------------
  971. void LLAgent::clearControlFlags(U32 mask)
  972. {
  973. U32 old_flags = mControlFlags;
  974. mControlFlags &= ~mask;
  975. if (old_flags != mControlFlags)
  976. {
  977. mbFlagsDirty = TRUE;
  978. }
  979. }
  980. //-----------------------------------------------------------------------------
  981. // controlFlagsDirty()
  982. //-----------------------------------------------------------------------------
  983. BOOL LLAgent::controlFlagsDirty() const
  984. {
  985. return mbFlagsDirty;
  986. }
  987. //-----------------------------------------------------------------------------
  988. // enableControlFlagReset()
  989. //-----------------------------------------------------------------------------
  990. void LLAgent::enableControlFlagReset()
  991. {
  992. mbFlagsNeedReset = TRUE;
  993. }
  994. //-----------------------------------------------------------------------------
  995. // resetControlFlags()
  996. //-----------------------------------------------------------------------------
  997. void LLAgent::resetControlFlags()
  998. {
  999. if (mbFlagsNeedReset)
  1000. {
  1001. mbFlagsNeedReset = FALSE;
  1002. mbFlagsDirty = FALSE;
  1003. // reset all of the ephemeral flags
  1004. // some flags are managed elsewhere
  1005. mControlFlags &= AGENT_CONTROL_AWAY | AGENT_CONTROL_FLY | AGENT_CONTROL_MOUSELOOK;
  1006. }
  1007. }
  1008. //-----------------------------------------------------------------------------
  1009. // setAFK()
  1010. //-----------------------------------------------------------------------------
  1011. void LLAgent::setAFK()
  1012. {
  1013. if (!gAgent.getRegion())
  1014. {
  1015. // Don't set AFK if we're not talking to a region yet.
  1016. return;
  1017. }
  1018. if (!(mControlFlags & AGENT_CONTROL_AWAY))
  1019. {
  1020. sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_START);
  1021. setControlFlags(AGENT_CONTROL_AWAY | AGENT_CONTROL_STOP);
  1022. LL_INFOS("AFK") << "Setting Away" << LL_ENDL;
  1023. gAwayTimer.start();
  1024. if (gAFKMenu)
  1025. {
  1026. gAFKMenu->setLabel(LLTrans::getString("AvatarSetNotAway"));
  1027. }
  1028. }
  1029. }
  1030. //-----------------------------------------------------------------------------
  1031. // clearAFK()
  1032. //-----------------------------------------------------------------------------
  1033. void LLAgent::clearAFK()
  1034. {
  1035. gAwayTriggerTimer.reset();
  1036. // Gods can sometimes get into away state (via gestures)
  1037. // without setting the appropriate control flag. JC
  1038. if (mControlFlags & AGENT_CONTROL_AWAY
  1039. || (isAgentAvatarValid()
  1040. && (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AWAY) != gAgentAvatarp->mSignaledAnimations.end())))
  1041. {
  1042. sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP);
  1043. clearControlFlags(AGENT_CONTROL_AWAY);
  1044. LL_INFOS("AFK") << "Clearing Away" << LL_ENDL;
  1045. if (gAFKMenu)
  1046. {
  1047. gAFKMenu->setLabel(LLTrans::getString("AvatarSetAway"));
  1048. }
  1049. }
  1050. }
  1051. //-----------------------------------------------------------------------------
  1052. // getAFK()
  1053. //-----------------------------------------------------------------------------
  1054. BOOL LLAgent::getAFK() const
  1055. {
  1056. return (mControlFlags & AGENT_CONTROL_AWAY) != 0;
  1057. }
  1058. //-----------------------------------------------------------------------------
  1059. // setBusy()
  1060. //-----------------------------------------------------------------------------
  1061. void LLAgent::setBusy()
  1062. {
  1063. sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_START);
  1064. mIsBusy = TRUE;
  1065. if (gBusyMenu)
  1066. {
  1067. gBusyMenu->setLabel(LLTrans::getString("AvatarSetNotBusy"));
  1068. }
  1069. LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(true);
  1070. }
  1071. //-----------------------------------------------------------------------------
  1072. // clearBusy()
  1073. //-----------------------------------------------------------------------------
  1074. void LLAgent::clearBusy()
  1075. {
  1076. mIsBusy = FALSE;
  1077. sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_STOP);
  1078. if (gBusyMenu)
  1079. {
  1080. gBusyMenu->setLabel(LLTrans::getString("AvatarSetBusy"));
  1081. }
  1082. LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(false);
  1083. }
  1084. //-----------------------------------------------------------------------------
  1085. // getBusy()
  1086. //-----------------------------------------------------------------------------
  1087. BOOL LLAgent::getBusy() const
  1088. {
  1089. return mIsBusy;
  1090. }
  1091. //-----------------------------------------------------------------------------
  1092. // startAutoPilotGlobal()
  1093. //-----------------------------------------------------------------------------
  1094. void LLAgent::startAutoPilotGlobal(
  1095. const LLVector3d &target_global,
  1096. const std::string& behavior_name,
  1097. const LLQuaternion *target_rotation,
  1098. void (*finish_callback)(BOOL, void *),
  1099. void *callback_data,
  1100. F32 stop_distance,
  1101. F32 rot_threshold,
  1102. BOOL allow_flying)
  1103. {
  1104. if (!isAgentAvatarValid())
  1105. {
  1106. return;
  1107. }
  1108. // Are there any pending callbacks from previous auto pilot requests?
  1109. if (mAutoPilotFinishedCallback)
  1110. {
  1111. mAutoPilotFinishedCallback(dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData);
  1112. }
  1113. mAutoPilotFinishedCallback = finish_callback;
  1114. mAutoPilotCallbackData = callback_data;
  1115. mAutoPilotRotationThreshold = rot_threshold;
  1116. mAutoPilotBehaviorName = behavior_name;
  1117. mAutoPilotAllowFlying = allow_flying;
  1118. LLVector3d delta_pos( target_global );
  1119. delta_pos -= getPositionGlobal();
  1120. F64 distance = delta_pos.magVec();
  1121. LLVector3d trace_target = target_global;
  1122. trace_target.mdV[VZ] -= 10.f;
  1123. LLVector3d intersection;
  1124. LLVector3 normal;
  1125. LLViewerObject *hit_obj;
  1126. F32 heightDelta = LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, trace_target, intersection, normal, &hit_obj);
  1127. if (stop_distance > 0.f)
  1128. {
  1129. mAutoPilotStopDistance = stop_distance;
  1130. }
  1131. else
  1132. {
  1133. // Guess at a reasonable stop distance.
  1134. mAutoPilotStopDistance = (F32) sqrt( distance );
  1135. if (mAutoPilotStopDistance < 0.5f)
  1136. {
  1137. mAutoPilotStopDistance = 0.5f;
  1138. }
  1139. }
  1140. if (mAutoPilotAllowFlying)
  1141. {
  1142. mAutoPilotFlyOnStop = getFlying();
  1143. }
  1144. else
  1145. {
  1146. mAutoPilotFlyOnStop = FALSE;
  1147. }
  1148. if (distance > 30.0 && mAutoPilotAllowFlying)
  1149. {
  1150. setFlying(TRUE);
  1151. }
  1152. if ( distance > 1.f &&
  1153. mAutoPilotAllowFlying &&
  1154. heightDelta > (sqrtf(mAutoPilotStopDistance) + 1.f))
  1155. {
  1156. setFlying(TRUE);
  1157. // Do not force flying for "Sit" behavior to prevent flying after pressing "Stand"
  1158. // from an object. See EXT-1655.
  1159. if ("Sit" != mAutoPilotBehaviorName)
  1160. mAutoPilotFlyOnStop = TRUE;
  1161. }
  1162. mAutoPilot = TRUE;
  1163. setAutoPilotTargetGlobal(target_global);
  1164. if (target_rotation)
  1165. {
  1166. mAutoPilotUseRotation = TRUE;
  1167. mAutoPilotTargetFacing = LLVector3::x_axis * *target_rotation;
  1168. mAutoPilotTargetFacing.mV[VZ] = 0.f;
  1169. mAutoPilotTargetFacing.normalize();
  1170. }
  1171. else
  1172. {
  1173. mAutoPilotUseRotation = FALSE;
  1174. }
  1175. mAutoPilotNoProgressFrameCount = 0;
  1176. }
  1177. //-----------------------------------------------------------------------------
  1178. // setAutoPilotTargetGlobal
  1179. //-----------------------------------------------------------------------------
  1180. void LLAgent::setAutoPilotTargetGlobal(const LLVector3d &target_global)
  1181. {
  1182. if (mAutoPilot)
  1183. {
  1184. mAutoPilotTargetGlobal = target_global;
  1185. // trace ray down to find height of destination from ground
  1186. LLVector3d traceEndPt = target_global;
  1187. traceEndPt.mdV[VZ] -= 20.f;
  1188. LLVector3d targetOnGround;
  1189. LLVector3 groundNorm;
  1190. LLViewerObject *obj;
  1191. LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, traceEndPt, targetOnGround, groundNorm, &obj);
  1192. F64 target_height = llmax((F64)gAgentAvatarp->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]);
  1193. // clamp z value of target to minimum height above ground
  1194. mAutoPilotTargetGlobal.mdV[VZ] = targetOnGround.mdV[VZ] + target_height;
  1195. mAutoPilotTargetDist = (F32)dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal);
  1196. }
  1197. }
  1198. //-----------------------------------------------------------------------------
  1199. // startFollowPilot()
  1200. //-----------------------------------------------------------------------------
  1201. void LLAgent::startFollowPilot(const LLUUID &leader_id, BOOL allow_flying, F32 stop_distance)
  1202. {
  1203. mLeaderID = leader_id;
  1204. if ( mLeaderID.isNull() ) return;
  1205. LLViewerObject* object = gObjectList.findObject(mLeaderID);
  1206. if (!object)
  1207. {
  1208. mLeaderID = LLUUID::null;
  1209. return;
  1210. }
  1211. startAutoPilotGlobal(object->getPositionGlobal(),
  1212. std::string(), // behavior_name
  1213. NULL, // target_rotation
  1214. NULL, // finish_callback
  1215. NULL, // callback_data
  1216. stop_distance,
  1217. 0.03f, // rotation_threshold
  1218. allow_flying);
  1219. }
  1220. //-----------------------------------------------------------------------------
  1221. // stopAutoPilot()
  1222. //-----------------------------------------------------------------------------
  1223. void LLAgent::stopAutoPilot(BOOL user_cancel)
  1224. {
  1225. if (mAutoPilot)
  1226. {
  1227. mAutoPilot = FALSE;
  1228. if (mAutoPilotUseRotation && !user_cancel)
  1229. {
  1230. resetAxes(mAutoPilotTargetFacing);
  1231. }
  1232. // Restore previous flying state before invoking mAutoPilotFinishedCallback to allow
  1233. // callback function to change the flying state (like in near_sit_down_point()).
  1234. // If the user cancelled, don't change the fly state
  1235. if (!user_cancel)
  1236. {
  1237. setFlying(mAutoPilotFlyOnStop);
  1238. }
  1239. //NB: auto pilot can terminate for a reason other than reaching the destination
  1240. if (mAutoPilotFinishedCallback)
  1241. {
  1242. mAutoPilotFinishedCallback(!user_cancel && dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData);
  1243. mAutoPilotFinishedCallback = NULL;
  1244. }
  1245. mLeaderID = LLUUID::null;
  1246. setControlFlags(AGENT_CONTROL_STOP);
  1247. if (user_cancel && !mAutoPilotBehaviorName.empty())
  1248. {
  1249. if (mAutoPilotBehaviorName == "Sit")
  1250. LLNotificationsUtil::add("CancelledSit");
  1251. else if (mAutoPilotBehaviorName == "Attach")
  1252. LLNotificationsUtil::add("CancelledAttach");
  1253. else
  1254. LLNotificationsUtil::add("Cancelled");
  1255. }
  1256. }
  1257. }
  1258. // Returns necessary agent pitch and yaw changes, radians.
  1259. //-----------------------------------------------------------------------------
  1260. // autoPilot()
  1261. //-----------------------------------------------------------------------------
  1262. void LLAgent::autoPilot(F32 *delta_yaw)
  1263. {
  1264. if (mAutoPilot)
  1265. {
  1266. if (!mLeaderID.isNull())
  1267. {
  1268. LLViewerObject* object = gObjectList.findObject(mLeaderID);
  1269. if (!object)
  1270. {
  1271. stopAutoPilot();
  1272. return;
  1273. }
  1274. mAutoPilotTargetGlobal = object->getPositionGlobal();
  1275. }
  1276. if (!isAgentAvatarValid()) return;
  1277. if (gAgentAvatarp->mInAir && mAutoPilotAllowFlying)
  1278. {
  1279. setFlying(TRUE);
  1280. }
  1281. LLVector3 at;
  1282. at.setVec(mFrameAgent.getAtAxis());
  1283. LLVector3 target_agent = getPosAgentFromGlobal(mAutoPilotTargetGlobal);
  1284. LLVector3 direction = target_agent - getPositionAgent();
  1285. F32 target_dist = direction.magVec();
  1286. if (target_dist >= mAutoPilotTargetDist)
  1287. {
  1288. mAutoPilotNoProgressFrameCount++;
  1289. if (mAutoPilotNoProgressFrameCount > AUTOPILOT_MAX_TIME_NO_PROGRESS * gFPSClamped)
  1290. {
  1291. stopAutoPilot();
  1292. return;
  1293. }
  1294. }
  1295. mAutoPilotTargetDist = target_dist;
  1296. // Make this a two-dimensional solution
  1297. at.mV[VZ] = 0.f;
  1298. direction.mV[VZ] = 0.f;
  1299. at.normalize();
  1300. F32 xy_distance = direction.normalize();
  1301. F32 yaw = 0.f;
  1302. if (mAutoPilotTargetDist > mAutoPilotStopDistance)
  1303. {
  1304. yaw = angle_between(mFrameAgent.getAtAxis(), direction);
  1305. }
  1306. else if (mAutoPilotUseRotation)
  1307. {
  1308. // we're close now just aim at target facing
  1309. yaw = angle_between(at, mAutoPilotTargetFacing);
  1310. direction = mAutoPilotTargetFacing;
  1311. }
  1312. yaw = 4.f * yaw / gFPSClamped;
  1313. // figure out which direction to turn
  1314. LLVector3 scratch(at % direction);
  1315. if (scratch.mV[VZ] > 0.f)
  1316. {
  1317. setControlFlags(AGENT_CONTROL_YAW_POS);
  1318. }
  1319. else
  1320. {
  1321. yaw = -yaw;
  1322. setControlFlags(AGENT_CONTROL_YAW_NEG);
  1323. }
  1324. *delta_yaw = yaw;
  1325. // Compute when to start slowing down and when to stop
  1326. F32 stop_distance = mAutoPilotStopDistance;
  1327. F32 slow_distance;
  1328. if (getFlying())
  1329. {
  1330. slow_distance = llmax(6.f, mAutoPilotStopDistance + 5.f);
  1331. stop_distance = llmax(2.f, mAutoPilotStopDistance);
  1332. }
  1333. else
  1334. {
  1335. slow_distance = llmax(3.f, mAutoPilotStopDistance + 2.f);
  1336. }
  1337. // If we're flying, handle autopilot points above or below you.
  1338. if (getFlying() && xy_distance < AUTOPILOT_HEIGHT_ADJUST_DISTANCE)
  1339. {
  1340. if (isAgentAvatarValid())
  1341. {
  1342. F64 current_height = gAgentAvatarp->getPositionGlobal().mdV[VZ];
  1343. F32 delta_z = (F32)(mAutoPilotTargetGlobal.mdV[VZ] - current_height);
  1344. F32 slope = delta_z / xy_distance;
  1345. if (slope > 0.45f && delta_z > 6.f)
  1346. {
  1347. setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_POS);
  1348. }
  1349. else if (slope > 0.002f && delta_z > 0.5f)
  1350. {
  1351. setControlFlags(AGENT_CONTROL_UP_POS);
  1352. }
  1353. else if (slope < -0.45f && delta_z < -6.f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND)
  1354. {
  1355. setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_NEG);
  1356. }
  1357. else if (slope < -0.002f && delta_z < -0.5f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND)
  1358. {
  1359. setControlFlags(AGENT_CONTROL_UP_NEG);
  1360. }
  1361. }
  1362. }
  1363. // calculate delta rotation to target heading
  1364. F32 delta_target_heading = angle_between(mFrameAgent.getAtAxis(), mAutoPilotTargetFacing);
  1365. if (xy_distance > slow_distance && yaw < (F_PI / 10.f))
  1366. {
  1367. // walking/flying fast
  1368. setControlFlags(AGENT_CONTROL_FAST_AT | AGENT_CONTROL_AT_POS);
  1369. }
  1370. else if (mAutoPilotTargetDist > mAutoPilotStopDistance)
  1371. {
  1372. // walking/flying slow
  1373. if (at * direction > 0.9f)
  1374. {
  1375. setControlFlags(AGENT_CONTROL_AT_POS);
  1376. }
  1377. else if (at * direction < -0.9f)
  1378. {
  1379. setControlFlags(AGENT_CONTROL_AT_NEG);
  1380. }
  1381. }
  1382. // check to see if we need to keep rotating to target orientation
  1383. if (mAutoPilotTargetDist < mAutoPilotStopDistance)
  1384. {
  1385. setControlFlags(AGENT_CONTROL_STOP);
  1386. if(!mAutoPilotUseRotation || (delta_target_heading < mAutoPilotRotationThreshold))
  1387. {
  1388. stopAutoPilot();
  1389. }
  1390. }
  1391. }
  1392. }
  1393. //-----------------------------------------------------------------------------
  1394. // propagate()
  1395. //-----------------------------------------------------------------------------
  1396. void LLAgent::propagate(const F32 dt)
  1397. {
  1398. // Update UI based on agent motion
  1399. LLFloaterMove *floater_move = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
  1400. if (floater_move)
  1401. {
  1402. floater_move->mForwardButton ->setToggleState( gAgentCamera.getAtKey() > 0 || gAgentCamera.getWalkKey() > 0 );
  1403. floater_move->mBackwardButton ->setToggleState( gAgentCamera.getAtKey() < 0 || gAgentCamera.getWalkKey() < 0 );
  1404. floater_move->mTurnLeftButton ->setToggleState( gAgentCamera.getYawKey() > 0.f );
  1405. floater_move->mTurnRightButton ->setToggleState( gAgentCamera.getYawKey() < 0.f );
  1406. floater_move->mSlideLeftButton ->setToggleState( gAgentCamera.getLeftKey() > 0.f );
  1407. floater_move->mSlideRightButton ->setToggleState( gAgentCamera.getLeftKey() < 0.f );
  1408. floater_move->mMoveUpButton ->setToggleState( gAgentCamera.getUpKey() > 0 );
  1409. floater_move->mMoveDownButton ->setToggleState( gAgentCamera.getUpKey() < 0 );
  1410. }
  1411. // handle rotation based on keyboard levels
  1412. const F32 YAW_RATE = 90.f * DEG_TO_RAD; // radians per second
  1413. yaw(YAW_RATE * gAgentCamera.getYawKey() * dt);
  1414. const F32 PITCH_RATE = 90.f * DEG_TO_RAD; // radians per second
  1415. pitch(PITCH_RATE * gAgentCamera.getPitchKey() * dt);
  1416. // handle auto-land behavior
  1417. if (isAgentAvatarValid())
  1418. {
  1419. BOOL in_air = gAgentAvatarp->mInAir;
  1420. LLVector3 land_vel = getVelocity();
  1421. land_vel.mV[VZ] = 0.f;
  1422. if (!in_air
  1423. && gAgentCamera.getUpKey() < 0
  1424. && land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED
  1425. && gSavedSettings.getBOOL("AutomaticFly"))
  1426. {
  1427. // land automatically
  1428. setFlying(FALSE);
  1429. }
  1430. }
  1431. gAgentCamera.clearGeneralKeys();
  1432. }
  1433. //-----------------------------------------------------------------------------
  1434. // updateAgentPosition()
  1435. //-----------------------------------------------------------------------------
  1436. void LLAgent::updateAgentPosition(const F32 dt, const F32 yaw_radians, const S32 mouse_x, const S32 mouse_y)
  1437. {
  1438. if (mMoveTimer.getStarted() && mMoveTimer.getElapsedTimeF32() > gSavedSettings.getF32("NotMovingHintTimeout"))
  1439. {
  1440. LLFirstUse::notMoving();
  1441. }
  1442. propagate(dt);
  1443. // static S32 cameraUpdateCount = 0;
  1444. rotate(yaw_radians, 0, 0, 1);
  1445. //
  1446. // Check for water and land collision, set underwater flag
  1447. //
  1448. gAgentCamera.updateLookAt(mouse_x, mouse_y);
  1449. }
  1450. // friends and operators
  1451. std::ostream& operator<<(std::ostream &s, const LLAgent &agent)
  1452. {
  1453. // This is unfinished, but might never be used.
  1454. // We'll just leave it for now; we can always delete it.
  1455. s << " { "
  1456. << " Frame = " << agent.mFrameAgent << "\n"
  1457. << " }";
  1458. return s;
  1459. }
  1460. // TRUE if your own avatar needs to be rendered. Usually only
  1461. // in third person and build.
  1462. //-----------------------------------------------------------------------------
  1463. // needsRenderAvatar()
  1464. //-----------------------------------------------------------------------------
  1465. BOOL LLAgent::needsRenderAvatar()
  1466. {
  1467. if (gAgentCamera.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson)
  1468. {
  1469. return FALSE;
  1470. }
  1471. return mShowAvatar && mGenderChosen;
  1472. }
  1473. // TRUE if we need to render your own avatar's head.
  1474. BOOL LLAgent::needsRenderHead()
  1475. {
  1476. return (LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCamera.cameraMouselook());
  1477. }
  1478. //-----------------------------------------------------------------------------
  1479. // startTyping()
  1480. //-----------------------------------------------------------------------------
  1481. void LLAgent::startTyping()
  1482. {
  1483. mTypingTimer.reset();
  1484. if (getRenderState() & AGENT_STATE_TYPING)
  1485. {
  1486. // already typing, don't trigger a different animation
  1487. return;
  1488. }
  1489. setRenderState(AGENT_STATE_TYPING);
  1490. if (mChatTimer.getElapsedTimeF32() < 2.f)
  1491. {
  1492. LLViewerObject* chatter = gObjectList.findObject(mLastChatterID);
  1493. if (chatter && chatter->isAvatar())
  1494. {
  1495. gAgentCamera.setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero);
  1496. }
  1497. }
  1498. if (gSavedSettings.getBOOL("PlayTypingAnim"))
  1499. {
  1500. sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_START);
  1501. }
  1502. LLNearbyChatBar::getInstance()->sendChatFromViewer("", CHAT_TYPE_START, FALSE);
  1503. }
  1504. //-----------------------------------------------------------------------------
  1505. // stopTyping()
  1506. //-----------------------------------------------------------------------------
  1507. void LLAgent::stopTyping()
  1508. {
  1509. if (mRenderState & AGENT_STATE_TYPING)
  1510. {
  1511. clearRenderState(AGENT_STATE_TYPING);
  1512. sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_STOP);
  1513. LLNearbyChatBar::getInstance()->sendChatFromViewer("", CHAT_TYPE_STOP, FALSE);
  1514. }
  1515. }
  1516. //-----------------------------------------------------------------------------
  1517. // setRenderState()
  1518. //-----------------------------------------------------------------------------
  1519. void LLAgent::setRenderState(U8 newstate)
  1520. {
  1521. mRenderState |= newstate;
  1522. }
  1523. //-----------------------------------------------------------------------------
  1524. // clearRenderState()
  1525. //-----------------------------------------------------------------------------
  1526. void LLAgent::clearRenderState(U8 clearstate)
  1527. {
  1528. mRenderState &= ~clearstate;
  1529. }
  1530. //-----------------------------------------------------------------------------
  1531. // getRenderState()
  1532. //-----------------------------------------------------------------------------
  1533. U8 LLAgent::getRenderState()
  1534. {
  1535. // *FIX: don't do stuff in a getter! This is infinite loop city!
  1536. if ((mTypingTimer.getElapsedTimeF32() > TYPING_TIMEOUT_SECS)
  1537. && (mRenderState & AGENT_STATE_TYPING))
  1538. {
  1539. stopTyping();
  1540. }
  1541. if ((!LLSelectMgr::getInstance()->getSelection()->isEmpty() && LLSelectMgr::getInstance()->shouldShowSelection())
  1542. || LLToolMgr::getInstance()->getCurrentTool()->isEditing() )
  1543. {
  1544. setRenderState(AGENT_STATE_EDITING);
  1545. }
  1546. else
  1547. {
  1548. clearRenderState(AGENT_STATE_EDITING);
  1549. }
  1550. return mRenderState;
  1551. }
  1552. //-----------------------------------------------------------------------------
  1553. //-----------------------------------------------------------------------------
  1554. //-----------------------------------------------------------------------------
  1555. // endAnimationUpdateUI()
  1556. //-----------------------------------------------------------------------------
  1557. void LLAgent::endAnimationUpdateUI()
  1558. {
  1559. if (gAgentCamera.getCameraMode() == gAgentCamera.getLastCameraMode())
  1560. {
  1561. // We're already done endAnimationUpdateUI for this transition.
  1562. return;
  1563. }
  1564. // clean up UI from mode we're leaving
  1565. if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_MOUSELOOK )
  1566. {
  1567. gToolBarView->setToolBarsVisible(true);
  1568. // show mouse cursor
  1569. gViewerWindow->showCursor();
  1570. // show menus
  1571. gMenuBarView->setVisible(TRUE);
  1572. LLNavigationBar::getInstance()->setVisible(TRUE && gSavedSettings.getBOOL("ShowNavbarNavigationPanel"));
  1573. gStatusBar->setVisibleForMouselook(true);
  1574. if (gSavedSettings.getBOOL("ShowMiniLocationPanel"))
  1575. {
  1576. LLPanelTopInfoBar::getInstance()->setVisible(TRUE);
  1577. }
  1578. LLChicletBar::getInstance()->setVisible(TRUE);
  1579. LLPanelStandStopFlying::getInstance()->setVisible(TRUE);
  1580. LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
  1581. LLFloaterCamera::onLeavingMouseLook();
  1582. if (mMouselookModeOutSignal)
  1583. {
  1584. (*mMouselookModeOutSignal)();
  1585. }
  1586. // Only pop if we have pushed...
  1587. if (TRUE == mViewsPushed)
  1588. {
  1589. #if 0 // Use this once all floaters are registered
  1590. LLFloaterReg::restoreVisibleInstances();
  1591. #else // Use this for now
  1592. LLFloaterView::skip_list_t skip_list;
  1593. if (LLFloaterReg::findInstance("mini_map"))
  1594. {
  1595. skip_list.insert(LLFloaterReg::findInstance("mini_map"));
  1596. }
  1597. gFloaterView->popVisibleAll(skip_list);
  1598. #endif
  1599. mViewsPushed = FALSE;
  1600. }
  1601. gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
  1602. if( gMorphView )
  1603. {
  1604. gMorphView->setVisible( FALSE );
  1605. }
  1606. // Disable mouselook-specific animations
  1607. if (isAgentAvatarValid())
  1608. {
  1609. if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) )
  1610. {
  1611. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end())
  1612. {
  1613. sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_STOP);
  1614. sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_START);
  1615. }
  1616. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end())
  1617. {
  1618. sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_STOP);
  1619. sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_START);
  1620. }
  1621. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end())
  1622. {
  1623. sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_STOP);
  1624. sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_START);
  1625. }
  1626. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != gAgentAvatarp->mSignaledAnimations.end())
  1627. {
  1628. sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_STOP);
  1629. sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_START);
  1630. }
  1631. }
  1632. }
  1633. }
  1634. else if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR)
  1635. {
  1636. // make sure we ask to save changes
  1637. LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
  1638. if( gMorphView )
  1639. {
  1640. gMorphView->setVisible( FALSE );
  1641. }
  1642. if (isAgentAvatarValid())
  1643. {
  1644. if(mCustomAnim)
  1645. {
  1646. sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_STOP);
  1647. sendAnimationRequest(ANIM_AGENT_CUSTOMIZE_DONE, ANIM_REQUEST_START);
  1648. mCustomAnim = FALSE ;
  1649. }
  1650. }
  1651. gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
  1652. LLFloaterCamera::onAvatarEditingAppearance(false);
  1653. }
  1654. //---------------------------------------------------------------------
  1655. // Set up UI for mode we're entering
  1656. //---------------------------------------------------------------------
  1657. if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK)
  1658. {
  1659. // clean up UI
  1660. // first show anything hidden by UI toggle
  1661. gViewerWindow->setUIVisibility(TRUE);
  1662. // then hide stuff we want hidden for mouselook
  1663. gToolBarView->setToolBarsVisible(false);
  1664. gMenuBarView->setVisible(FALSE);
  1665. LLNavigationBar::getInstance()->setVisible(FALSE);
  1666. gStatusBar->setVisibleForMouselook(false);
  1667. LLPanelTopInfoBar::getInstance()->setVisible(FALSE);
  1668. LLChicletBar::getInstance()->setVisible(FALSE);
  1669. LLPanelStandStopFlying::getInstance()->setVisible(FALSE);
  1670. // clear out camera lag effect
  1671. gAgentCamera.clearCameraLag();
  1672. // JC - Added for always chat in third person option
  1673. gFocusMgr.setKeyboardFocus(NULL);
  1674. LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset);
  1675. mViewsPushed = TRUE;
  1676. if (mMouselookModeInSignal)
  1677. {
  1678. (*mMouselookModeInSignal)();
  1679. }
  1680. // hide all floaters except the mini map
  1681. #if 0 // Use this once all floaters are registered
  1682. std::set<std::string> exceptions;
  1683. exceptions.insert("mini_map");
  1684. LLFloaterReg::hideVisibleInstances(exceptions);
  1685. #else // Use this for now
  1686. LLFloaterView::skip_list_t skip_list;
  1687. skip_list.insert(LLFloaterReg::findInstance("mini_map"));
  1688. gFloaterView->pushVisibleAll(FALSE, skip_list);
  1689. #endif
  1690. if( gMorphView )
  1691. {
  1692. gMorphView->setVisible(FALSE);
  1693. }
  1694. gConsole->setVisible( TRUE );
  1695. if (isAgentAvatarValid())
  1696. {
  1697. // Trigger mouselook-specific animations
  1698. if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) )
  1699. {
  1700. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end())
  1701. {
  1702. sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_STOP);
  1703. sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_START);
  1704. }
  1705. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end())
  1706. {
  1707. sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_STOP);
  1708. sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_START);
  1709. }
  1710. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end())
  1711. {
  1712. sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_STOP);
  1713. sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_START);
  1714. }
  1715. if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != gAgentAvatarp->mSignaledAnimations.end())
  1716. {
  1717. sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_STOP);
  1718. sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_START);
  1719. }
  1720. }
  1721. if (gAgentAvatarp->getParent())
  1722. {
  1723. LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
  1724. LLViewerObject* root_object = (LLViewerObject*)gAgentAvatarp->getRoot();
  1725. if (root_object->flagCameraDecoupled())
  1726. {
  1727. resetAxes(at_axis);
  1728. }
  1729. else
  1730. {
  1731. resetAxes(at_axis * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation());
  1732. }
  1733. }
  1734. }
  1735. }
  1736. else if (gAgentCamera.getCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR)
  1737. {
  1738. LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset);
  1739. if( gMorphView )
  1740. {
  1741. gMorphView->setVisible( TRUE );
  1742. }
  1743. // freeze avatar
  1744. if (isAgentAvatarValid())
  1745. {
  1746. mPauseRequest = gAgentAvatarp->requestPause();
  1747. }
  1748. LLFloaterCamera::onAvatarEditingAppearance(true);
  1749. }
  1750. if (isAgentAvatarValid())
  1751. {
  1752. gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode());
  1753. }
  1754. gFloaterTools->dirty();
  1755. // Don't let this be called more than once if the camera
  1756. // mode hasn't changed. --JC
  1757. gAgentCamera.updateLastCamera();
  1758. }
  1759. boost::signals2::connection LLAgent::setMouselookModeInCallback( const camera_signal_t::slot_type& cb )
  1760. {
  1761. if (!mMouselookModeInSignal) mMouselookModeInSignal = new camera_signal_t();
  1762. return mMouselookModeInSignal->connect(cb);
  1763. }
  1764. boost::signals2::connection LLAgent::setMouselookModeOutCallback( const camera_signal_t::slot_type& cb )
  1765. {
  1766. if (!mMouselookModeOutSignal) mMouselookModeOutSignal = new camera_signal_t();
  1767. return mMouselookModeOutSignal->connect(cb);
  1768. }
  1769. //-----------------------------------------------------------------------------
  1770. // heardChat()
  1771. //-----------------------------------------------------------------------------
  1772. void LLAgent::heardChat(const LLUUID& id)
  1773. {
  1774. // log text and voice chat to speaker mgr
  1775. // for keeping track of active speakers, etc.
  1776. LLLocalSpeakerMgr::getInstance()->speakerChatted(id);
  1777. // don't respond to your own voice
  1778. if (id == getID()) return;
  1779. if (ll_rand(2) == 0)
  1780. {
  1781. LLViewerObject *chatter = gObjectList.findObject(mLastChatterID);
  1782. gAgentCamera.setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero);
  1783. }
  1784. mLastChatterID = id;
  1785. mChatTimer.reset();
  1786. }
  1787. const F32 SIT_POINT_EXTENTS = 0.2f;
  1788. LLSD ll_sdmap_from_vector3(const LLVector3& vec)
  1789. {
  1790. LLSD ret;
  1791. ret["X"] = vec.mV[VX];
  1792. ret["Y"] = vec.mV[VY];
  1793. ret["Z"] = vec.mV[VZ];
  1794. return ret;
  1795. }
  1796. LLVector3 ll_vector3_from_sdmap(const LLSD& sd)
  1797. {
  1798. LLVector3 ret;
  1799. ret.mV[VX] = F32(sd["X"].asReal());
  1800. ret.mV[VY] = F32(sd["Y"].asReal());
  1801. ret.mV[VZ] = F32(sd["Z"].asReal());
  1802. return ret;
  1803. }
  1804. void LLAgent::setStartPosition( U32 location_id )
  1805. {
  1806. LLViewerObject *object;
  1807. if (gAgentID == LLUUID::null)
  1808. {
  1809. return;
  1810. }
  1811. // we've got an ID for an agent viewerobject
  1812. object = gObjectList.findObject(gAgentID);
  1813. if (! object)
  1814. {
  1815. llinfos << "setStartPosition - Can't find agent viewerobject id " << gAgentID << llendl;
  1816. return;
  1817. }
  1818. // we've got the viewer object
  1819. // Sometimes the agent can be velocity interpolated off of
  1820. // this simulator. Clamp it to the region the agent is
  1821. // in, a little bit in on each side.
  1822. const F32 INSET = 0.5f; //meters
  1823. const F32 REGION_WIDTH = LLWorld::getInstance()->getRegionWidthInMeters();
  1824. LLVector3 agent_pos = getPositionAgent();
  1825. if (isAgentAvatarValid())
  1826. {
  1827. // the z height is at the agent's feet
  1828. agent_pos.mV[VZ] -= 0.5f * gAgentAvatarp->mBodySize.mV[VZ];
  1829. }
  1830. agent_pos.mV[VX] = llclamp( agent_pos.mV[VX], INSET, REGION_WIDTH - INSET );
  1831. agent_pos.mV[VY] = llclamp( agent_pos.mV[VY], INSET, REGION_WIDTH - INSET );
  1832. // Don't let them go below ground, or too high.
  1833. agent_pos.mV[VZ] = llclamp( agent_pos.mV[VZ],
  1834. mRegionp->getLandHeightRegion( agent_pos ),
  1835. LLWorld::getInstance()->getRegionMaxHeight() );
  1836. // Send the CapReq
  1837. LLSD request;
  1838. LLSD body;
  1839. LLSD homeLocation;
  1840. homeLocation["LocationId"] = LLSD::Integer(location_id);
  1841. homeLocation["LocationPos"] = ll_sdmap_from_vector3(agent_pos);
  1842. homeLocation["LocationLookAt"] = ll_sdmap_from_vector3(mFrameAgent.getAtAxis());
  1843. body["HomeLocation"] = homeLocation;
  1844. // This awkward idiom warrants explanation.
  1845. // For starters, LLSDMessage::ResponderAdapter is ONLY for testing the new
  1846. // LLSDMessage functionality with a pre-existing LLHTTPClient::Responder.
  1847. // In new code, define your reply/error methods on the same class as the
  1848. // sending method, bind them to local LLEventPump objects and pass those
  1849. // LLEventPump names in the request LLSD object.
  1850. // When testing old code, the new LLHomeLocationResponder object
  1851. // is referenced by an LLHTTPClient::ResponderPtr, so when the
  1852. // ResponderAdapter is deleted, the LLHomeLocationResponder will be too.
  1853. // We must trust that the underlying LLHTTPClient code will eventually
  1854. // fire either the reply callback or the error callback; either will cause
  1855. // the ResponderAdapter to delete itself.
  1856. LLSDMessage::ResponderAdapter*
  1857. adapter(new LLSDMessage::ResponderAdapter(new LLHomeLocationResponder()));
  1858. request["message"] = "HomeLocation";
  1859. request["payload"] = body;
  1860. request["reply"] = adapter->getReplyName();
  1861. request["error"] = adapter->getErrorName();
  1862. gAgent.getRegion()->getCapAPI().post(request);
  1863. const U32 HOME_INDEX = 1;
  1864. if( HOME_INDEX == location_id )
  1865. {
  1866. setHomePosRegion( mRegionp->getHandle(), getPositionAgent() );
  1867. }
  1868. }
  1869. struct HomeLocationMapper: public LLCapabilityListener::CapabilityMapper
  1870. {
  1871. // No reply message expected
  1872. HomeLocationMapper(): LLCapabilityListener::CapabilityMapper("HomeLocation") {}
  1873. virtual void buildMessage(LLMessageSystem* msg,
  1874. const LLUUID& agentID,
  1875. const LLUUID& sessionID,
  1876. const std::string& capabilityName,
  1877. const LLSD& payload) const
  1878. {
  1879. msg->newMessageFast(_PREHASH_SetStartLocationRequest);
  1880. msg->nextBlockFast( _PREHASH_AgentData);
  1881. msg->addUUIDFast(_PREHASH_AgentID, agentID);
  1882. msg->addUUIDFast(_PREHASH_SessionID, sessionID);
  1883. msg->nextBlockFast( _PREHASH_StartLocationData);
  1884. // corrected by sim
  1885. msg->addStringFast(_PREHASH_SimName, "");
  1886. msg->addU32Fast(_PREHASH_LocationID, payload["HomeLocation"]["LocationId"].asInteger());
  1887. msg->addVector3Fast(_PREHASH_LocationPos,
  1888. ll_vector3_from_sdmap(payload["HomeLocation"]["LocationPos"]));
  1889. msg->addVector3Fast(_PREHASH_LocationLookAt,
  1890. ll_vector3_from_sdmap(payload["HomeLocation"]["LocationLookAt"]));
  1891. }
  1892. };
  1893. // Need an instance of this class so it will self-register
  1894. static HomeLocationMapper homeLocationMapper;
  1895. void LLAgent::requestStopMotion( LLMotion* motion )
  1896. {
  1897. // Notify all avatars that a motion has stopped.
  1898. // This is needed to clear the animation state bits
  1899. LLUUID anim_state = motion->getID();
  1900. onAnimStop(motion->getID());
  1901. // if motion is not looping, it could have stopped by running out of time
  1902. // so we need to tell the server this
  1903. // llinfos << "Sending stop for motion " << motion->getName() << llendl;
  1904. sendAnimationRequest( anim_state, ANIM_REQUEST_STOP );
  1905. }
  1906. void LLAgent::onAnimStop(const LLUUID& id)
  1907. {
  1908. // handle automatic state transitions (based on completion of animation playback)
  1909. if (id == ANIM_AGENT_STAND)
  1910. {
  1911. stopFidget();
  1912. }
  1913. else if (id == ANIM_AGENT_AWAY)
  1914. {
  1915. clearAFK();
  1916. }
  1917. else if (id == ANIM_AGENT_STANDUP)
  1918. {
  1919. // send stand up command
  1920. setControlFlags(AGENT_CONTROL_FINISH_ANIM);
  1921. // now trigger dusting self off animation
  1922. if (isAgentAvatarValid() && !gAgentAvatarp->mBelowWater && rand() % 3 == 0)
  1923. sendAnimationRequest( ANIM_AGENT_BRUSH, ANIM_REQUEST_START );
  1924. }
  1925. else if (id == ANIM_AGENT_PRE_JUMP || id == ANIM_AGENT_LAND || id == ANIM_AGENT_MEDIUM_LAND)
  1926. {
  1927. setControlFlags(AGENT_CONTROL_FINISH_ANIM);
  1928. }
  1929. }
  1930. bool LLAgent::isGodlike() const
  1931. {