diff options
Diffstat (limited to 'indra/newview/llagent.cpp')
-rw-r--r-- | indra/newview/llagent.cpp | 140 |
1 files changed, 65 insertions, 75 deletions
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 6db7088812..8e15a08373 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -222,7 +222,6 @@ private: LLVector3d mPosGlobal; }; - class LLTeleportRequestViaLocationLookAt : public LLTeleportRequestViaLocation { public: @@ -844,7 +843,6 @@ void LLAgent::movePitch(F32 mag) } } - // Does this parcel allow you to fly? BOOL LLAgent::canFly() { @@ -926,7 +924,6 @@ void LLAgent::setFlying(BOOL fly, BOOL fail_sound) mbFlagsDirty = TRUE; } - // UI based mechanism of setting fly state //----------------------------------------------------------------------------- // toggleFlying() @@ -1005,7 +1002,6 @@ void LLAgent::capabilityReceivedCallback(const LLUUID ®ion_id, LLViewerRegion } } - //----------------------------------------------------------------------------- // setRegion() //----------------------------------------------------------------------------- @@ -1112,7 +1108,6 @@ void LLAgent::setRegion(LLViewerRegion *regionp) mRegionChangedSignal(); } - //----------------------------------------------------------------------------- // getRegion() //----------------------------------------------------------------------------- @@ -1121,7 +1116,6 @@ LLViewerRegion *LLAgent::getRegion() const return mRegionp; } - LLHost LLAgent::getRegionHost() const { if (mRegionp) @@ -1152,7 +1146,6 @@ BOOL LLAgent::inPrelude() return mRegionp && mRegionp->isPrelude(); } - std::string LLAgent::getRegionCapability(const std::string &name) { if (!mRegionp) @@ -1161,7 +1154,6 @@ std::string LLAgent::getRegionCapability(const std::string &name) return mRegionp->getCapability(name); } - //----------------------------------------------------------------------------- // canManageEstate() //----------------------------------------------------------------------------- @@ -1189,7 +1181,6 @@ void LLAgent::sendMessage() gMessageSystem->sendMessage(mRegionp->getHost()); } - //----------------------------------------------------------------------------- // sendReliableMessage() //----------------------------------------------------------------------------- @@ -1223,7 +1214,6 @@ LLVector3 LLAgent::getVelocity() const } } - //----------------------------------------------------------------------------- // setPositionAgent() //----------------------------------------------------------------------------- @@ -1292,12 +1282,11 @@ const LLVector3 &LLAgent::getPositionAgent() mFrameAgent.setOrigin(gAgentAvatarp->getPositionAgent()); } else - { - mFrameAgent.setOrigin(gAgentAvatarp->getRenderPosition()); - } + { + mFrameAgent.setOrigin(gAgentAvatarp->getRenderPosition()); + } } - return mFrameAgent.getOrigin(); } @@ -1306,7 +1295,6 @@ boost::signals2::connection LLAgent::whenPositionChanged(position_signal_t::slot return mOnPositionChanged.connect(fn); } - //----------------------------------------------------------------------------- // getRegionsVisited() //----------------------------------------------------------------------------- @@ -1323,7 +1311,6 @@ F64 LLAgent::getDistanceTraveled() const return mDistanceTraveled; } - //----------------------------------------------------------------------------- // getPosAgentFromGlobal() //----------------------------------------------------------------------------- @@ -1334,7 +1321,6 @@ LLVector3 LLAgent::getPosAgentFromGlobal(const LLVector3d &pos_global) const return pos_agent; } - //----------------------------------------------------------------------------- // getPosGlobalFromAgent() //----------------------------------------------------------------------------- @@ -1350,7 +1336,6 @@ void LLAgent::sitDown() setControlFlags(AGENT_CONTROL_SIT_ON_GROUND); } - //----------------------------------------------------------------------------- // resetAxes() //----------------------------------------------------------------------------- @@ -1359,7 +1344,6 @@ void LLAgent::resetAxes() mFrameAgent.resetAxes(); } - // Copied from LLCamera::setOriginAndLookAt // Look_at must be unit vector //----------------------------------------------------------------------------- @@ -1388,7 +1372,6 @@ void LLAgent::resetAxes(const LLVector3 &look_at) mFrameAgent.setAxes(look_at, left, up); } - //----------------------------------------------------------------------------- // rotate() //----------------------------------------------------------------------------- @@ -1397,7 +1380,6 @@ void LLAgent::rotate(F32 angle, const LLVector3 &axis) mFrameAgent.rotate(angle, axis); } - //----------------------------------------------------------------------------- // rotate() //----------------------------------------------------------------------------- @@ -1406,7 +1388,6 @@ void LLAgent::rotate(F32 angle, F32 x, F32 y, F32 z) mFrameAgent.rotate(angle, x, y, z); } - //----------------------------------------------------------------------------- // rotate() //----------------------------------------------------------------------------- @@ -1415,7 +1396,6 @@ void LLAgent::rotate(const LLMatrix3 &matrix) mFrameAgent.rotate(matrix); } - //----------------------------------------------------------------------------- // rotate() //----------------------------------------------------------------------------- @@ -1424,7 +1404,6 @@ void LLAgent::rotate(const LLQuaternion &quaternion) mFrameAgent.rotate(quaternion); } - //----------------------------------------------------------------------------- // getReferenceUpVector() //----------------------------------------------------------------------------- @@ -1453,51 +1432,71 @@ LLVector3 LLAgent::getReferenceUpVector() return up_vector; } - // Radians, positive is forward into ground //----------------------------------------------------------------------------- // pitch() //----------------------------------------------------------------------------- void LLAgent::pitch(F32 angle) { - // don't let user pitch if pointed almost all the way down or up + if (gAgentCamera.getCameraMode() == CAMERA_MODE_THIRD_PERSON || + gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK) + { + // Backup the current orientation + LLCoordFrame saved_frame_agent(mFrameAgent); - // A dot B = mag(A) * mag(B) * cos(angle between A and B) - // so... cos(angle between A and B) = A dot B / mag(A) / mag(B) - // = A dot B for unit vectors + // Optimistic rotation up/down (vertical angle can reach and exceed 0 or 180) + mFrameAgent.pitch(angle); - LLVector3 skyward = getReferenceUpVector(); + // Cosine of the angle between current agent At and Up directions + F32 agent_at_to_up_now_cos = saved_frame_agent.mXAxis * gAgentCamera.getCameraUpVector(); + bool pitch_away_from_horizont = (angle < 0) ^ (agent_at_to_up_now_cos < 0); + // We always allow to pitch in direction to horizont (from zenith or from nadir) + if (!pitch_away_from_horizont) + return; - // clamp pitch to limits - if (angle >= 0.f) - { - const F32 look_down_limit = 179.f * DEG_TO_RAD; - F32 angle_from_skyward = acos(mFrameAgent.getAtAxis() * skyward); - if (angle_from_skyward + angle > look_down_limit) + // Current angle between agent At and Up directions + F32 agent_at_to_up_now = acos(agent_at_to_up_now_cos); + // Requested angle between agent At and Up directions + F32 agent_at_to_up_new = agent_at_to_up_now + angle; + F32 agent_at_to_up_new_sin = sin(agent_at_to_up_new); + // Overpitched? Then rollback + if (agent_at_to_up_new_sin < 1e-4) { - angle = look_down_limit - angle_from_skyward; + mFrameAgent = saved_frame_agent; + return; } - } - else if (angle < 0.f) - { - const F32 look_up_limit = 5.f * DEG_TO_RAD; - const LLVector3& viewer_camera_pos = LLViewerCamera::getInstance()->getOrigin(); - LLVector3 agent_focus_pos = getPosAgentFromGlobal(gAgentCamera.calcFocusPositionTargetGlobal()); - LLVector3 look_dir = agent_focus_pos - viewer_camera_pos; - F32 angle_from_skyward = angle_between(look_dir, skyward); - if (angle_from_skyward + angle < look_up_limit) + + if (gAgentCamera.getCameraMode() == CAMERA_MODE_THIRD_PERSON || + (isAgentAvatarValid() && gAgentAvatarp->getParent())) { - angle = look_up_limit - angle_from_skyward; + // Camera sight relative to agent frame (focus - offset) + LLVector3 camera_offset(gAgentCamera.getCameraOffsetInitial()); + LLVector3 camera_focus(gAgentCamera.getFocusOffsetInitial()); + LLVector3 camera_sight(camera_focus - camera_offset); + // 2D projection of the camera sight to the XZ plane + LLVector2 camera_sight_2d_vert(1, camera_sight[VZ]); + camera_sight_2d_vert.normalize(); + // Cosine of the 2D angle between initial camera At and X axis (in the XZ plane) + F32 camera_sight_to_at_2d_vert_cos = camera_sight_2d_vert * LLVector2(LLVector3::x_axis); + F32 camera_sight_to_at_2d_vert = acos(camera_sight_to_at_2d_vert_cos); + // Requested angle between camera At and Up directions + F32 camera_at_to_up_new = agent_at_to_up_new - camera_sight_to_at_2d_vert; + F32 camera_at_to_up_new_sin = sin(camera_at_to_up_new); + // Overpitched? Then rollback + if (camera_at_to_up_new_sin < 1e-4) + { + mFrameAgent = saved_frame_agent; + return; + } } } - - if (fabs(angle) > 1e-4) + else { + // No limitations in other modes mFrameAgent.pitch(angle); } } - //----------------------------------------------------------------------------- // roll() //----------------------------------------------------------------------------- @@ -1506,7 +1505,6 @@ void LLAgent::roll(F32 angle) mFrameAgent.roll(angle); } - //----------------------------------------------------------------------------- // yaw() //----------------------------------------------------------------------------- @@ -1518,7 +1516,6 @@ void LLAgent::yaw(F32 angle) } } - // Returns a quat that represents the rotation of the agent in the absolute frame //----------------------------------------------------------------------------- // getQuat() @@ -1545,7 +1542,6 @@ void LLAgent::setControlFlags(U32 mask) mbFlagsDirty = TRUE; } - //----------------------------------------------------------------------------- // clearControlFlags() //----------------------------------------------------------------------------- @@ -1659,7 +1655,6 @@ bool LLAgent::isDoNotDisturb() const return mIsDoNotDisturb; } - //----------------------------------------------------------------------------- // startAutoPilotGlobal() //----------------------------------------------------------------------------- @@ -1765,7 +1760,6 @@ void LLAgent::startAutoPilotGlobal( mAutoPilotNoProgressFrameCount = 0; } - //----------------------------------------------------------------------------- // setAutoPilotTargetGlobal //----------------------------------------------------------------------------- @@ -1819,7 +1813,6 @@ void LLAgent::startFollowPilot(const LLUUID &leader_id, BOOL allow_flying, F32 s allow_flying); } - //----------------------------------------------------------------------------- // stopAutoPilot() //----------------------------------------------------------------------------- @@ -1861,7 +1854,6 @@ void LLAgent::stopAutoPilot(BOOL user_cancel) } } - // Returns necessary agent pitch and yaw changes, radians. //----------------------------------------------------------------------------- // autoPilot() @@ -2050,7 +2042,6 @@ void LLAgent::autoPilot(F32 *delta_yaw) } } - //----------------------------------------------------------------------------- // propagate() //----------------------------------------------------------------------------- @@ -2071,11 +2062,20 @@ void LLAgent::propagate(const F32 dt) } // handle rotation based on keyboard levels - const F32 YAW_RATE = 90.f * DEG_TO_RAD; // radians per second - yaw(YAW_RATE * gAgentCamera.getYawKey() * dt); + if (fabs(dt) > 1e-6) + { + if (fabs(gAgentCamera.getYawKey()) > 1e-6) + { + static const F32 YAW_RATE = 90.f * DEG_TO_RAD; // radians per second + yaw(YAW_RATE * gAgentCamera.getYawKey() * dt); + } - const F32 PITCH_RATE = 90.f * DEG_TO_RAD; // radians per second - pitch(PITCH_RATE * gAgentCamera.getPitchKey() * dt); + if (fabs(gAgentCamera.getPitchKey()) > 1e-6) + { + static const F32 PITCH_RATE = 90.f * DEG_TO_RAD; // radians per second + pitch(PITCH_RATE * gAgentCamera.getPitchKey() * dt); + } + } // handle auto-land behavior if (isAgentAvatarValid()) @@ -2236,7 +2236,6 @@ void LLAgent::clearRenderState(U8 clearstate) mRenderState &= ~clearstate; } - //----------------------------------------------------------------------------- // getRenderState() //----------------------------------------------------------------------------- @@ -2278,6 +2277,7 @@ void LLAgent::endAnimationUpdateUI() { return; } + if (gAgentCamera.getCameraMode() == gAgentCamera.getLastCameraMode()) { // We're already done endAnimationUpdateUI for this transition. @@ -2343,9 +2343,8 @@ void LLAgent::endAnimationUpdateUI() mViewsPushed = FALSE; } - gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR); - if( gMorphView ) + if (gMorphView) { gMorphView->setVisible( FALSE ); } @@ -2353,7 +2352,7 @@ void LLAgent::endAnimationUpdateUI() // Disable mouselook-specific animations if (isAgentAvatarValid()) { - if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) ) + if (gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS)) { if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end()) { @@ -2972,7 +2971,6 @@ void LLAgent::sendMaturityPreferenceToServer(U8 pPreferredMaturity) } } - void LLAgent::processMaturityPreferenceFromServer(const LLSD &result, U8 perferredMaturity) { U8 maturity = SIM_ACCESS_MIN; @@ -3042,7 +3040,6 @@ void LLAgent::changeInterestListMode(const std::string &new_mode) } } - bool LLAgent::requestPostCapability(const std::string &capName, LLSD &postData, httpCallback_t cbSuccess, httpCallback_t cbFailure) { if (getRegion()) @@ -3370,7 +3367,6 @@ void LLAgent::sendAnimationStateReset() sendReliableMessage(); } - // Send a message to the region to revoke sepecified permissions on ALL scripts in the region // If the target is an object in the region, permissions in scripts on that object are cleared. // If it is the region ID, all scripts clear the permissions for this agent @@ -4304,7 +4300,6 @@ void LLAgent::onCapabilitiesReceivedAfterTeleport() check_merchant_status(); } - void LLAgent::teleportRequest( const U64& region_handle, const LLVector3& pos_local, @@ -4404,7 +4399,6 @@ void LLAgent::doTeleportViaLure(const LLUUID& lure_id, BOOL godlike) } } - // James Cook, July 28, 2005 void LLAgent::teleportCancel() { @@ -4529,7 +4523,6 @@ LLAgent::ETeleportState LLAgent::getTeleportState() const TELEPORT_NONE : mTeleportState; } - void LLAgent::setTeleportState(ETeleportState state) { if (mTeleportRequest && (state != TELEPORT_NONE) && (mTeleportRequest->getStatus() == LLTeleportRequest::kFailed)) @@ -4574,7 +4567,6 @@ void LLAgent::setTeleportState(ETeleportState state) } } - void LLAgent::stopCurrentAnimations() { LL_DEBUGS("Avatar") << "Stopping current animations" << LL_ENDL; @@ -4689,7 +4681,6 @@ void LLAgent::stopFidget() gAgent.sendAnimationRequests(anims, ANIM_REQUEST_STOP); } - void LLAgent::requestEnterGodMode() { LLMessageSystem* msg = gMessageSystem; @@ -4810,7 +4801,6 @@ void LLAgent::sendAgentUpdateUserInfo(const std::string& directory_visibility) } } - void LLAgent::updateAgentUserInfoCoro(std::string capurl, std::string directory_visibility) { LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); |