From fc49539b36adfd4c87d7824db5d94a7858683f3d Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 23 Mar 2010 15:59:52 -0400 Subject: EXT-2959 : Full out camera functions from llagent to llagentcamera First check-in; only compiles, nothing more. --- indra/newview/llagent.cpp | 321 ++++++++++++++++++++++++++-------------------- 1 file changed, 182 insertions(+), 139 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index c5d7f6f118..5ee026f021 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -35,6 +35,7 @@ #include "pipeline.h" +#include "llagentcamera.h" #include "llagentlistener.h" #include "llagentwearables.h" #include "llagentui.h" @@ -59,6 +60,7 @@ #include "llnearbychatbar.h" #include "llnotificationsutil.h" #include "llparcel.h" +#include "llrendersphere.h" #include "llsdutil.h" #include "llsidetray.h" #include "llsky.h" @@ -80,6 +82,8 @@ #include "llworld.h" #include "llworldmap.h" +LLAgentCamera gAgentCameraHACK; // Seraph delete + using namespace LLVOAvatarDefines; extern LLMenuBarGL* gMenuBarView; @@ -106,14 +110,18 @@ const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS = 1.5f; // seconds const LLVector3d FACE_EDIT_CAMERA_OFFSET(0.4f, -0.05f, 0.07f); const LLVector3d FACE_EDIT_TARGET_OFFSET(0.f, 0.f, 0.05f); +/* // Mousewheel camera zoom const F32 MIN_ZOOM_FRACTION = 0.25f; const F32 INITIAL_ZOOM_FRACTION = 1.f; const F32 MAX_ZOOM_FRACTION = 8.f; +*/ + const F32 METERS_PER_WHEEL_CLICK = 1.f; const F32 MAX_TIME_DELTA = 1.f; +/* const F32 CAMERA_ZOOM_HALF_LIFE = 0.07f; // seconds const F32 FOV_ZOOM_HALF_LIFE = 0.07f; // seconds @@ -141,20 +149,25 @@ const F32 OBJECT_MIN_ZOOM = 0.02f; const F32 APPEARANCE_MIN_ZOOM = 0.39f; const F32 APPEARANCE_MAX_ZOOM = 8.f; +*/ // fidget constants const F32 MIN_FIDGET_TIME = 8.f; // seconds const F32 MAX_FIDGET_TIME = 20.f; // seconds const S32 MAX_NUM_CHAT_POSITIONS = 10; +/* const F32 GROUND_TO_AIR_CAMERA_TRANSITION_TIME = 0.5f; const F32 GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME = 0.5f; +*/ const F32 MAX_VELOCITY_AUTO_LAND_SQUARED = 4.f * 4.f; const F32 MAX_FOCUS_OFFSET = 20.f; +/* const F32 OBJECT_EXTENTS_PADDING = 0.5f; +*/ const F32 MIN_RADIUS_ALPHA_SIZZLE = 0.5f; @@ -224,14 +237,14 @@ LLAgent::LLAgent() : mHideGroupTitle(FALSE), mGroupID(), - mLookAt(NULL), - mPointAt(NULL), +//// mLookAt(NULL), +//// mPointAt(NULL), - mHUDTargetZoom(1.f), - mHUDCurZoom(1.f), +//// mHUDTargetZoom(1.f), +//// mHUDCurZoom(1.f), mInitialized(FALSE), mListener(), - mForceMouselook(FALSE), +//// mForceMouselook(FALSE), mDoubleTapRunTimer(), mDoubleTapRunMode(DOUBLETAP_NONE), @@ -254,47 +267,47 @@ LLAgent::LLAgent() : mRenderState(0), mTypingTimer(), - mCameraMode( CAMERA_MODE_THIRD_PERSON ), - mLastCameraMode( CAMERA_MODE_THIRD_PERSON ), +//// mCameraMode( CAMERA_MODE_THIRD_PERSON ), +//// mLastCameraMode( CAMERA_MODE_THIRD_PERSON ), mViewsPushed(FALSE), - mCameraPreset(CAMERA_PRESET_REAR_VIEW), +//// mCameraPreset(CAMERA_PRESET_REAR_VIEW), mCustomAnim(FALSE), mShowAvatar(TRUE), - mCameraAnimating( FALSE ), - mAnimationCameraStartGlobal(), - mAnimationFocusStartGlobal(), - mAnimationTimer(), - mAnimationDuration(0.33f), +//// mCameraAnimating( FALSE ), +//// mAnimationCameraStartGlobal(), +//// mAnimationFocusStartGlobal(), +//// mAnimationTimer(), +//// mAnimationDuration(0.33f), - mCameraFOVZoomFactor(0.f), - mCameraCurrentFOVZoomFactor(0.f), - mCameraFocusOffset(), - mCameraFOVDefault(DEFAULT_FIELD_OF_VIEW), - - mCameraCollidePlane(), - - mCurrentCameraDistance(2.f), // meters, set in init() - mTargetCameraDistance(2.f), - mCameraZoomFraction(1.f), // deprecated - mThirdPersonHeadOffset(0.f, 0.f, 1.f), - mSitCameraEnabled(FALSE), - mCameraSmoothingLastPositionGlobal(), - mCameraSmoothingLastPositionAgent(), - mCameraSmoothingStop(FALSE), - - mCameraUpVector(LLVector3::z_axis), // default is straight up - - mFocusOnAvatar(TRUE), - mFocusGlobal(), - mFocusTargetGlobal(), - mFocusObject(NULL), - mFocusObjectDist(0.f), - mFocusObjectOffset(), - mFocusDotRadius( 0.1f ), // meters - mTrackFocusObject(TRUE), - mUIOffset(0.f), +//// mCameraFOVZoomFactor(0.f), +//// mCameraCurrentFOVZoomFactor(0.f), +//// mCameraFocusOffset(), +//// mCameraFOVDefault(DEFAULT_FIELD_OF_VIEW), + +//// mCameraCollidePlane(), + +//// mCurrentCameraDistance(2.f), // meters, set in init() +//// mTargetCameraDistance(2.f), +//// mCameraZoomFraction(1.f), // deprecated +//// mThirdPersonHeadOffset(0.f, 0.f, 1.f), +//// mSitCameraEnabled(FALSE), +//// mCameraSmoothingLastPositionGlobal(), +//// mCameraSmoothingLastPositionAgent(), +//// mCameraSmoothingStop(FALSE), + +//// mCameraUpVector(LLVector3::z_axis), // default is straight up + +//// mFocusOnAvatar(TRUE), +//// mFocusGlobal(), +//// mFocusTargetGlobal(), +//// mFocusObject(NULL), +//// mFocusObjectDist(0.f), +//// mFocusObjectOffset(), +//// mFocusDotRadius( 0.1f ), // meters +//// mTrackFocusObject(TRUE), +// mUIOffset(0.f), mFrameAgent(), @@ -358,7 +371,7 @@ LLAgent::LLAgent() : mControlsTakenPassedOnCount[i] = 0; } - mFollowCam.setMaxCameraDistantFromSubject( MAX_CAMERA_DISTANCE_FROM_AGENT ); +//// mFollowCam.setMaxCameraDistantFromSubject( MAX_CAMERA_DISTANCE_FROM_AGENT ); mListener.reset(new LLAgentListener(*this)); } @@ -376,6 +389,9 @@ void LLAgent::init() // *Note: this is where LLViewerCamera::getInstance() used to be constructed. + setFlying( gSavedSettings.getBOOL("FlyingAtExit") ); + +/* LLViewerCamera::getInstance()->setView(DEFAULT_FIELD_OF_VIEW); // Leave at 0.1 meters until we have real near clip management LLViewerCamera::getInstance()->setNear(0.1f); @@ -383,25 +399,24 @@ void LLAgent::init() LLViewerCamera::getInstance()->setAspect( gViewerWindow->getWorldViewAspectRatio() ); // default, overridden in LLViewerWindow::reshape LLViewerCamera::getInstance()->setViewHeightInPixels(768); // default, overridden in LLViewerWindow::reshape - setFlying( gSavedSettings.getBOOL("FlyingAtExit") ); - - mCameraFocusOffsetTarget = LLVector4(gSavedSettings.getVector3("CameraOffsetBuild")); +//// mCameraFocusOffsetTarget = LLVector4(gSavedSettings.getVector3("CameraOffsetBuild")); - mCameraPreset = (ECameraPreset) gSavedSettings.getU32("CameraPreset"); +//// mCameraPreset = (ECameraPreset) gSavedSettings.getU32("CameraPreset"); - mCameraOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getVector3("CameraOffsetRearView"); - mCameraOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getVector3("CameraOffsetFrontView"); - mCameraOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getVector3("CameraOffsetGroupView"); +//// mCameraOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getVector3("CameraOffsetRearView"); +//// mCameraOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getVector3("CameraOffsetFrontView"); +//// mCameraOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getVector3("CameraOffsetGroupView"); - mFocusOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getVector3d("FocusOffsetRearView"); - mFocusOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getVector3d("FocusOffsetFrontView"); - mFocusOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getVector3d("FocusOffsetGroupView"); +//// mFocusOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getVector3d("FocusOffsetRearView"); +//// mFocusOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getVector3d("FocusOffsetFrontView"); +//// mFocusOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getVector3d("FocusOffsetGroupView"); - mCameraCollidePlane.clearVec(); - mCurrentCameraDistance = getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale"); - mTargetCameraDistance = mCurrentCameraDistance; - mCameraZoomFraction = 1.f; - mTrackFocusObject = gSavedSettings.getBOOL("TrackFocusObject"); +//// mCameraCollidePlane.clearVec(); +//// mCurrentCameraDistance = getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale"); +//// mTargetCameraDistance = mCurrentCameraDistance; +//// mCameraZoomFraction = 1.f; +//// mTrackFocusObject = gSavedSettings.getBOOL("TrackFocusObject"); +*/ mEffectColor = LLUIColorTable::instance().getColor("EffectColor"); @@ -416,22 +431,9 @@ void LLAgent::init() //----------------------------------------------------------------------------- void LLAgent::cleanup() { - setSitCamera(LLUUID::null); - mAvatarObject = NULL; - - if(mLookAt) - { - mLookAt->markDead() ; - mLookAt = NULL; - } - if(mPointAt) - { - mPointAt->markDead() ; - mPointAt = NULL; - } mRegionp = NULL; - setFocusObject(NULL); + gAgentCameraHACK.cleanup(); } //----------------------------------------------------------------------------- @@ -444,6 +446,7 @@ LLAgent::~LLAgent() // *Note: this is where LLViewerCamera::getInstance() used to be deleted. } +/* // Change camera back to third person, stop the autopilot, // deselect stuff, etc. //----------------------------------------------------------------------------- @@ -520,6 +523,7 @@ void LLAgent::resetView(BOOL reset_camera, BOOL change_camera) mHUDTargetZoom = 1.f; } +*/ // Handle any actions that need to be performed when the main app gains focus // (such as through alt-tab). @@ -528,9 +532,9 @@ void LLAgent::resetView(BOOL reset_camera, BOOL change_camera) //----------------------------------------------------------------------------- void LLAgent::onAppFocusGained() { - if (CAMERA_MODE_MOUSELOOK == mCameraMode) + if (CAMERA_MODE_MOUSELOOK == gAgentCameraHACK.mCameraMode) { - changeCameraToDefault(); + gAgentCameraHACK.changeCameraToDefault(); LLToolMgr::getInstance()->clearSavedTool(); } } @@ -547,6 +551,7 @@ void LLAgent::ageChat() } } +/* // Allow camera to be moved somewhere other than behind avatar. //----------------------------------------------------------------------------- // unlockView() @@ -562,7 +567,7 @@ void LLAgent::unlockView() setFocusOnAvatar(FALSE, FALSE); // no animation } } - +*/ //----------------------------------------------------------------------------- // moveAt() @@ -585,7 +590,7 @@ void LLAgent::moveAt(S32 direction, bool reset) if (reset) { - resetView(); + gAgentCameraHACK.resetView(); } } @@ -608,7 +613,7 @@ void LLAgent::moveAtNudge(S32 direction) setControlFlags(AGENT_CONTROL_NUDGE_AT_NEG); } - resetView(); + gAgentCameraHACK.resetView(); } //----------------------------------------------------------------------------- @@ -630,7 +635,7 @@ void LLAgent::moveLeft(S32 direction) setControlFlags(AGENT_CONTROL_LEFT_NEG | AGENT_CONTROL_FAST_LEFT); } - resetView(); + gAgentCameraHACK.resetView(); } //----------------------------------------------------------------------------- @@ -652,7 +657,7 @@ void LLAgent::moveLeftNudge(S32 direction) setControlFlags(AGENT_CONTROL_NUDGE_LEFT_NEG); } - resetView(); + gAgentCameraHACK.resetView(); } //----------------------------------------------------------------------------- @@ -674,7 +679,7 @@ void LLAgent::moveUp(S32 direction) setControlFlags(AGENT_CONTROL_UP_NEG | AGENT_CONTROL_FAST_UP); } - resetView(); + gAgentCameraHACK.resetView(); } //----------------------------------------------------------------------------- @@ -695,7 +700,7 @@ void LLAgent::moveYaw(F32 mag, bool reset_view) if (reset_view) { - resetView(); + gAgentCameraHACK.resetView(); } } @@ -806,7 +811,7 @@ void LLAgent::toggleFlying() BOOL fly = !gAgent.getFlying(); gAgent.setFlying( fly ); - gAgent.resetView(); + gAgentCameraHACK.resetView(); } // static @@ -878,7 +883,8 @@ void LLAgent::setRegion(LLViewerRegion *regionp) LLVector3 delta; delta.setVec(regionp->getOriginGlobal()); - setPositionAgent(getPositionAgent() - delta); + setPositionAgent +(getPositionAgent() - delta); LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin(); LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta); @@ -1028,6 +1034,7 @@ void LLAgent::setPositionAgent(const LLVector3 &pos_agent) } } +/* //----------------------------------------------------------------------------- // slamLookAt() //----------------------------------------------------------------------------- @@ -1038,6 +1045,7 @@ void LLAgent::slamLookAt(const LLVector3 &look_at) look_at_norm.normalize(); resetAxes(look_at_norm); } +*/ //----------------------------------------------------------------------------- // getPositionGlobal() @@ -1193,7 +1201,7 @@ LLVector3 LLAgent::getReferenceUpVector() mAvatarObject->getParent() && mAvatarObject->mDrawable.notNull()) { - U32 camera_mode = mCameraAnimating ? mLastCameraMode : mCameraMode; + U32 camera_mode = gAgentCameraHACK.mCameraAnimating ? gAgentCameraHACK.mLastCameraMode : gAgentCameraHACK.mCameraMode; // and in third person... if (camera_mode == CAMERA_MODE_THIRD_PERSON) { @@ -1292,7 +1300,7 @@ LLQuaternion LLAgent::getQuat() const return mFrameAgent.getQuaternion(); } - +/* //----------------------------------------------------------------------------- // calcFocusOffset() //----------------------------------------------------------------------------- @@ -1845,13 +1853,11 @@ void LLAgent::cameraZoomIn(const F32 fraction) { new_distance = max_distance; - /* // Unless camera is unlocked - if (!LLViewerCamera::sDisableCameraConstraints) - { - return; - } - */ + //if (!LLViewerCamera::sDisableCameraConstraints) + //{ + // return; + //} } if( cameraCustomizeAvatar() ) @@ -1985,6 +1991,7 @@ void LLAgent::cameraPanUp(F32 meters) // NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind -Nyx mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal(); } +*/ //----------------------------------------------------------------------------- // setKey() @@ -2546,9 +2553,10 @@ void LLAgent::updateAgentPosition(const F32 dt, const F32 yaw_radians, const S32 // Check for water and land collision, set underwater flag // - updateLookAt(mouse_x, mouse_y); + gAgentCameraHACK.updateLookAt(mouse_x, mouse_y); } +/* //----------------------------------------------------------------------------- // updateLookAt() //----------------------------------------------------------------------------- @@ -2620,6 +2628,7 @@ void LLAgent::updateLookAt(const S32 mouse_x, const S32 mouse_y) setLookAt(lookAtType, mAvatarObject, headLookAxis); } } +*/ // friends and operators @@ -2652,22 +2661,22 @@ void LLAgent::setAvatarObject(LLVOAvatarSelf *avatar) return; } - if (!mLookAt) + if (!gAgentCameraHACK.mLookAt) { - mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT); + gAgentCameraHACK.mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT); } - if (!mPointAt) + if (!gAgentCameraHACK.mPointAt) { - mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT); + gAgentCameraHACK.mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT); } - if (!mLookAt.isNull()) + if (!gAgentCameraHACK.mLookAt.isNull()) { - mLookAt->setSourceObject(avatar); + gAgentCameraHACK.mLookAt->setSourceObject(avatar); } - if (!mPointAt.isNull()) + if (!gAgentCameraHACK.mPointAt.isNull()) { - mPointAt->setSourceObject(avatar); + gAgentCameraHACK.mPointAt->setSourceObject(avatar); } } @@ -2678,7 +2687,7 @@ void LLAgent::setAvatarObject(LLVOAvatarSelf *avatar) //----------------------------------------------------------------------------- BOOL LLAgent::needsRenderAvatar() { - if (cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson) + if (gAgentCameraHACK.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson) { return FALSE; } @@ -2689,7 +2698,7 @@ BOOL LLAgent::needsRenderAvatar() // TRUE if we need to render your own avatar's head. BOOL LLAgent::needsRenderHead() { - return (LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !cameraMouselook()); + return (LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCameraHACK.cameraMouselook()); } //----------------------------------------------------------------------------- @@ -2711,7 +2720,7 @@ void LLAgent::startTyping() LLViewerObject* chatter = gObjectList.findObject(mLastChatterID); if (chatter && chatter->isAvatar()) { - gAgent.setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero); + gAgentCameraHACK.setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero); } } @@ -2790,14 +2799,14 @@ U8 LLAgent::getRenderState() //----------------------------------------------------------------------------- void LLAgent::endAnimationUpdateUI() { - if (mCameraMode == mLastCameraMode) + if (gAgentCameraHACK.mCameraMode == gAgentCameraHACK.mLastCameraMode) { // We're already done endAnimationUpdateUI for this transition. return; } // clean up UI from mode we're leaving - if ( mLastCameraMode == CAMERA_MODE_MOUSELOOK ) + if (gAgentCameraHACK.mLastCameraMode == CAMERA_MODE_MOUSELOOK ) { // show mouse cursor gViewerWindow->showCursor(); @@ -2835,7 +2844,7 @@ void LLAgent::endAnimationUpdateUI() } - gAgent.setLookAt(LOOKAT_TARGET_CLEAR); + gAgentCameraHACK.setLookAt(LOOKAT_TARGET_CLEAR); if( gMorphView ) { gMorphView->setVisible( FALSE ); @@ -2870,7 +2879,7 @@ void LLAgent::endAnimationUpdateUI() } } else - if( mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR ) + if(gAgentCameraHACK.mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) { // make sure we ask to save changes @@ -2892,13 +2901,13 @@ void LLAgent::endAnimationUpdateUI() } } - setLookAt(LOOKAT_TARGET_CLEAR); + gAgentCameraHACK.setLookAt(LOOKAT_TARGET_CLEAR); } //--------------------------------------------------------------------- // Set up UI for mode we're entering //--------------------------------------------------------------------- - if (mCameraMode == CAMERA_MODE_MOUSELOOK) + if (gAgentCameraHACK.mCameraMode == CAMERA_MODE_MOUSELOOK) { // hide menus gMenuBarView->setVisible(FALSE); @@ -2913,7 +2922,7 @@ void LLAgent::endAnimationUpdateUI() LLPanelStandStopFlying::getInstance()->setVisible(FALSE); // clear out camera lag effect - mCameraLag.clearVec(); + gAgentCameraHACK.mCameraLag.clearVec(); // JC - Added for always chat in third person option gFocusMgr.setKeyboardFocus(NULL); @@ -2983,7 +2992,7 @@ void LLAgent::endAnimationUpdateUI() } } - else if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) + else if (gAgentCameraHACK.mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) { LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset); @@ -3001,18 +3010,18 @@ void LLAgent::endAnimationUpdateUI() if (getAvatarObject()) { - getAvatarObject()->updateAttachmentVisibility(mCameraMode); + getAvatarObject()->updateAttachmentVisibility(gAgentCameraHACK.mCameraMode); } gFloaterTools->dirty(); // Don't let this be called more than once if the camera // mode hasn't changed. --JC - mLastCameraMode = mCameraMode; + gAgentCameraHACK.mLastCameraMode = gAgentCameraHACK.mCameraMode; } - +/* //----------------------------------------------------------------------------- // updateCamera() //----------------------------------------------------------------------------- @@ -3438,8 +3447,8 @@ F32 LLAgent::calcCustomizeAvatarUIOffset( const LLVector3d& camera_pos_global ) ui_offset = -offset; } } - F32 range = (F32)dist_vec(camera_pos_global, gAgent.getFocusGlobal()); - mUIOffset = lerp(mUIOffset, ui_offset, LLCriticalDamp::getInterpolant(0.05f)); + F32 range = (F32)dist_vec(camera_pos_global, gAgentCamera.getFocusGlobal()); + gAgentCameraHACK.mUIOffset = lerp(mUIOffset, ui_offset, LLCriticalDamp::getInterpolant(0.05f)); return mUIOffset * range; } @@ -3885,13 +3894,12 @@ LLVector3 LLAgent::getCameraOffsetInitial() return mCameraOffsetInitial[mCameraPreset]; } - //----------------------------------------------------------------------------- // handleScrollWheel() //----------------------------------------------------------------------------- void LLAgent::handleScrollWheel(S32 clicks) { - if ( mCameraMode == CAMERA_MODE_FOLLOW && gAgent.getFocusOnAvatar()) + if ( mCameraMode == CAMERA_MODE_FOLLOW && gAgentCamera.getFocusOnAvatar()) { if ( ! mFollowCam.getPositionLocked() ) // not if the followCam position is locked in place { @@ -3935,7 +3943,6 @@ void LLAgent::handleScrollWheel(S32 clicks) } } - //----------------------------------------------------------------------------- // getCameraMinOffGround() //----------------------------------------------------------------------------- @@ -4267,7 +4274,7 @@ void LLAgent::changeCameraToCustomizeAvatar(BOOL avatar_animate, BOOL camera_ani - gAgent.setFocusGlobal(LLVector3d::zero); + gAgentCamera.setFocusGlobal(LLVector3d::zero); } else { @@ -4576,6 +4583,7 @@ void LLAgent::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate) mFocusOnAvatar = focus_on_avatar; } +*/ //----------------------------------------------------------------------------- // heardChat() @@ -4592,7 +4600,7 @@ void LLAgent::heardChat(const LLUUID& id) if (ll_rand(2) == 0) { LLViewerObject *chatter = gObjectList.findObject(mLastChatterID); - setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero); + gAgentCameraHACK.setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero); } mLastChatterID = id; @@ -4605,7 +4613,7 @@ void LLAgent::heardChat(const LLUUID& id) void LLAgent::lookAtLastChat() { // Block if camera is animating or not in normal third person camera mode - if (mCameraAnimating || !cameraThirdPerson()) + if (gAgentCameraHACK.mCameraAnimating || !gAgentCameraHACK.cameraThirdPerson()) { return; } @@ -4629,7 +4637,7 @@ void LLAgent::lookAtLastChat() setControlFlags(AGENT_CONTROL_STOP); - changeCameraToThirdPerson(); + gAgentCameraHACK.changeCameraToThirdPerson(); LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition(); LLVector3 left = delta_pos % LLVector3::z_axis; @@ -4641,15 +4649,15 @@ void LLAgent::lookAtLastChat() new_camera_pos += up * 0.2f; if (chatter_av->mHeadp) { - setFocusGlobal(getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()), mLastChatterID); - mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()); + gAgentCameraHACK.setFocusGlobal(getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()), mLastChatterID); + gAgentCameraHACK.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()); } else { - setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); - mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); + gAgentCameraHACK.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); + gAgentCameraHACK.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); } - setFocusOnAvatar(FALSE, TRUE); + gAgentCameraHACK.setFocusOnAvatar(FALSE, TRUE); } else { @@ -4658,7 +4666,7 @@ void LLAgent::lookAtLastChat() setControlFlags(AGENT_CONTROL_STOP); - changeCameraToThirdPerson(); + gAgentCameraHACK.changeCameraToThirdPerson(); LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition(); LLVector3 left = delta_pos % LLVector3::z_axis; @@ -4669,9 +4677,9 @@ void LLAgent::lookAtLastChat() new_camera_pos += left * 0.3f; new_camera_pos += up * 0.2f; - setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); - mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); - setFocusOnAvatar(FALSE, TRUE); + gAgentCameraHACK.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); + gAgentCameraHACK.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); + gAgentCameraHACK.setFocusOnAvatar(FALSE, TRUE); } } } @@ -5182,7 +5190,7 @@ LLQuaternion LLAgent::getHeadRotation() return LLQuaternion::DEFAULT; } - if (!gAgent.cameraMouselook()) + if (!gAgentCameraHACK.cameraMouselook()) { return mAvatarObject->getRotation(); } @@ -5353,10 +5361,11 @@ void LLAgent::initOriginGlobal(const LLVector3d &origin_global) BOOL LLAgent::leftButtonGrabbed() const { - return (!cameraMouselook() && mControlsTakenCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) - || (cameraMouselook() && mControlsTakenCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0) - || (!cameraMouselook() && mControlsTakenPassedOnCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) - || (cameraMouselook() && mControlsTakenPassedOnCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0); + const BOOL camera_mouse_look = gAgentCameraHACK.cameraMouselook(); + return (!camera_mouse_look && mControlsTakenCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) + || (camera_mouse_look && mControlsTakenCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0) + || (!camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) + || (camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0); } BOOL LLAgent::rotateGrabbed() const @@ -5824,7 +5833,7 @@ void LLAgent::processAgentCachedTextureResponse(LLMessageSystem *mesgsys, void * return; } - if (gAgent.cameraCustomizeAvatar()) + if (gAgentCameraHACK.cameraCustomizeAvatar()) { // ignore baked textures when in customize mode return; @@ -5981,7 +5990,7 @@ bool LLAgent::teleportCore(bool is_local) // Close all pie menus, deselect land, etc. // Don't change the camera until we know teleport succeeded. JC - resetView(FALSE); + gAgentCameraHACK.resetView(FALSE); // local logic LLViewerStats::getInstance()->incStat(LLViewerStats::ST_TELEPORT_COUNT); @@ -6282,7 +6291,7 @@ void LLAgent::sendAgentSetAppearance() { if (mAvatarObject.isNull()) return; - if (gAgentQueryManager.mNumPendingQueries > 0 && !gAgent.cameraCustomizeAvatar()) + if (gAgentQueryManager.mNumPendingQueries > 0 && !gAgentCameraHACK.cameraCustomizeAvatar()) { return; } @@ -6500,7 +6509,41 @@ void LLAgent::dumpGroupInfo() //llinfos << "insig " << gAgent.mGroupInsigniaID << llendl; } -/********************************************************************************/ +// Draw a representation of current autopilot target +void LLAgent::renderAutoPilotTarget() +{ + if (mAutoPilot) + { + F32 height_meters; + LLVector3d target_global; + + glMatrixMode(GL_MODELVIEW); + gGL.pushMatrix(); + + // not textured + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + + // lovely green + glColor4f(0.f, 1.f, 1.f, 1.f); + + target_global = mAutoPilotTargetGlobal; + + gGL.translatef((F32)(target_global.mdV[VX]), (F32)(target_global.mdV[VY]), (F32)(target_global.mdV[VZ])); + + height_meters = 1.f; + + glScalef(height_meters, height_meters, height_meters); + + gSphere.render(1500.f); + + gGL.popMatrix(); + } +} + +/******************************************************************************** + * + */ + LLAgentQueryManager gAgentQueryManager; LLAgentQueryManager::LLAgentQueryManager() : -- cgit v1.2.3 From cc4a9b5640f4295c8af78efd4271a251434e39c6 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Wed, 24 Mar 2010 16:12:01 -0400 Subject: EXT-2959 : Pull out camera functions from llagent to llagentcamera #2 checkin. Superficial cleanup and some bug fixing (e.g. took out duplicate mDrawDistance from llagent, took out gAgentCameraHACK and gAgentHACK). --- indra/newview/llagent.cpp | 3933 ++++++++------------------------------------- 1 file changed, 676 insertions(+), 3257 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 5ee026f021..5dd4215206 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -82,8 +82,6 @@ #include "llworld.h" #include "llworldmap.h" -LLAgentCamera gAgentCameraHACK; // Seraph delete - using namespace LLVOAvatarDefines; extern LLMenuBarGL* gMenuBarView; @@ -110,65 +108,20 @@ const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS = 1.5f; // seconds const LLVector3d FACE_EDIT_CAMERA_OFFSET(0.4f, -0.05f, 0.07f); const LLVector3d FACE_EDIT_TARGET_OFFSET(0.f, 0.f, 0.05f); -/* -// Mousewheel camera zoom -const F32 MIN_ZOOM_FRACTION = 0.25f; -const F32 INITIAL_ZOOM_FRACTION = 1.f; -const F32 MAX_ZOOM_FRACTION = 8.f; -*/ - const F32 METERS_PER_WHEEL_CLICK = 1.f; const F32 MAX_TIME_DELTA = 1.f; -/* -const F32 CAMERA_ZOOM_HALF_LIFE = 0.07f; // seconds -const F32 FOV_ZOOM_HALF_LIFE = 0.07f; // seconds - -const F32 CAMERA_FOCUS_HALF_LIFE = 0.f;//0.02f; -const F32 CAMERA_LAG_HALF_LIFE = 0.25f; -const F32 MIN_CAMERA_LAG = 0.5f; -const F32 MAX_CAMERA_LAG = 5.f; - -const F32 CAMERA_COLLIDE_EPSILON = 0.1f; -const F32 MIN_CAMERA_DISTANCE = 0.1f; -const F32 AVATAR_ZOOM_MIN_X_FACTOR = 0.55f; -const F32 AVATAR_ZOOM_MIN_Y_FACTOR = 0.7f; -const F32 AVATAR_ZOOM_MIN_Z_FACTOR = 1.15f; - -const F32 MAX_CAMERA_DISTANCE_FROM_AGENT = 50.f; - -const F32 MAX_CAMERA_SMOOTH_DISTANCE = 50.0f; - -const F32 HEAD_BUFFER_SIZE = 0.3f; -const F32 CUSTOMIZE_AVATAR_CAMERA_ANIM_SLOP = 0.2f; - -const F32 LAND_MIN_ZOOM = 0.15f; -const F32 AVATAR_MIN_ZOOM = 0.5f; -const F32 OBJECT_MIN_ZOOM = 0.02f; - -const F32 APPEARANCE_MIN_ZOOM = 0.39f; -const F32 APPEARANCE_MAX_ZOOM = 8.f; -*/ - // fidget constants const F32 MIN_FIDGET_TIME = 8.f; // seconds const F32 MAX_FIDGET_TIME = 20.f; // seconds const S32 MAX_NUM_CHAT_POSITIONS = 10; -/* -const F32 GROUND_TO_AIR_CAMERA_TRANSITION_TIME = 0.5f; -const F32 GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME = 0.5f; -*/ const F32 MAX_VELOCITY_AUTO_LAND_SQUARED = 4.f * 4.f; const F32 MAX_FOCUS_OFFSET = 20.f; -/* -const F32 OBJECT_EXTENTS_PADDING = 0.5f; -*/ - const F32 MIN_RADIUS_ALPHA_SIZZLE = 0.5f; const F64 CHAT_AGE_FAST_RATE = 3.0; @@ -231,20 +184,12 @@ bool handleSlowMotionAnimation(const LLSD& newvalue) // LLAgent() //----------------------------------------------------------------------------- LLAgent::LLAgent() : - mDrawDistance( DEFAULT_FAR_PLANE ), - mGroupPowers(0), mHideGroupTitle(FALSE), mGroupID(), -//// mLookAt(NULL), -//// mPointAt(NULL), - -//// mHUDTargetZoom(1.f), -//// mHUDCurZoom(1.f), mInitialized(FALSE), mListener(), -//// mForceMouselook(FALSE), mDoubleTapRunTimer(), mDoubleTapRunMode(DOUBLETAP_NONE), @@ -267,48 +212,10 @@ LLAgent::LLAgent() : mRenderState(0), mTypingTimer(), -//// mCameraMode( CAMERA_MODE_THIRD_PERSON ), -//// mLastCameraMode( CAMERA_MODE_THIRD_PERSON ), mViewsPushed(FALSE), -//// mCameraPreset(CAMERA_PRESET_REAR_VIEW), - mCustomAnim(FALSE), mShowAvatar(TRUE), -//// mCameraAnimating( FALSE ), -//// mAnimationCameraStartGlobal(), -//// mAnimationFocusStartGlobal(), -//// mAnimationTimer(), -//// mAnimationDuration(0.33f), - -//// mCameraFOVZoomFactor(0.f), -//// mCameraCurrentFOVZoomFactor(0.f), -//// mCameraFocusOffset(), -//// mCameraFOVDefault(DEFAULT_FIELD_OF_VIEW), - -//// mCameraCollidePlane(), - -//// mCurrentCameraDistance(2.f), // meters, set in init() -//// mTargetCameraDistance(2.f), -//// mCameraZoomFraction(1.f), // deprecated -//// mThirdPersonHeadOffset(0.f, 0.f, 1.f), -//// mSitCameraEnabled(FALSE), -//// mCameraSmoothingLastPositionGlobal(), -//// mCameraSmoothingLastPositionAgent(), -//// mCameraSmoothingStop(FALSE), - -//// mCameraUpVector(LLVector3::z_axis), // default is straight up - -//// mFocusOnAvatar(TRUE), -//// mFocusGlobal(), -//// mFocusTargetGlobal(), -//// mFocusObject(NULL), -//// mFocusObjectDist(0.f), -//// mFocusObjectOffset(), -//// mFocusDotRadius( 0.1f ), // meters -//// mTrackFocusObject(TRUE), -// mUIOffset(0.f), - mFrameAgent(), mIsBusy(FALSE), @@ -320,20 +227,6 @@ LLAgent::LLAgent() : mYawKey(0.f), mPitchKey(0.f), - mOrbitLeftKey(0.f), - mOrbitRightKey(0.f), - mOrbitUpKey(0.f), - mOrbitDownKey(0.f), - mOrbitInKey(0.f), - mOrbitOutKey(0.f), - - mPanUpKey(0.f), - mPanDownKey(0.f), - mPanLeftKey(0.f), - mPanRightKey(0.f), - mPanInKey(0.f), - mPanOutKey(0.f), - mControlFlags(0x00000000), mbFlagsDirty(FALSE), mbFlagsNeedReset(FALSE), @@ -371,7 +264,6 @@ LLAgent::LLAgent() : mControlsTakenPassedOnCount[i] = 0; } -//// mFollowCam.setMaxCameraDistantFromSubject( MAX_CAMERA_DISTANCE_FROM_AGENT ); mListener.reset(new LLAgentListener(*this)); } @@ -385,39 +277,10 @@ void LLAgent::init() gSavedSettings.declareBOOL("SlowMotionAnimation", FALSE, "Declared in code", FALSE); gSavedSettings.getControl("SlowMotionAnimation")->getSignal()->connect(boost::bind(&handleSlowMotionAnimation, _2)); - mDrawDistance = gSavedSettings.getF32("RenderFarClip"); - // *Note: this is where LLViewerCamera::getInstance() used to be constructed. setFlying( gSavedSettings.getBOOL("FlyingAtExit") ); -/* - LLViewerCamera::getInstance()->setView(DEFAULT_FIELD_OF_VIEW); - // Leave at 0.1 meters until we have real near clip management - LLViewerCamera::getInstance()->setNear(0.1f); - LLViewerCamera::getInstance()->setFar(mDrawDistance); // if you want to change camera settings, do so in camera.h - LLViewerCamera::getInstance()->setAspect( gViewerWindow->getWorldViewAspectRatio() ); // default, overridden in LLViewerWindow::reshape - LLViewerCamera::getInstance()->setViewHeightInPixels(768); // default, overridden in LLViewerWindow::reshape - -//// mCameraFocusOffsetTarget = LLVector4(gSavedSettings.getVector3("CameraOffsetBuild")); - -//// mCameraPreset = (ECameraPreset) gSavedSettings.getU32("CameraPreset"); - -//// mCameraOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getVector3("CameraOffsetRearView"); -//// mCameraOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getVector3("CameraOffsetFrontView"); -//// mCameraOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getVector3("CameraOffsetGroupView"); - -//// mFocusOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getVector3d("FocusOffsetRearView"); -//// mFocusOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getVector3d("FocusOffsetFrontView"); -//// mFocusOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getVector3d("FocusOffsetGroupView"); - -//// mCameraCollidePlane.clearVec(); -//// mCurrentCameraDistance = getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale"); -//// mTargetCameraDistance = mCurrentCameraDistance; -//// mCameraZoomFraction = 1.f; -//// mTrackFocusObject = gSavedSettings.getBOOL("TrackFocusObject"); -*/ - mEffectColor = LLUIColorTable::instance().getColor("EffectColor"); gSavedSettings.getControl("PreferredMaturity")->getValidateSignal()->connect(boost::bind(&LLAgent::validateMaturity, this, _2)); @@ -433,7 +296,7 @@ void LLAgent::cleanup() { mAvatarObject = NULL; mRegionp = NULL; - gAgentCameraHACK.cleanup(); + gAgentCamera.cleanup(); } //----------------------------------------------------------------------------- @@ -446,85 +309,6 @@ LLAgent::~LLAgent() // *Note: this is where LLViewerCamera::getInstance() used to be deleted. } -/* -// Change camera back to third person, stop the autopilot, -// deselect stuff, etc. -//----------------------------------------------------------------------------- -// resetView() -//----------------------------------------------------------------------------- -void LLAgent::resetView(BOOL reset_camera, BOOL change_camera) -{ - if (mAutoPilot) - { - stopAutoPilot(TRUE); - } - - if (!gNoRender) - { - LLSelectMgr::getInstance()->unhighlightAll(); - - // By popular request, keep land selection while walking around. JC - // LLViewerParcelMgr::getInstance()->deselectLand(); - - // force deselect when walking and attachment is selected - // this is so people don't wig out when their avatar moves without animating - if (LLSelectMgr::getInstance()->getSelection()->isAttachment()) - { - LLSelectMgr::getInstance()->deselectAll(); - } - - // Hide all popup menus - gMenuHolder->hideMenus(); - } - - if (change_camera && !gSavedSettings.getBOOL("FreezeTime")) - { - changeCameraToDefault(); - - if (LLViewerJoystick::getInstance()->getOverrideCamera()) - { - handle_toggle_flycam(); - } - - // reset avatar mode from eventual residual motion - if (LLToolMgr::getInstance()->inBuildMode()) - { - LLViewerJoystick::getInstance()->moveAvatar(true); - } - - //Camera Tool is needed for Free Camera Control Mode - if (!LLFloaterCamera::inFreeCameraMode()) - { - LLFloaterReg::hideInstance("build"); - - // Switch back to basic toolset - LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); - } - - gViewerWindow->showCursor(); - } - - - if (reset_camera && !gSavedSettings.getBOOL("FreezeTime")) - { - if (!gViewerWindow->getLeftMouseDown() && cameraThirdPerson()) - { - // leaving mouse-steer mode - LLVector3 agent_at_axis = getAtAxis(); - agent_at_axis -= projected_vec(agent_at_axis, getReferenceUpVector()); - agent_at_axis.normalize(); - gAgent.resetAxes(lerp(getAtAxis(), agent_at_axis, LLCriticalDamp::getInterpolant(0.3f))); - } - - setFocusOnAvatar(TRUE, ANIMATE); - - mCameraFOVZoomFactor = 0.f; - } - - mHUDTargetZoom = 1.f; -} -*/ - // Handle any actions that need to be performed when the main app gains focus // (such as through alt-tab). //----------------------------------------------------------------------------- @@ -532,9 +316,9 @@ void LLAgent::resetView(BOOL reset_camera, BOOL change_camera) //----------------------------------------------------------------------------- void LLAgent::onAppFocusGained() { - if (CAMERA_MODE_MOUSELOOK == gAgentCameraHACK.mCameraMode) + if (CAMERA_MODE_MOUSELOOK == gAgentCamera.mCameraMode) { - gAgentCameraHACK.changeCameraToDefault(); + gAgentCamera.changeCameraToDefault(); LLToolMgr::getInstance()->clearSavedTool(); } } @@ -551,24 +335,6 @@ void LLAgent::ageChat() } } -/* -// Allow camera to be moved somewhere other than behind avatar. -//----------------------------------------------------------------------------- -// unlockView() -//----------------------------------------------------------------------------- -void LLAgent::unlockView() -{ - if (getFocusOnAvatar()) - { - if (mAvatarObject.notNull()) - { - setFocusGlobal( LLVector3d::zero, mAvatarObject->mID ); - } - setFocusOnAvatar(FALSE, FALSE); // no animation - } -} -*/ - //----------------------------------------------------------------------------- // moveAt() //----------------------------------------------------------------------------- @@ -590,7 +356,7 @@ void LLAgent::moveAt(S32 direction, bool reset) if (reset) { - gAgentCameraHACK.resetView(); + gAgentCamera.resetView(); } } @@ -613,7 +379,7 @@ void LLAgent::moveAtNudge(S32 direction) setControlFlags(AGENT_CONTROL_NUDGE_AT_NEG); } - gAgentCameraHACK.resetView(); + gAgentCamera.resetView(); } //----------------------------------------------------------------------------- @@ -635,7 +401,7 @@ void LLAgent::moveLeft(S32 direction) setControlFlags(AGENT_CONTROL_LEFT_NEG | AGENT_CONTROL_FAST_LEFT); } - gAgentCameraHACK.resetView(); + gAgentCamera.resetView(); } //----------------------------------------------------------------------------- @@ -657,7 +423,7 @@ void LLAgent::moveLeftNudge(S32 direction) setControlFlags(AGENT_CONTROL_NUDGE_LEFT_NEG); } - gAgentCameraHACK.resetView(); + gAgentCamera.resetView(); } //----------------------------------------------------------------------------- @@ -679,7 +445,7 @@ void LLAgent::moveUp(S32 direction) setControlFlags(AGENT_CONTROL_UP_NEG | AGENT_CONTROL_FAST_UP); } - gAgentCameraHACK.resetView(); + gAgentCamera.resetView(); } //----------------------------------------------------------------------------- @@ -700,7 +466,7 @@ void LLAgent::moveYaw(F32 mag, bool reset_view) if (reset_view) { - gAgentCameraHACK.resetView(); + gAgentCamera.resetView(); } } @@ -811,7 +577,7 @@ void LLAgent::toggleFlying() BOOL fly = !gAgent.getFlying(); gAgent.setFlying( fly ); - gAgentCameraHACK.resetView(); + gAgentCamera.resetView(); } // static @@ -883,8 +649,7 @@ void LLAgent::setRegion(LLViewerRegion *regionp) LLVector3 delta; delta.setVec(regionp->getOriginGlobal()); - setPositionAgent -(getPositionAgent() - delta); + setPositionAgent(getPositionAgent() - delta); LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin(); LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta); @@ -1034,19 +799,6 @@ void LLAgent::setPositionAgent(const LLVector3 &pos_agent) } } -/* -//----------------------------------------------------------------------------- -// slamLookAt() -//----------------------------------------------------------------------------- -void LLAgent::slamLookAt(const LLVector3 &look_at) -{ - LLVector3 look_at_norm = look_at; - look_at_norm.mV[VZ] = 0.f; - look_at_norm.normalize(); - resetAxes(look_at_norm); -} -*/ - //----------------------------------------------------------------------------- // getPositionGlobal() //----------------------------------------------------------------------------- @@ -1201,7 +953,7 @@ LLVector3 LLAgent::getReferenceUpVector() mAvatarObject->getParent() && mAvatarObject->mDrawable.notNull()) { - U32 camera_mode = gAgentCameraHACK.mCameraAnimating ? gAgentCameraHACK.mLastCameraMode : gAgentCameraHACK.mCameraMode; + U32 camera_mode = gAgentCamera.mCameraAnimating ? gAgentCamera.mLastCameraMode : gAgentCamera.mCameraMode; // and in third person... if (camera_mode == CAMERA_MODE_THIRD_PERSON) { @@ -1300,3290 +1052,959 @@ LLQuaternion LLAgent::getQuat() const return mFrameAgent.getQuaternion(); } -/* //----------------------------------------------------------------------------- -// calcFocusOffset() +// setKey() //----------------------------------------------------------------------------- -LLVector3 LLAgent::calcFocusOffset(LLViewerObject *object, LLVector3 original_focus_point, S32 x, S32 y) +void LLAgent::setKey(const S32 direction, S32 &key) { - LLMatrix4 obj_matrix = object->getRenderMatrix(); - LLQuaternion obj_rot = object->getRenderRotation(); - LLVector3 obj_pos = object->getRenderPosition(); - - BOOL is_avatar = object->isAvatar(); - // if is avatar - don't do any funk heuristics to position the focal point - // see DEV-30589 - if (is_avatar) + if (direction > 0) { - return original_focus_point - obj_pos; + key = 1; + } + else if (direction < 0) + { + key = -1; } - - - LLQuaternion inv_obj_rot = ~obj_rot; // get inverse of rotation - LLVector3 object_extents = object->getScale(); - // make sure they object extents are non-zero - object_extents.clamp(0.001f, F32_MAX); - - // obj_to_cam_ray is unit vector pointing from object center to camera, in the coordinate frame of the object - LLVector3 obj_to_cam_ray = obj_pos - LLViewerCamera::getInstance()->getOrigin(); - obj_to_cam_ray.rotVec(inv_obj_rot); - obj_to_cam_ray.normalize(); - - // obj_to_cam_ray_proportions are the (positive) ratios of - // the obj_to_cam_ray x,y,z components with the x,y,z object dimensions. - LLVector3 obj_to_cam_ray_proportions; - obj_to_cam_ray_proportions.mV[VX] = llabs(obj_to_cam_ray.mV[VX] / object_extents.mV[VX]); - obj_to_cam_ray_proportions.mV[VY] = llabs(obj_to_cam_ray.mV[VY] / object_extents.mV[VY]); - obj_to_cam_ray_proportions.mV[VZ] = llabs(obj_to_cam_ray.mV[VZ] / object_extents.mV[VZ]); - - // find the largest ratio stored in obj_to_cam_ray_proportions - // this corresponds to the object's local axial plane (XY, YZ, XZ) that is *most* facing the camera - LLVector3 longest_object_axis; - // is x-axis longest? - if (obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VY] - && obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VZ]) - { - // then grab it - longest_object_axis.setVec(obj_matrix.getFwdRow4()); - } - // is y-axis longest? - else if (obj_to_cam_ray_proportions.mV[VY] > obj_to_cam_ray_proportions.mV[VZ]) - { - // then grab it - longest_object_axis.setVec(obj_matrix.getLeftRow4()); - } - // otherwise, use z axis else { - longest_object_axis.setVec(obj_matrix.getUpRow4()); + key = 0; } +} - // Use this axis as the normal to project mouse click on to plane with that normal, at the object center. - // This generates a point behind the mouse cursor that is approximately in the middle of the object in - // terms of depth. - // We do this to allow the camera rotation tool to "tumble" the object by rotating the camera. - // If the focus point were the object surface under the mouse, camera rotation would introduce an undesirable - // eccentricity to the object orientation - LLVector3 focus_plane_normal(longest_object_axis); - focus_plane_normal.normalize(); - - LLVector3d focus_pt_global; - gViewerWindow->mousePointOnPlaneGlobal(focus_pt_global, x, y, gAgent.getPosGlobalFromAgent(obj_pos), focus_plane_normal); - LLVector3 focus_pt = gAgent.getPosAgentFromGlobal(focus_pt_global); - - // find vector from camera to focus point in object space - LLVector3 camera_to_focus_vec = focus_pt - LLViewerCamera::getInstance()->getOrigin(); - camera_to_focus_vec.rotVec(inv_obj_rot); - - // find vector from object origin to focus point in object coordinates - LLVector3 focus_offset_from_object_center = focus_pt - obj_pos; - // convert to object-local space - focus_offset_from_object_center.rotVec(inv_obj_rot); - - // We need to project the focus point back into the bounding box of the focused object. - // Do this by calculating the XYZ scale factors needed to get focus offset back in bounds along the camera_focus axis - LLVector3 clip_fraction; - // for each axis... - for (U32 axis = VX; axis <= VZ; axis++) +//----------------------------------------------------------------------------- +// getControlFlags() +//----------------------------------------------------------------------------- +U32 LLAgent::getControlFlags() +{ +/* + // HACK -- avoids maintenance of control flags when camera mode is turned on or off, + // only worries about it when the flags are measured + if (mCameraMode == CAMERA_MODE_MOUSELOOK) { - //...calculate distance that focus offset sits outside of bounding box along that axis... - //NOTE: dist_out_of_bounds keeps the sign of focus_offset_from_object_center - F32 dist_out_of_bounds; - if (focus_offset_from_object_center.mV[axis] > 0.f) - { - dist_out_of_bounds = llmax(0.f, focus_offset_from_object_center.mV[axis] - (object_extents.mV[axis] * 0.5f)); - } - else - { - dist_out_of_bounds = llmin(0.f, focus_offset_from_object_center.mV[axis] + (object_extents.mV[axis] * 0.5f)); - } - - //...then calculate the scale factor needed to push camera_to_focus_vec back in bounds along current axis - if (llabs(camera_to_focus_vec.mV[axis]) < 0.0001f) - { - // don't divide by very small number - clip_fraction.mV[axis] = 0.f; - } - else + if ( !(mControlFlags & AGENT_CONTROL_MOUSELOOK) ) { - clip_fraction.mV[axis] = dist_out_of_bounds / camera_to_focus_vec.mV[axis]; + mControlFlags |= AGENT_CONTROL_MOUSELOOK; } } +*/ + return mControlFlags; +} - LLVector3 abs_clip_fraction = clip_fraction; - abs_clip_fraction.abs(); - - // find axis of focus offset that is *most* outside the bounding box and use that to - // rescale focus offset to inside object extents - if (abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VY] - && abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VZ]) - { - focus_offset_from_object_center -= clip_fraction.mV[VX] * camera_to_focus_vec; - } - else if (abs_clip_fraction.mV[VY] > abs_clip_fraction.mV[VZ]) - { - focus_offset_from_object_center -= clip_fraction.mV[VY] * camera_to_focus_vec; - } - else - { - focus_offset_from_object_center -= clip_fraction.mV[VZ] * camera_to_focus_vec; - } - - // convert back to world space - focus_offset_from_object_center.rotVec(obj_rot); - - // now, based on distance of camera from object relative to object size - // push the focus point towards the near surface of the object when (relatively) close to the objcet - // or keep the focus point in the object middle when (relatively) far - // NOTE: leave focus point in middle of avatars, since the behavior you want when alt-zooming on avatars - // is almost always "tumble about middle" and not "spin around surface point" - if (!is_avatar) - { - LLVector3 obj_rel = original_focus_point - object->getRenderPosition(); - - //now that we have the object relative position, we should bias toward the center of the object - //based on the distance of the camera to the focus point vs. the distance of the camera to the focus - - F32 relDist = llabs(obj_rel * LLViewerCamera::getInstance()->getAtAxis()); - F32 viewDist = dist_vec(obj_pos + obj_rel, LLViewerCamera::getInstance()->getOrigin()); - - - LLBBox obj_bbox = object->getBoundingBoxAgent(); - F32 bias = 0.f; +//----------------------------------------------------------------------------- +// setControlFlags() +//----------------------------------------------------------------------------- +void LLAgent::setControlFlags(U32 mask) +{ + mControlFlags |= mask; + mbFlagsDirty = TRUE; +} - // virtual_camera_pos is the camera position we are simulating by backing the camera off - // and adjusting the FOV - LLVector3 virtual_camera_pos = gAgent.getPosAgentFromGlobal(mFocusTargetGlobal + (getCameraPositionGlobal() - mFocusTargetGlobal) / (1.f + mCameraFOVZoomFactor)); - // if the camera is inside the object (large, hollow objects, for example) - // leave focus point all the way to destination depth, away from object center - if(!obj_bbox.containsPointAgent(virtual_camera_pos)) - { - // perform magic number biasing of focus point towards surface vs. planar center - bias = clamp_rescale(relDist/viewDist, 0.1f, 0.7f, 0.0f, 1.0f); - obj_rel = lerp(focus_offset_from_object_center, obj_rel, bias); - } - - focus_offset_from_object_center = obj_rel; +//----------------------------------------------------------------------------- +// clearControlFlags() +//----------------------------------------------------------------------------- +void LLAgent::clearControlFlags(U32 mask) +{ + U32 old_flags = mControlFlags; + mControlFlags &= ~mask; + if (old_flags != mControlFlags) + { + mbFlagsDirty = TRUE; } +} - return focus_offset_from_object_center; +//----------------------------------------------------------------------------- +// controlFlagsDirty() +//----------------------------------------------------------------------------- +BOOL LLAgent::controlFlagsDirty() const +{ + return mbFlagsDirty; } //----------------------------------------------------------------------------- -// calcCameraMinDistance() +// enableControlFlagReset() //----------------------------------------------------------------------------- -BOOL LLAgent::calcCameraMinDistance(F32 &obj_min_distance) +void LLAgent::enableControlFlagReset() { - BOOL soft_limit = FALSE; // is the bounding box to be treated literally (volumes) or as an approximation (avatars) + mbFlagsNeedReset = TRUE; +} - if (!mFocusObject || mFocusObject->isDead()) +//----------------------------------------------------------------------------- +// resetControlFlags() +//----------------------------------------------------------------------------- +void LLAgent::resetControlFlags() +{ + if (mbFlagsNeedReset) { - obj_min_distance = 0.f; - return TRUE; + mbFlagsNeedReset = FALSE; + mbFlagsDirty = FALSE; + // reset all of the ephemeral flags + // some flags are managed elsewhere + mControlFlags &= AGENT_CONTROL_AWAY | AGENT_CONTROL_FLY | AGENT_CONTROL_MOUSELOOK; } +} - if (mFocusObject->mDrawable.isNull()) +//----------------------------------------------------------------------------- +// setAFK() +//----------------------------------------------------------------------------- +void LLAgent::setAFK() +{ + // Drones can't go AFK + if (gNoRender) { -#ifdef LL_RELEASE_FOR_DOWNLOAD - llwarns << "Focus object with no drawable!" << llendl; -#else - mFocusObject->dump(); - llerrs << "Focus object with no drawable!" << llendl; -#endif - obj_min_distance = 0.f; - return TRUE; + return; } - - LLQuaternion inv_object_rot = ~mFocusObject->getRenderRotation(); - LLVector3 target_offset_origin = mFocusObjectOffset; - LLVector3 camera_offset_target(getCameraPositionAgent() - getPosAgentFromGlobal(mFocusTargetGlobal)); - - // convert offsets into object local space - camera_offset_target.rotVec(inv_object_rot); - target_offset_origin.rotVec(inv_object_rot); - // push around object extents based on target offset - LLVector3 object_extents = mFocusObject->getScale(); - if (mFocusObject->isAvatar()) + if (!gAgent.getRegion()) { - // fudge factors that lets you zoom in on avatars a bit more (which don't do FOV zoom) - object_extents.mV[VX] *= AVATAR_ZOOM_MIN_X_FACTOR; - object_extents.mV[VY] *= AVATAR_ZOOM_MIN_Y_FACTOR; - object_extents.mV[VZ] *= AVATAR_ZOOM_MIN_Z_FACTOR; - soft_limit = TRUE; + // Don't set AFK if we're not talking to a region yet. + return; } - LLVector3 abs_target_offset = target_offset_origin; - abs_target_offset.abs(); - - LLVector3 target_offset_dir = target_offset_origin; - F32 object_radius = mFocusObject->getVObjRadius(); - BOOL target_outside_object_extents = FALSE; - - for (U32 i = VX; i <= VZ; i++) + if (!(mControlFlags & AGENT_CONTROL_AWAY)) { - if (abs_target_offset.mV[i] * 2.f > object_extents.mV[i] + OBJECT_EXTENTS_PADDING) - { - target_outside_object_extents = TRUE; - } - if (camera_offset_target.mV[i] > 0.f) - { - object_extents.mV[i] -= target_offset_origin.mV[i] * 2.f; - } - else + sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_START); + setControlFlags(AGENT_CONTROL_AWAY | AGENT_CONTROL_STOP); + gAwayTimer.start(); + if (gAFKMenu) { - object_extents.mV[i] += target_offset_origin.mV[i] * 2.f; + gAFKMenu->setLabel(LLTrans::getString("AvatarSetNotAway")); } } +} - // don't shrink the object extents so far that the object inverts - object_extents.clamp(0.001f, F32_MAX); - - // move into first octant - LLVector3 camera_offset_target_abs_norm = camera_offset_target; - camera_offset_target_abs_norm.abs(); - // make sure offset is non-zero - camera_offset_target_abs_norm.clamp(0.001f, F32_MAX); - camera_offset_target_abs_norm.normalize(); - - // find camera position relative to normalized object extents - LLVector3 camera_offset_target_scaled = camera_offset_target_abs_norm; - camera_offset_target_scaled.mV[VX] /= object_extents.mV[VX]; - camera_offset_target_scaled.mV[VY] /= object_extents.mV[VY]; - camera_offset_target_scaled.mV[VZ] /= object_extents.mV[VZ]; +//----------------------------------------------------------------------------- +// clearAFK() +//----------------------------------------------------------------------------- +void LLAgent::clearAFK() +{ + gAwayTriggerTimer.reset(); - if (camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VY] && - camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VZ]) - { - if (camera_offset_target_abs_norm.mV[VX] < 0.001f) - { - obj_min_distance = object_extents.mV[VX] * 0.5f; - } - else - { - obj_min_distance = object_extents.mV[VX] * 0.5f / camera_offset_target_abs_norm.mV[VX]; - } - } - else if (camera_offset_target_scaled.mV[VY] > camera_offset_target_scaled.mV[VZ]) + // Gods can sometimes get into away state (via gestures) + // without setting the appropriate control flag. JC + LLVOAvatar* av = mAvatarObject; + if (mControlFlags & AGENT_CONTROL_AWAY + || (av + && (av->mSignaledAnimations.find(ANIM_AGENT_AWAY) != av->mSignaledAnimations.end()))) { - if (camera_offset_target_abs_norm.mV[VY] < 0.001f) - { - obj_min_distance = object_extents.mV[VY] * 0.5f; - } - else + sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP); + clearControlFlags(AGENT_CONTROL_AWAY); + if (gAFKMenu) { - obj_min_distance = object_extents.mV[VY] * 0.5f / camera_offset_target_abs_norm.mV[VY]; - } - } - else - { - if (camera_offset_target_abs_norm.mV[VZ] < 0.001f) - { - obj_min_distance = object_extents.mV[VZ] * 0.5f; - } - else - { - obj_min_distance = object_extents.mV[VZ] * 0.5f / camera_offset_target_abs_norm.mV[VZ]; + gAFKMenu->setLabel(LLTrans::getString("AvatarSetAway")); } } +} - LLVector3 object_split_axis; - LLVector3 target_offset_scaled = target_offset_origin; - target_offset_scaled.abs(); - target_offset_scaled.normalize(); - target_offset_scaled.mV[VX] /= object_extents.mV[VX]; - target_offset_scaled.mV[VY] /= object_extents.mV[VY]; - target_offset_scaled.mV[VZ] /= object_extents.mV[VZ]; +//----------------------------------------------------------------------------- +// getAFK() +//----------------------------------------------------------------------------- +BOOL LLAgent::getAFK() const +{ + return (mControlFlags & AGENT_CONTROL_AWAY) != 0; +} - if (target_offset_scaled.mV[VX] > target_offset_scaled.mV[VY] && - target_offset_scaled.mV[VX] > target_offset_scaled.mV[VZ]) - { - object_split_axis = LLVector3::x_axis; - } - else if (target_offset_scaled.mV[VY] > target_offset_scaled.mV[VZ]) +//----------------------------------------------------------------------------- +// setBusy() +//----------------------------------------------------------------------------- +void LLAgent::setBusy() +{ + sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_START); + mIsBusy = TRUE; + if (gBusyMenu) { - object_split_axis = LLVector3::y_axis; + gBusyMenu->setLabel(LLTrans::getString("AvatarSetNotBusy")); } - else + LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(true); +} + +//----------------------------------------------------------------------------- +// clearBusy() +//----------------------------------------------------------------------------- +void LLAgent::clearBusy() +{ + mIsBusy = FALSE; + sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_STOP); + if (gBusyMenu) { - object_split_axis = LLVector3::z_axis; + gBusyMenu->setLabel(LLTrans::getString("AvatarSetBusy")); } + LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(false); +} - LLVector3 camera_offset_object(getCameraPositionAgent() - mFocusObject->getPositionAgent()); +//----------------------------------------------------------------------------- +// getBusy() +//----------------------------------------------------------------------------- +BOOL LLAgent::getBusy() const +{ + return mIsBusy; +} - // length projected orthogonal to target offset - F32 camera_offset_dist = (camera_offset_object - target_offset_dir * (camera_offset_object * target_offset_dir)).magVec(); - // calculate whether the target point would be "visible" if it were outside the bounding box - // on the opposite of the splitting plane defined by object_split_axis; - BOOL exterior_target_visible = FALSE; - if (camera_offset_dist > object_radius) +//----------------------------------------------------------------------------- +// startAutoPilotGlobal() +//----------------------------------------------------------------------------- +void LLAgent::startAutoPilotGlobal(const LLVector3d &target_global, const std::string& behavior_name, const LLQuaternion *target_rotation, void (*finish_callback)(BOOL, void *), void *callback_data, F32 stop_distance, F32 rot_threshold) +{ + if (!gAgent.getAvatarObject()) { - // target is visible from camera, so turn off fov zoom - exterior_target_visible = TRUE; + return; } + + mAutoPilotFinishedCallback = finish_callback; + mAutoPilotCallbackData = callback_data; + mAutoPilotRotationThreshold = rot_threshold; + mAutoPilotBehaviorName = behavior_name; - F32 camera_offset_clip = camera_offset_object * object_split_axis; - F32 target_offset_clip = target_offset_dir * object_split_axis; - - // target has moved outside of object extents - // check to see if camera and target are on same side - if (target_outside_object_extents) - { - if (camera_offset_clip > 0.f && target_offset_clip > 0.f) - { - return FALSE; - } - else if (camera_offset_clip < 0.f && target_offset_clip < 0.f) - { - return FALSE; - } - } + LLVector3d delta_pos( target_global ); + delta_pos -= getPositionGlobal(); + F64 distance = delta_pos.magVec(); + LLVector3d trace_target = target_global; - // clamp obj distance to diagonal of 10 by 10 cube - obj_min_distance = llmin(obj_min_distance, 10.f * F_SQRT3); + trace_target.mdV[VZ] -= 10.f; - obj_min_distance += LLViewerCamera::getInstance()->getNear() + (soft_limit ? 0.1f : 0.2f); - - return TRUE; -} + LLVector3d intersection; + LLVector3 normal; + LLViewerObject *hit_obj; + F32 heightDelta = LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, trace_target, intersection, normal, &hit_obj); -F32 LLAgent::getCameraZoomFraction() -{ - // 0.f -> camera zoomed all the way out - // 1.f -> camera zoomed all the way in - LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); - if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) - { - // already [0,1] - return mHUDTargetZoom; - } - else if (mFocusOnAvatar && cameraThirdPerson()) - { - return clamp_rescale(mCameraZoomFraction, MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION, 1.f, 0.f); - } - else if (cameraCustomizeAvatar()) + if (stop_distance > 0.f) { - F32 distance = (F32)mCameraFocusOffsetTarget.magVec(); - return clamp_rescale(distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM, 1.f, 0.f ); + mAutoPilotStopDistance = stop_distance; } else { - F32 min_zoom; - const F32 DIST_FUDGE = 16.f; // meters - F32 max_zoom = llmin(mDrawDistance - DIST_FUDGE, - LLWorld::getInstance()->getRegionWidthInMeters() - DIST_FUDGE, - MAX_CAMERA_DISTANCE_FROM_AGENT); - - F32 distance = (F32)mCameraFocusOffsetTarget.magVec(); - if (mFocusObject.notNull()) - { - if (mFocusObject->isAvatar()) - { - min_zoom = AVATAR_MIN_ZOOM; - } - else - { - min_zoom = OBJECT_MIN_ZOOM; - } - } - else + // Guess at a reasonable stop distance. + mAutoPilotStopDistance = fsqrtf( distance ); + if (mAutoPilotStopDistance < 0.5f) { - min_zoom = LAND_MIN_ZOOM; + mAutoPilotStopDistance = 0.5f; } - - return clamp_rescale(distance, min_zoom, max_zoom, 1.f, 0.f); } -} -void LLAgent::setCameraZoomFraction(F32 fraction) -{ - // 0.f -> camera zoomed all the way out - // 1.f -> camera zoomed all the way in - LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); + mAutoPilotFlyOnStop = getFlying(); - if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) - { - mHUDTargetZoom = fraction; - } - else if (mFocusOnAvatar && cameraThirdPerson()) + if (distance > 30.0) { - mCameraZoomFraction = rescale(fraction, 0.f, 1.f, MAX_ZOOM_FRACTION, MIN_ZOOM_FRACTION); + setFlying(TRUE); } - else if (cameraCustomizeAvatar()) + + if ( distance > 1.f && heightDelta > (sqrtf(mAutoPilotStopDistance) + 1.f)) { - LLVector3d camera_offset_dir = mCameraFocusOffsetTarget; - camera_offset_dir.normalize(); - mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, APPEARANCE_MAX_ZOOM, APPEARANCE_MIN_ZOOM); + setFlying(TRUE); + mAutoPilotFlyOnStop = TRUE; } - else - { - F32 min_zoom = LAND_MIN_ZOOM; - const F32 DIST_FUDGE = 16.f; // meters - F32 max_zoom = llmin(mDrawDistance - DIST_FUDGE, - LLWorld::getInstance()->getRegionWidthInMeters() - DIST_FUDGE, - MAX_CAMERA_DISTANCE_FROM_AGENT); - if (mFocusObject.notNull()) - { - if (mFocusObject.notNull()) - { - if (mFocusObject->isAvatar()) - { - min_zoom = AVATAR_MIN_ZOOM; - } - else - { - min_zoom = OBJECT_MIN_ZOOM; - } - } - } + mAutoPilot = TRUE; + mAutoPilotTargetGlobal = target_global; - LLVector3d camera_offset_dir = mCameraFocusOffsetTarget; - camera_offset_dir.normalize(); - mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, max_zoom, min_zoom); - } - startCameraAnimation(); -} + // trace ray down to find height of destination from ground + LLVector3d traceEndPt = target_global; + traceEndPt.mdV[VZ] -= 20.f; + + LLVector3d targetOnGround; + LLVector3 groundNorm; + LLViewerObject *obj; + LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, traceEndPt, targetOnGround, groundNorm, &obj); + F64 target_height = llmax((F64)gAgent.getAvatarObject()->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]); -//----------------------------------------------------------------------------- -// cameraOrbitAround() -//----------------------------------------------------------------------------- -void LLAgent::cameraOrbitAround(const F32 radians) -{ - LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); - if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) - { - // do nothing for hud selection - } - else if (mFocusOnAvatar && (mCameraMode == CAMERA_MODE_THIRD_PERSON || mCameraMode == CAMERA_MODE_FOLLOW)) + // clamp z value of target to minimum height above ground + mAutoPilotTargetGlobal.mdV[VZ] = targetOnGround.mdV[VZ] + target_height; + mAutoPilotTargetDist = (F32)dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal); + if (target_rotation) { - mFrameAgent.rotate(radians, getReferenceUpVector()); + mAutoPilotUseRotation = TRUE; + mAutoPilotTargetFacing = LLVector3::x_axis * *target_rotation; + mAutoPilotTargetFacing.mV[VZ] = 0.f; + mAutoPilotTargetFacing.normalize(); } else { - mCameraFocusOffsetTarget.rotVec(radians, 0.f, 0.f, 1.f); - - cameraZoomIn(1.f); + mAutoPilotUseRotation = FALSE; } + + mAutoPilotNoProgressFrameCount = 0; } //----------------------------------------------------------------------------- -// cameraOrbitOver() +// startFollowPilot() //----------------------------------------------------------------------------- -void LLAgent::cameraOrbitOver(const F32 angle) +void LLAgent::startFollowPilot(const LLUUID &leader_id) { - LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); - if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) - { - // do nothing for hud selection - } - else if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON) - { - pitch(angle); - } - else - { - LLVector3 camera_offset_unit(mCameraFocusOffsetTarget); - camera_offset_unit.normalize(); - - F32 angle_from_up = acos( camera_offset_unit * getReferenceUpVector() ); - - LLVector3d left_axis; - left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis()); - F32 new_angle = llclamp(angle_from_up - angle, 1.f * DEG_TO_RAD, 179.f * DEG_TO_RAD); - mCameraFocusOffsetTarget.rotVec(angle_from_up - new_angle, left_axis); - - cameraZoomIn(1.f); - } -} + if (!mAutoPilot) return; -//----------------------------------------------------------------------------- -// cameraZoomIn() -//----------------------------------------------------------------------------- -void LLAgent::cameraZoomIn(const F32 fraction) -{ - if (gDisconnected) - { - return; - } + mLeaderID = leader_id; + if ( mLeaderID.isNull() ) return; - LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); - if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) + LLViewerObject* object = gObjectList.findObject(mLeaderID); + if (!object) { - // just update hud zoom level - mHUDTargetZoom /= fraction; + mLeaderID = LLUUID::null; return; } + startAutoPilotGlobal(object->getPositionGlobal()); +} - LLVector3d camera_offset(mCameraFocusOffsetTarget); - LLVector3d camera_offset_unit(mCameraFocusOffsetTarget); - F32 min_zoom = LAND_MIN_ZOOM; - F32 current_distance = (F32)camera_offset_unit.normalize(); - F32 new_distance = current_distance * fraction; - // Don't move through focus point - if (mFocusObject) +//----------------------------------------------------------------------------- +// stopAutoPilot() +//----------------------------------------------------------------------------- +void LLAgent::stopAutoPilot(BOOL user_cancel) +{ + if (mAutoPilot) { - LLVector3 camera_offset_dir((F32)camera_offset_unit.mdV[VX], (F32)camera_offset_unit.mdV[VY], (F32)camera_offset_unit.mdV[VZ]); - - if (mFocusObject->isAvatar()) + mAutoPilot = FALSE; + if (mAutoPilotUseRotation && !user_cancel) { - calcCameraMinDistance(min_zoom); + resetAxes(mAutoPilotTargetFacing); } - else + //NB: auto pilot can terminate for a reason other than reaching the destination + if (mAutoPilotFinishedCallback) { - min_zoom = OBJECT_MIN_ZOOM; + mAutoPilotFinishedCallback(!user_cancel && dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData); } - } - - new_distance = llmax(new_distance, min_zoom); - - // Don't zoom too far back - const F32 DIST_FUDGE = 16.f; // meters - F32 max_distance = llmin(mDrawDistance - DIST_FUDGE, - LLWorld::getInstance()->getRegionWidthInMeters() - DIST_FUDGE ); - - if (new_distance > max_distance) - { - new_distance = max_distance; + mLeaderID = LLUUID::null; - // Unless camera is unlocked - //if (!LLViewerCamera::sDisableCameraConstraints) - //{ - // return; - //} - } + // If the user cancelled, don't change the fly state + if (!user_cancel) + { + setFlying(mAutoPilotFlyOnStop); + } + setControlFlags(AGENT_CONTROL_STOP); - if( cameraCustomizeAvatar() ) - { - new_distance = llclamp( new_distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM ); + if (user_cancel && !mAutoPilotBehaviorName.empty()) + { + if (mAutoPilotBehaviorName == "Sit") + LLNotificationsUtil::add("CancelledSit"); + else if (mAutoPilotBehaviorName == "Attach") + LLNotificationsUtil::add("CancelledAttach"); + else + LLNotificationsUtil::add("Cancelled"); + } } - - mCameraFocusOffsetTarget = new_distance * camera_offset_unit; } + +// Returns necessary agent pitch and yaw changes, radians. //----------------------------------------------------------------------------- -// cameraOrbitIn() +// autoPilot() //----------------------------------------------------------------------------- -void LLAgent::cameraOrbitIn(const F32 meters) +void LLAgent::autoPilot(F32 *delta_yaw) { - if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON) + if (mAutoPilot) { - F32 camera_offset_dist = llmax(0.001f, getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale")); - - mCameraZoomFraction = (mTargetCameraDistance - meters) / camera_offset_dist; - - if (!gSavedSettings.getBOOL("FreezeTime") && mCameraZoomFraction < MIN_ZOOM_FRACTION && meters > 0.f) + if (!mLeaderID.isNull()) { - // No need to animate, camera is already there. - changeCameraToMouselook(FALSE); + LLViewerObject* object = gObjectList.findObject(mLeaderID); + if (!object) + { + stopAutoPilot(); + return; + } + mAutoPilotTargetGlobal = object->getPositionGlobal(); } - - mCameraZoomFraction = llclamp(mCameraZoomFraction, MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION); - } - else - { - LLVector3d camera_offset(mCameraFocusOffsetTarget); - LLVector3d camera_offset_unit(mCameraFocusOffsetTarget); - F32 current_distance = (F32)camera_offset_unit.normalize(); - F32 new_distance = current_distance - meters; - F32 min_zoom = LAND_MIN_ZOOM; - // Don't move through focus point - if (mFocusObject.notNull()) + if (mAvatarObject.isNull()) { - if (mFocusObject->isAvatar()) - { - min_zoom = AVATAR_MIN_ZOOM; - } - else - { - min_zoom = OBJECT_MIN_ZOOM; - } + return; } - new_distance = llmax(new_distance, min_zoom); + if (mAvatarObject->mInAir) + { + setFlying(TRUE); + } + + LLVector3 at; + at.setVec(mFrameAgent.getAtAxis()); + LLVector3 target_agent = getPosAgentFromGlobal(mAutoPilotTargetGlobal); + LLVector3 direction = target_agent - getPositionAgent(); - // Don't zoom too far back - const F32 DIST_FUDGE = 16.f; // meters - F32 max_distance = llmin(mDrawDistance - DIST_FUDGE, - LLWorld::getInstance()->getRegionWidthInMeters() - DIST_FUDGE ); + F32 target_dist = direction.magVec(); - if (new_distance > max_distance) + if (target_dist >= mAutoPilotTargetDist) { - // Unless camera is unlocked - if (!gSavedSettings.getBOOL("DisableCameraConstraints")) + mAutoPilotNoProgressFrameCount++; + if (mAutoPilotNoProgressFrameCount > AUTOPILOT_MAX_TIME_NO_PROGRESS * gFPSClamped) { + stopAutoPilot(); return; } } - if( CAMERA_MODE_CUSTOMIZE_AVATAR == getCameraMode() ) - { - new_distance = llclamp( new_distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM ); - } - - // Compute new camera offset - mCameraFocusOffsetTarget = new_distance * camera_offset_unit; - cameraZoomIn(1.f); - } -} - - -//----------------------------------------------------------------------------- -// cameraPanIn() -//----------------------------------------------------------------------------- -void LLAgent::cameraPanIn(F32 meters) -{ - LLVector3d at_axis; - at_axis.setVec(LLViewerCamera::getInstance()->getAtAxis()); - - mFocusTargetGlobal += meters * at_axis; - mFocusGlobal = mFocusTargetGlobal; - // don't enforce zoom constraints as this is the only way for users to get past them easily - updateFocusOffset(); - // NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind -Nyx - mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal(); -} - -//----------------------------------------------------------------------------- -// cameraPanLeft() -//----------------------------------------------------------------------------- -void LLAgent::cameraPanLeft(F32 meters) -{ - LLVector3d left_axis; - left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis()); - - mFocusTargetGlobal += meters * left_axis; - mFocusGlobal = mFocusTargetGlobal; - - // disable smoothing for camera pan, which causes some residents unhappiness - mCameraSmoothingStop = TRUE; - - cameraZoomIn(1.f); - updateFocusOffset(); - // NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind - Nyx - mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal(); -} - -//----------------------------------------------------------------------------- -// cameraPanUp() -//----------------------------------------------------------------------------- -void LLAgent::cameraPanUp(F32 meters) -{ - LLVector3d up_axis; - up_axis.setVec(LLViewerCamera::getInstance()->getUpAxis()); - - mFocusTargetGlobal += meters * up_axis; - mFocusGlobal = mFocusTargetGlobal; - - // disable smoothing for camera pan, which causes some residents unhappiness - mCameraSmoothingStop = TRUE; - - cameraZoomIn(1.f); - updateFocusOffset(); - // NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind -Nyx - mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal(); -} -*/ - -//----------------------------------------------------------------------------- -// setKey() -//----------------------------------------------------------------------------- -void LLAgent::setKey(const S32 direction, S32 &key) -{ - if (direction > 0) - { - key = 1; - } - else if (direction < 0) - { - key = -1; - } - else - { - key = 0; - } -} - - -//----------------------------------------------------------------------------- -// getControlFlags() -//----------------------------------------------------------------------------- -U32 LLAgent::getControlFlags() -{ -/* - // HACK -- avoids maintenance of control flags when camera mode is turned on or off, - // only worries about it when the flags are measured - if (mCameraMode == CAMERA_MODE_MOUSELOOK) - { - if ( !(mControlFlags & AGENT_CONTROL_MOUSELOOK) ) - { - mControlFlags |= AGENT_CONTROL_MOUSELOOK; - } - } -*/ - return mControlFlags; -} - -//----------------------------------------------------------------------------- -// setControlFlags() -//----------------------------------------------------------------------------- -void LLAgent::setControlFlags(U32 mask) -{ - mControlFlags |= mask; - mbFlagsDirty = TRUE; -} - - -//----------------------------------------------------------------------------- -// clearControlFlags() -//----------------------------------------------------------------------------- -void LLAgent::clearControlFlags(U32 mask) -{ - U32 old_flags = mControlFlags; - mControlFlags &= ~mask; - if (old_flags != mControlFlags) - { - mbFlagsDirty = TRUE; - } -} - -//----------------------------------------------------------------------------- -// controlFlagsDirty() -//----------------------------------------------------------------------------- -BOOL LLAgent::controlFlagsDirty() const -{ - return mbFlagsDirty; -} - -//----------------------------------------------------------------------------- -// enableControlFlagReset() -//----------------------------------------------------------------------------- -void LLAgent::enableControlFlagReset() -{ - mbFlagsNeedReset = TRUE; -} - -//----------------------------------------------------------------------------- -// resetControlFlags() -//----------------------------------------------------------------------------- -void LLAgent::resetControlFlags() -{ - if (mbFlagsNeedReset) - { - mbFlagsNeedReset = FALSE; - mbFlagsDirty = FALSE; - // reset all of the ephemeral flags - // some flags are managed elsewhere - mControlFlags &= AGENT_CONTROL_AWAY | AGENT_CONTROL_FLY | AGENT_CONTROL_MOUSELOOK; - } -} - -//----------------------------------------------------------------------------- -// setAFK() -//----------------------------------------------------------------------------- -void LLAgent::setAFK() -{ - // Drones can't go AFK - if (gNoRender) - { - return; - } - - if (!gAgent.getRegion()) - { - // Don't set AFK if we're not talking to a region yet. - return; - } - - if (!(mControlFlags & AGENT_CONTROL_AWAY)) - { - sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_START); - setControlFlags(AGENT_CONTROL_AWAY | AGENT_CONTROL_STOP); - gAwayTimer.start(); - if (gAFKMenu) - { - gAFKMenu->setLabel(LLTrans::getString("AvatarSetNotAway")); - } - } -} - -//----------------------------------------------------------------------------- -// clearAFK() -//----------------------------------------------------------------------------- -void LLAgent::clearAFK() -{ - gAwayTriggerTimer.reset(); - - // Gods can sometimes get into away state (via gestures) - // without setting the appropriate control flag. JC - LLVOAvatar* av = mAvatarObject; - if (mControlFlags & AGENT_CONTROL_AWAY - || (av - && (av->mSignaledAnimations.find(ANIM_AGENT_AWAY) != av->mSignaledAnimations.end()))) - { - sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP); - clearControlFlags(AGENT_CONTROL_AWAY); - if (gAFKMenu) - { - gAFKMenu->setLabel(LLTrans::getString("AvatarSetAway")); - } - } -} - -//----------------------------------------------------------------------------- -// getAFK() -//----------------------------------------------------------------------------- -BOOL LLAgent::getAFK() const -{ - return (mControlFlags & AGENT_CONTROL_AWAY) != 0; -} - -//----------------------------------------------------------------------------- -// setBusy() -//----------------------------------------------------------------------------- -void LLAgent::setBusy() -{ - sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_START); - mIsBusy = TRUE; - if (gBusyMenu) - { - gBusyMenu->setLabel(LLTrans::getString("AvatarSetNotBusy")); - } - LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(true); -} - -//----------------------------------------------------------------------------- -// clearBusy() -//----------------------------------------------------------------------------- -void LLAgent::clearBusy() -{ - mIsBusy = FALSE; - sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_STOP); - if (gBusyMenu) - { - gBusyMenu->setLabel(LLTrans::getString("AvatarSetBusy")); - } - LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(false); -} - -//----------------------------------------------------------------------------- -// getBusy() -//----------------------------------------------------------------------------- -BOOL LLAgent::getBusy() const -{ - return mIsBusy; -} - - -//----------------------------------------------------------------------------- -// startAutoPilotGlobal() -//----------------------------------------------------------------------------- -void LLAgent::startAutoPilotGlobal(const LLVector3d &target_global, const std::string& behavior_name, const LLQuaternion *target_rotation, void (*finish_callback)(BOOL, void *), void *callback_data, F32 stop_distance, F32 rot_threshold) -{ - if (!gAgent.getAvatarObject()) - { - return; - } - - mAutoPilotFinishedCallback = finish_callback; - mAutoPilotCallbackData = callback_data; - mAutoPilotRotationThreshold = rot_threshold; - mAutoPilotBehaviorName = behavior_name; - - LLVector3d delta_pos( target_global ); - delta_pos -= getPositionGlobal(); - F64 distance = delta_pos.magVec(); - LLVector3d trace_target = target_global; - - trace_target.mdV[VZ] -= 10.f; - - LLVector3d intersection; - LLVector3 normal; - LLViewerObject *hit_obj; - F32 heightDelta = LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, trace_target, intersection, normal, &hit_obj); - - if (stop_distance > 0.f) - { - mAutoPilotStopDistance = stop_distance; - } - else - { - // Guess at a reasonable stop distance. - mAutoPilotStopDistance = fsqrtf( distance ); - if (mAutoPilotStopDistance < 0.5f) - { - mAutoPilotStopDistance = 0.5f; - } - } - - mAutoPilotFlyOnStop = getFlying(); - - if (distance > 30.0) - { - setFlying(TRUE); - } - - if ( distance > 1.f && heightDelta > (sqrtf(mAutoPilotStopDistance) + 1.f)) - { - setFlying(TRUE); - mAutoPilotFlyOnStop = TRUE; - } - - mAutoPilot = TRUE; - mAutoPilotTargetGlobal = target_global; - - // trace ray down to find height of destination from ground - LLVector3d traceEndPt = target_global; - traceEndPt.mdV[VZ] -= 20.f; - - LLVector3d targetOnGround; - LLVector3 groundNorm; - LLViewerObject *obj; - - LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, traceEndPt, targetOnGround, groundNorm, &obj); - F64 target_height = llmax((F64)gAgent.getAvatarObject()->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]); - - // clamp z value of target to minimum height above ground - mAutoPilotTargetGlobal.mdV[VZ] = targetOnGround.mdV[VZ] + target_height; - mAutoPilotTargetDist = (F32)dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal); - if (target_rotation) - { - mAutoPilotUseRotation = TRUE; - mAutoPilotTargetFacing = LLVector3::x_axis * *target_rotation; - mAutoPilotTargetFacing.mV[VZ] = 0.f; - mAutoPilotTargetFacing.normalize(); - } - else - { - mAutoPilotUseRotation = FALSE; - } - - mAutoPilotNoProgressFrameCount = 0; -} - - -//----------------------------------------------------------------------------- -// startFollowPilot() -//----------------------------------------------------------------------------- -void LLAgent::startFollowPilot(const LLUUID &leader_id) -{ - if (!mAutoPilot) return; - - mLeaderID = leader_id; - if ( mLeaderID.isNull() ) return; - - LLViewerObject* object = gObjectList.findObject(mLeaderID); - if (!object) - { - mLeaderID = LLUUID::null; - return; - } - - startAutoPilotGlobal(object->getPositionGlobal()); -} - - -//----------------------------------------------------------------------------- -// stopAutoPilot() -//----------------------------------------------------------------------------- -void LLAgent::stopAutoPilot(BOOL user_cancel) -{ - if (mAutoPilot) - { - mAutoPilot = FALSE; - if (mAutoPilotUseRotation && !user_cancel) - { - resetAxes(mAutoPilotTargetFacing); - } - //NB: auto pilot can terminate for a reason other than reaching the destination - if (mAutoPilotFinishedCallback) - { - mAutoPilotFinishedCallback(!user_cancel && dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData); - } - mLeaderID = LLUUID::null; - - // If the user cancelled, don't change the fly state - if (!user_cancel) - { - setFlying(mAutoPilotFlyOnStop); - } - setControlFlags(AGENT_CONTROL_STOP); - - if (user_cancel && !mAutoPilotBehaviorName.empty()) - { - if (mAutoPilotBehaviorName == "Sit") - LLNotificationsUtil::add("CancelledSit"); - else if (mAutoPilotBehaviorName == "Attach") - LLNotificationsUtil::add("CancelledAttach"); - else - LLNotificationsUtil::add("Cancelled"); - } - } -} - - -// Returns necessary agent pitch and yaw changes, radians. -//----------------------------------------------------------------------------- -// autoPilot() -//----------------------------------------------------------------------------- -void LLAgent::autoPilot(F32 *delta_yaw) -{ - if (mAutoPilot) - { - if (!mLeaderID.isNull()) - { - LLViewerObject* object = gObjectList.findObject(mLeaderID); - if (!object) - { - stopAutoPilot(); - return; - } - mAutoPilotTargetGlobal = object->getPositionGlobal(); - } - - if (mAvatarObject.isNull()) - { - return; - } - - if (mAvatarObject->mInAir) - { - setFlying(TRUE); - } - - LLVector3 at; - at.setVec(mFrameAgent.getAtAxis()); - LLVector3 target_agent = getPosAgentFromGlobal(mAutoPilotTargetGlobal); - LLVector3 direction = target_agent - getPositionAgent(); - - F32 target_dist = direction.magVec(); - - if (target_dist >= mAutoPilotTargetDist) - { - mAutoPilotNoProgressFrameCount++; - if (mAutoPilotNoProgressFrameCount > AUTOPILOT_MAX_TIME_NO_PROGRESS * gFPSClamped) - { - stopAutoPilot(); - return; - } - } - - mAutoPilotTargetDist = target_dist; - - // Make this a two-dimensional solution - at.mV[VZ] = 0.f; - direction.mV[VZ] = 0.f; - - at.normalize(); - F32 xy_distance = direction.normalize(); - - F32 yaw = 0.f; - if (mAutoPilotTargetDist > mAutoPilotStopDistance) - { - yaw = angle_between(mFrameAgent.getAtAxis(), direction); - } - else if (mAutoPilotUseRotation) - { - // we're close now just aim at target facing - yaw = angle_between(at, mAutoPilotTargetFacing); - direction = mAutoPilotTargetFacing; - } - - yaw = 4.f * yaw / gFPSClamped; - - // figure out which direction to turn - LLVector3 scratch(at % direction); - - if (scratch.mV[VZ] > 0.f) - { - setControlFlags(AGENT_CONTROL_YAW_POS); - } - else - { - yaw = -yaw; - setControlFlags(AGENT_CONTROL_YAW_NEG); - } - - *delta_yaw = yaw; - - // Compute when to start slowing down and when to stop - F32 stop_distance = mAutoPilotStopDistance; - F32 slow_distance; - if (getFlying()) - { - slow_distance = llmax(6.f, mAutoPilotStopDistance + 5.f); - stop_distance = llmax(2.f, mAutoPilotStopDistance); - } - else - { - slow_distance = llmax(3.f, mAutoPilotStopDistance + 2.f); - } - - // If we're flying, handle autopilot points above or below you. - if (getFlying() && xy_distance < AUTOPILOT_HEIGHT_ADJUST_DISTANCE) - { - if (mAvatarObject.notNull()) - { - F64 current_height = mAvatarObject->getPositionGlobal().mdV[VZ]; - F32 delta_z = (F32)(mAutoPilotTargetGlobal.mdV[VZ] - current_height); - F32 slope = delta_z / xy_distance; - if (slope > 0.45f && delta_z > 6.f) - { - setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_POS); - } - else if (slope > 0.002f && delta_z > 0.5f) - { - setControlFlags(AGENT_CONTROL_UP_POS); - } - else if (slope < -0.45f && delta_z < -6.f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND) - { - setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_NEG); - } - else if (slope < -0.002f && delta_z < -0.5f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND) - { - setControlFlags(AGENT_CONTROL_UP_NEG); - } - } - } - - // calculate delta rotation to target heading - F32 delta_target_heading = angle_between(mFrameAgent.getAtAxis(), mAutoPilotTargetFacing); - - if (xy_distance > slow_distance && yaw < (F_PI / 10.f)) - { - // walking/flying fast - setControlFlags(AGENT_CONTROL_FAST_AT | AGENT_CONTROL_AT_POS); - } - else if (mAutoPilotTargetDist > mAutoPilotStopDistance) - { - // walking/flying slow - if (at * direction > 0.9f) - { - setControlFlags(AGENT_CONTROL_AT_POS); - } - else if (at * direction < -0.9f) - { - setControlFlags(AGENT_CONTROL_AT_NEG); - } - } - - // check to see if we need to keep rotating to target orientation - if (mAutoPilotTargetDist < mAutoPilotStopDistance) - { - setControlFlags(AGENT_CONTROL_STOP); - if(!mAutoPilotUseRotation || (delta_target_heading < mAutoPilotRotationThreshold)) - { - stopAutoPilot(); - } - } - } -} - - -//----------------------------------------------------------------------------- -// propagate() -//----------------------------------------------------------------------------- -void LLAgent::propagate(const F32 dt) -{ - // Update UI based on agent motion - LLFloaterMove *floater_move = LLFloaterReg::findTypedInstance("moveview"); - if (floater_move) - { - floater_move->mForwardButton ->setToggleState( mAtKey > 0 || mWalkKey > 0 ); - floater_move->mBackwardButton ->setToggleState( mAtKey < 0 || mWalkKey < 0 ); - floater_move->mTurnLeftButton ->setToggleState( mYawKey > 0.f ); - floater_move->mTurnRightButton ->setToggleState( mYawKey < 0.f ); - floater_move->mMoveUpButton ->setToggleState( mUpKey > 0 ); - floater_move->mMoveDownButton ->setToggleState( mUpKey < 0 ); - } - - // handle rotation based on keyboard levels - const F32 YAW_RATE = 90.f * DEG_TO_RAD; // radians per second - yaw(YAW_RATE * mYawKey * dt); - - const F32 PITCH_RATE = 90.f * DEG_TO_RAD; // radians per second - pitch(PITCH_RATE * mPitchKey * dt); - - // handle auto-land behavior - if (mAvatarObject.notNull()) - { - BOOL in_air = mAvatarObject->mInAir; - LLVector3 land_vel = getVelocity(); - land_vel.mV[VZ] = 0.f; - - if (!in_air - && mUpKey < 0 - && land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED - && gSavedSettings.getBOOL("AutomaticFly")) - { - // land automatically - setFlying(FALSE); - } - } - - // clear keys - mAtKey = 0; - mWalkKey = 0; - mLeftKey = 0; - mUpKey = 0; - mYawKey = 0.f; - mPitchKey = 0.f; -} - -//----------------------------------------------------------------------------- -// updateAgentPosition() -//----------------------------------------------------------------------------- -void LLAgent::updateAgentPosition(const F32 dt, const F32 yaw_radians, const S32 mouse_x, const S32 mouse_y) -{ - propagate(dt); - - // static S32 cameraUpdateCount = 0; - - rotate(yaw_radians, 0, 0, 1); - - // - // Check for water and land collision, set underwater flag - // - - gAgentCameraHACK.updateLookAt(mouse_x, mouse_y); -} - -/* -//----------------------------------------------------------------------------- -// updateLookAt() -//----------------------------------------------------------------------------- -void LLAgent::updateLookAt(const S32 mouse_x, const S32 mouse_y) -{ - static LLVector3 last_at_axis; - - - if (mAvatarObject.isNull()) - { - return; - } - - LLQuaternion av_inv_rot = ~mAvatarObject->mRoot.getWorldRotation(); - LLVector3 root_at = LLVector3::x_axis * mAvatarObject->mRoot.getWorldRotation(); - - if ((gViewerWindow->getMouseVelocityStat()->getCurrent() < 0.01f) && - (root_at * last_at_axis > 0.95f )) - { - LLVector3 vel = mAvatarObject->getVelocity(); - if (vel.magVecSquared() > 4.f) - { - setLookAt(LOOKAT_TARGET_IDLE, mAvatarObject, vel * av_inv_rot); - } - else - { - // *FIX: rotate mframeagent by sit object's rotation? - LLQuaternion look_rotation = mAvatarObject->isSitting() ? mAvatarObject->getRenderRotation() : mFrameAgent.getQuaternion(); // use camera's current rotation - LLVector3 look_offset = LLVector3(2.f, 0.f, 0.f) * look_rotation * av_inv_rot; - setLookAt(LOOKAT_TARGET_IDLE, mAvatarObject, look_offset); - } - last_at_axis = root_at; - return; - } - - last_at_axis = root_at; - - if (CAMERA_MODE_CUSTOMIZE_AVATAR == getCameraMode()) - { - setLookAt(LOOKAT_TARGET_NONE, mAvatarObject, LLVector3(-2.f, 0.f, 0.f)); - } - else - { - // Move head based on cursor position - ELookAtType lookAtType = LOOKAT_TARGET_NONE; - LLVector3 headLookAxis; - LLCoordFrame frameCamera = *((LLCoordFrame*)LLViewerCamera::getInstance()); - - if (cameraMouselook()) - { - lookAtType = LOOKAT_TARGET_MOUSELOOK; - } - else if (cameraThirdPerson()) - { - // range from -.5 to .5 - F32 x_from_center = - ((F32) mouse_x / (F32) gViewerWindow->getWindowWidthScaled() ) - 0.5f; - F32 y_from_center = - ((F32) mouse_y / (F32) gViewerWindow->getWindowHeightScaled() ) - 0.5f; - - frameCamera.yaw( - x_from_center * gSavedSettings.getF32("YawFromMousePosition") * DEG_TO_RAD); - frameCamera.pitch( - y_from_center * gSavedSettings.getF32("PitchFromMousePosition") * DEG_TO_RAD); - lookAtType = LOOKAT_TARGET_FREELOOK; - } - - headLookAxis = frameCamera.getAtAxis(); - // RN: we use world-space offset for mouselook and freelook - //headLookAxis = headLookAxis * av_inv_rot; - setLookAt(lookAtType, mAvatarObject, headLookAxis); - } -} -*/ - -// friends and operators - -std::ostream& operator<<(std::ostream &s, const LLAgent &agent) -{ - // This is unfinished, but might never be used. - // We'll just leave it for now; we can always delete it. - s << " { " - << " Frame = " << agent.mFrameAgent << "\n" - << " }"; - return s; -} - - -// ------------------- Beginning of legacy LLCamera hack ---------------------- -// This section is included for legacy LLCamera support until -// it is no longer needed. Some legacy code must exist in -// non-legacy functions, and is labeled with "// legacy" comments. - -//----------------------------------------------------------------------------- -// setAvatarObject() -//----------------------------------------------------------------------------- -void LLAgent::setAvatarObject(LLVOAvatarSelf *avatar) -{ - mAvatarObject = avatar; - - if (!avatar) - { - llinfos << "Setting LLAgent::mAvatarObject to NULL" << llendl; - return; - } - - if (!gAgentCameraHACK.mLookAt) - { - gAgentCameraHACK.mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT); - } - if (!gAgentCameraHACK.mPointAt) - { - gAgentCameraHACK.mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT); - } - - if (!gAgentCameraHACK.mLookAt.isNull()) - { - gAgentCameraHACK.mLookAt->setSourceObject(avatar); - } - if (!gAgentCameraHACK.mPointAt.isNull()) - { - gAgentCameraHACK.mPointAt->setSourceObject(avatar); - } -} - -// TRUE if your own avatar needs to be rendered. Usually only -// in third person and build. -//----------------------------------------------------------------------------- -// needsRenderAvatar() -//----------------------------------------------------------------------------- -BOOL LLAgent::needsRenderAvatar() -{ - if (gAgentCameraHACK.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson) - { - return FALSE; - } - - return mShowAvatar && mGenderChosen; -} - -// TRUE if we need to render your own avatar's head. -BOOL LLAgent::needsRenderHead() -{ - return (LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCameraHACK.cameraMouselook()); -} - -//----------------------------------------------------------------------------- -// startTyping() -//----------------------------------------------------------------------------- -void LLAgent::startTyping() -{ - mTypingTimer.reset(); - - if (getRenderState() & AGENT_STATE_TYPING) - { - // already typing, don't trigger a different animation - return; - } - setRenderState(AGENT_STATE_TYPING); - - if (mChatTimer.getElapsedTimeF32() < 2.f) - { - LLViewerObject* chatter = gObjectList.findObject(mLastChatterID); - if (chatter && chatter->isAvatar()) - { - gAgentCameraHACK.setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero); - } - } - - if (gSavedSettings.getBOOL("PlayTypingAnim")) - { - sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_START); - } - LLNearbyChatBar::getInstance()->sendChatFromViewer("", CHAT_TYPE_START, FALSE); -} - -//----------------------------------------------------------------------------- -// stopTyping() -//----------------------------------------------------------------------------- -void LLAgent::stopTyping() -{ - if (mRenderState & AGENT_STATE_TYPING) - { - clearRenderState(AGENT_STATE_TYPING); - sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_STOP); - LLNearbyChatBar::getInstance()->sendChatFromViewer("", CHAT_TYPE_STOP, FALSE); - } -} - -//----------------------------------------------------------------------------- -// setRenderState() -//----------------------------------------------------------------------------- -void LLAgent::setRenderState(U8 newstate) -{ - mRenderState |= newstate; -} - -//----------------------------------------------------------------------------- -// clearRenderState() -//----------------------------------------------------------------------------- -void LLAgent::clearRenderState(U8 clearstate) -{ - mRenderState &= ~clearstate; -} - - -//----------------------------------------------------------------------------- -// getRenderState() -//----------------------------------------------------------------------------- -U8 LLAgent::getRenderState() -{ - if (gNoRender || gKeyboard == NULL) - { - return 0; - } - - // *FIX: don't do stuff in a getter! This is infinite loop city! - if ((mTypingTimer.getElapsedTimeF32() > TYPING_TIMEOUT_SECS) - && (mRenderState & AGENT_STATE_TYPING)) - { - stopTyping(); - } - - if ((!LLSelectMgr::getInstance()->getSelection()->isEmpty() && LLSelectMgr::getInstance()->shouldShowSelection()) - || LLToolMgr::getInstance()->getCurrentTool()->isEditing() ) - { - setRenderState(AGENT_STATE_EDITING); - } - else - { - clearRenderState(AGENT_STATE_EDITING); - } - - return mRenderState; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// endAnimationUpdateUI() -//----------------------------------------------------------------------------- -void LLAgent::endAnimationUpdateUI() -{ - if (gAgentCameraHACK.mCameraMode == gAgentCameraHACK.mLastCameraMode) - { - // We're already done endAnimationUpdateUI for this transition. - return; - } - - // clean up UI from mode we're leaving - if (gAgentCameraHACK.mLastCameraMode == CAMERA_MODE_MOUSELOOK ) - { - // show mouse cursor - gViewerWindow->showCursor(); - // show menus - gMenuBarView->setVisible(TRUE); - LLNavigationBar::getInstance()->setVisible(TRUE); - gStatusBar->setVisibleForMouselook(true); - - LLBottomTray::getInstance()->onMouselookModeOut(); - - LLSideTray::getInstance()->getButtonsPanel()->setVisible(TRUE); - LLSideTray::getInstance()->updateSidetrayVisibility(); - - LLPanelStandStopFlying::getInstance()->setVisible(TRUE); - - LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); - - LLFloaterCamera::onLeavingMouseLook(); - - // Only pop if we have pushed... - if (TRUE == mViewsPushed) - { -#if 0 // Use this once all floaters are registered - LLFloaterReg::restoreVisibleInstances(); -#else // Use this for now - LLFloaterView::skip_list_t skip_list; - if (LLFloaterReg::findInstance("mini_map")) - { - skip_list.insert(LLFloaterReg::findInstance("mini_map")); - } - - gFloaterView->popVisibleAll(skip_list); -#endif - mViewsPushed = FALSE; - } - - - gAgentCameraHACK.setLookAt(LOOKAT_TARGET_CLEAR); - if( gMorphView ) - { - gMorphView->setVisible( FALSE ); - } - - // Disable mouselook-specific animations - if (mAvatarObject.notNull()) - { - if( mAvatarObject->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) ) - { - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_START); - } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_START); - } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_START); - } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_START); - } - } - } - } - else - if(gAgentCameraHACK.mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) - { - // make sure we ask to save changes - - LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); - - if( gMorphView ) - { - gMorphView->setVisible( FALSE ); - } - - if (mAvatarObject.notNull()) - { - if(mCustomAnim) - { - sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_CUSTOMIZE_DONE, ANIM_REQUEST_START); - - mCustomAnim = FALSE ; - } - - } - gAgentCameraHACK.setLookAt(LOOKAT_TARGET_CLEAR); - } - - //--------------------------------------------------------------------- - // Set up UI for mode we're entering - //--------------------------------------------------------------------- - if (gAgentCameraHACK.mCameraMode == CAMERA_MODE_MOUSELOOK) - { - // hide menus - gMenuBarView->setVisible(FALSE); - LLNavigationBar::getInstance()->setVisible(FALSE); - gStatusBar->setVisibleForMouselook(false); - - LLBottomTray::getInstance()->onMouselookModeIn(); - - LLSideTray::getInstance()->getButtonsPanel()->setVisible(FALSE); - LLSideTray::getInstance()->updateSidetrayVisibility(); - - LLPanelStandStopFlying::getInstance()->setVisible(FALSE); - - // clear out camera lag effect - gAgentCameraHACK.mCameraLag.clearVec(); - - // JC - Added for always chat in third person option - gFocusMgr.setKeyboardFocus(NULL); - - LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset); - - mViewsPushed = TRUE; - - // hide all floaters except the mini map - -#if 0 // Use this once all floaters are registered - std::set exceptions; - exceptions.insert("mini_map"); - LLFloaterReg::hideVisibleInstances(exceptions); -#else // Use this for now - LLFloaterView::skip_list_t skip_list; - skip_list.insert(LLFloaterReg::findInstance("mini_map")); - gFloaterView->pushVisibleAll(FALSE, skip_list); -#endif - - if( gMorphView ) - { - gMorphView->setVisible(FALSE); - } - - gConsole->setVisible( TRUE ); - - if (mAvatarObject.notNull()) - { - // Trigger mouselook-specific animations - if( mAvatarObject->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) ) - { - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_START); - } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_START); - } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_START); - } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != mAvatarObject->mSignaledAnimations.end()) - { - sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_STOP); - sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_START); - } - } - if (mAvatarObject->getParent()) - { - LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis(); - LLViewerObject* root_object = (LLViewerObject*)mAvatarObject->getRoot(); - if (root_object->flagCameraDecoupled()) - { - resetAxes(at_axis); - } - else - { - resetAxes(at_axis * ~((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation()); - } - } - } - - } - else if (gAgentCameraHACK.mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) - { - LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset); - - if( gMorphView ) - { - gMorphView->setVisible( TRUE ); - } - - // freeze avatar - if (mAvatarObject.notNull()) - { - mPauseRequest = mAvatarObject->requestPause(); - } - } - - if (getAvatarObject()) - { - getAvatarObject()->updateAttachmentVisibility(gAgentCameraHACK.mCameraMode); - } - - gFloaterTools->dirty(); - - // Don't let this be called more than once if the camera - // mode hasn't changed. --JC - gAgentCameraHACK.mLastCameraMode = gAgentCameraHACK.mCameraMode; - -} - -/* -//----------------------------------------------------------------------------- -// updateCamera() -//----------------------------------------------------------------------------- -void LLAgent::updateCamera() -{ - static LLFastTimer::DeclareTimer ftm("Camera"); - LLFastTimer t(ftm); - - //Ventrella - changed camera_skyward to the new global "mCameraUpVector" - mCameraUpVector = LLVector3::z_axis; - //LLVector3 camera_skyward(0.f, 0.f, 1.f); - //end Ventrella - - U32 camera_mode = mCameraAnimating ? mLastCameraMode : mCameraMode; - - validateFocusObject(); - - if (mAvatarObject.notNull() && - mAvatarObject->isSitting() && - camera_mode == CAMERA_MODE_MOUSELOOK) - { - //Ventrella - //changed camera_skyward to the new global "mCameraUpVector" - mCameraUpVector = mCameraUpVector * mAvatarObject->getRenderRotation(); - //end Ventrella - } - - if (cameraThirdPerson() && mFocusOnAvatar && LLFollowCamMgr::getActiveFollowCamParams()) - { - changeCameraToFollow(); - } - - //Ventrella - //NOTE - this needs to be integrated into a general upVector system here within llAgent. - if ( camera_mode == CAMERA_MODE_FOLLOW && mFocusOnAvatar ) - { - mCameraUpVector = mFollowCam.getUpVector(); - } - //end Ventrella - - if (mSitCameraEnabled) - { - if (mSitCameraReferenceObject->isDead()) - { - setSitCamera(LLUUID::null); - } - } - - // Update UI with our camera inputs - LLFloaterCamera* camera_floater = LLFloaterReg::findTypedInstance("camera"); - if (camera_floater) - { - camera_floater->mRotate->setToggleState( - mOrbitRightKey > 0.f, // left - mOrbitUpKey > 0.f, // top - mOrbitLeftKey > 0.f, // right - mOrbitDownKey > 0.f); // bottom - - camera_floater->mTrack->setToggleState( - mPanLeftKey > 0.f, // left - mPanUpKey > 0.f, // top - mPanRightKey > 0.f, // right - mPanDownKey > 0.f); // bottom - } - - // Handle camera movement based on keyboard. - const F32 ORBIT_OVER_RATE = 90.f * DEG_TO_RAD; // radians per second - const F32 ORBIT_AROUND_RATE = 90.f * DEG_TO_RAD; // radians per second - const F32 PAN_RATE = 5.f; // meters per second - - if( mOrbitUpKey || mOrbitDownKey ) - { - F32 input_rate = mOrbitUpKey - mOrbitDownKey; - cameraOrbitOver( input_rate * ORBIT_OVER_RATE / gFPSClamped ); - } - - if( mOrbitLeftKey || mOrbitRightKey) - { - F32 input_rate = mOrbitLeftKey - mOrbitRightKey; - cameraOrbitAround( input_rate * ORBIT_AROUND_RATE / gFPSClamped ); - } - - if( mOrbitInKey || mOrbitOutKey ) - { - F32 input_rate = mOrbitInKey - mOrbitOutKey; - - LLVector3d to_focus = gAgent.getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin()) - calcFocusPositionTargetGlobal(); - F32 distance_to_focus = (F32)to_focus.magVec(); - // Move at distance (in meters) meters per second - cameraOrbitIn( input_rate * distance_to_focus / gFPSClamped ); - } - - if( mPanInKey || mPanOutKey ) - { - F32 input_rate = mPanInKey - mPanOutKey; - cameraPanIn( input_rate * PAN_RATE / gFPSClamped ); - } - - if( mPanRightKey || mPanLeftKey ) - { - F32 input_rate = mPanRightKey - mPanLeftKey; - cameraPanLeft( input_rate * -PAN_RATE / gFPSClamped ); - } - - if( mPanUpKey || mPanDownKey ) - { - F32 input_rate = mPanUpKey - mPanDownKey; - cameraPanUp( input_rate * PAN_RATE / gFPSClamped ); - } - - // Clear camera keyboard keys. - mOrbitLeftKey = 0.f; - mOrbitRightKey = 0.f; - mOrbitUpKey = 0.f; - mOrbitDownKey = 0.f; - mOrbitInKey = 0.f; - mOrbitOutKey = 0.f; - - mPanRightKey = 0.f; - mPanLeftKey = 0.f; - mPanUpKey = 0.f; - mPanDownKey = 0.f; - mPanInKey = 0.f; - mPanOutKey = 0.f; - - // lerp camera focus offset - mCameraFocusOffset = lerp(mCameraFocusOffset, mCameraFocusOffsetTarget, LLCriticalDamp::getInterpolant(CAMERA_FOCUS_HALF_LIFE)); - - //Ventrella - if ( mCameraMode == CAMERA_MODE_FOLLOW ) - { - if ( mAvatarObject.notNull() ) - { - //-------------------------------------------------------------------------------- - // this is where the avatar's position and rotation are given to followCam, and - // where it is updated. All three of its attributes are updated: (1) position, - // (2) focus, and (3) upvector. They can then be queried elsewhere in llAgent. - //-------------------------------------------------------------------------------- - // *TODO: use combined rotation of frameagent and sit object - LLQuaternion avatarRotationForFollowCam = mAvatarObject->isSitting() ? mAvatarObject->getRenderRotation() : mFrameAgent.getQuaternion(); - - LLFollowCamParams* current_cam = LLFollowCamMgr::getActiveFollowCamParams(); - if (current_cam) - { - mFollowCam.copyParams(*current_cam); - mFollowCam.setSubjectPositionAndRotation( mAvatarObject->getRenderPosition(), avatarRotationForFollowCam ); - mFollowCam.update(); - LLViewerJoystick::getInstance()->setCameraNeedsUpdate(true); - } - else - { - changeCameraToThirdPerson(TRUE); - } - } - } - // end Ventrella - - BOOL hit_limit; - LLVector3d camera_pos_global; - LLVector3d camera_target_global = calcCameraPositionTargetGlobal(&hit_limit); - mCameraVirtualPositionAgent = getPosAgentFromGlobal(camera_target_global); - LLVector3d focus_target_global = calcFocusPositionTargetGlobal(); - - // perform field of view correction - mCameraFOVZoomFactor = calcCameraFOVZoomFactor(); - camera_target_global = focus_target_global + (camera_target_global - focus_target_global) * (1.f + mCameraFOVZoomFactor); - - mShowAvatar = TRUE; // can see avatar by default - - // Adjust position for animation - if (mCameraAnimating) - { - F32 time = mAnimationTimer.getElapsedTimeF32(); - - // yet another instance of critically damped motion, hooray! - // F32 fraction_of_animation = 1.f - pow(2.f, -time / CAMERA_ZOOM_HALF_LIFE); - - // linear interpolation - F32 fraction_of_animation = time / mAnimationDuration; - - BOOL isfirstPerson = mCameraMode == CAMERA_MODE_MOUSELOOK; - BOOL wasfirstPerson = mLastCameraMode == CAMERA_MODE_MOUSELOOK; - F32 fraction_animation_to_skip; - - if (mAnimationCameraStartGlobal == camera_target_global) - { - fraction_animation_to_skip = 0.f; - } - else - { - LLVector3d cam_delta = mAnimationCameraStartGlobal - camera_target_global; - fraction_animation_to_skip = HEAD_BUFFER_SIZE / (F32)cam_delta.magVec(); - } - F32 animation_start_fraction = (wasfirstPerson) ? fraction_animation_to_skip : 0.f; - F32 animation_finish_fraction = (isfirstPerson) ? (1.f - fraction_animation_to_skip) : 1.f; - - if (fraction_of_animation < animation_finish_fraction) - { - if (fraction_of_animation < animation_start_fraction || fraction_of_animation > animation_finish_fraction ) - { - mShowAvatar = FALSE; - } - - // ...adjust position for animation - F32 smooth_fraction_of_animation = llsmoothstep(0.0f, 1.0f, fraction_of_animation); - camera_pos_global = lerp(mAnimationCameraStartGlobal, camera_target_global, smooth_fraction_of_animation); - mFocusGlobal = lerp(mAnimationFocusStartGlobal, focus_target_global, smooth_fraction_of_animation); - } - else - { - // ...animation complete - mCameraAnimating = FALSE; - - camera_pos_global = camera_target_global; - mFocusGlobal = focus_target_global; - - endAnimationUpdateUI(); - mShowAvatar = TRUE; - } - - if (getAvatarObject() && mCameraMode != CAMERA_MODE_MOUSELOOK) - { - getAvatarObject()->updateAttachmentVisibility(mCameraMode); - } - } - else - { - camera_pos_global = camera_target_global; - mFocusGlobal = focus_target_global; - mShowAvatar = TRUE; - } - - // smoothing - if (TRUE) - { - LLVector3d agent_pos = getPositionGlobal(); - LLVector3d camera_pos_agent = camera_pos_global - agent_pos; - // Sitting on what you're manipulating can cause camera jitter with smoothing. - // This turns off smoothing while editing. -MG - mCameraSmoothingStop |= (BOOL)LLToolMgr::getInstance()->inBuildMode(); - - if (cameraThirdPerson() && !mCameraSmoothingStop) - { - const F32 SMOOTHING_HALF_LIFE = 0.02f; - - F32 smoothing = LLCriticalDamp::getInterpolant(gSavedSettings.getF32("CameraPositionSmoothing") * SMOOTHING_HALF_LIFE, FALSE); - - if (!mFocusObject) // we differentiate on avatar mode - { - // for avatar-relative focus, we smooth in avatar space - - // the avatar moves too jerkily w/r/t global space to smooth there. - - LLVector3d delta = camera_pos_agent - mCameraSmoothingLastPositionAgent; - if (delta.magVec() < MAX_CAMERA_SMOOTH_DISTANCE) // only smooth over short distances please - { - camera_pos_agent = lerp(mCameraSmoothingLastPositionAgent, camera_pos_agent, smoothing); - camera_pos_global = camera_pos_agent + agent_pos; - } - } - else - { - LLVector3d delta = camera_pos_global - mCameraSmoothingLastPositionGlobal; - if (delta.magVec() < MAX_CAMERA_SMOOTH_DISTANCE) // only smooth over short distances please - { - camera_pos_global = lerp(mCameraSmoothingLastPositionGlobal, camera_pos_global, smoothing); - } - } - } - - mCameraSmoothingLastPositionGlobal = camera_pos_global; - mCameraSmoothingLastPositionAgent = camera_pos_agent; - mCameraSmoothingStop = FALSE; - } - - - mCameraCurrentFOVZoomFactor = lerp(mCameraCurrentFOVZoomFactor, mCameraFOVZoomFactor, LLCriticalDamp::getInterpolant(FOV_ZOOM_HALF_LIFE)); - -// llinfos << "Current FOV Zoom: " << mCameraCurrentFOVZoomFactor << " Target FOV Zoom: " << mCameraFOVZoomFactor << " Object penetration: " << mFocusObjectDist << llendl; - - F32 ui_offset = 0.f; - if( CAMERA_MODE_CUSTOMIZE_AVATAR == mCameraMode ) - { - ui_offset = calcCustomizeAvatarUIOffset( camera_pos_global ); - } - - - LLVector3 focus_agent = getPosAgentFromGlobal(mFocusGlobal); - - mCameraPositionAgent = getPosAgentFromGlobal(camera_pos_global); - - // Move the camera - - //Ventrella - LLViewerCamera::getInstance()->updateCameraLocation(mCameraPositionAgent, mCameraUpVector, focus_agent); - //LLViewerCamera::getInstance()->updateCameraLocation(mCameraPositionAgent, camera_skyward, focus_agent); - //end Ventrella - - //RN: translate UI offset after camera is oriented properly - LLViewerCamera::getInstance()->translate(LLViewerCamera::getInstance()->getLeftAxis() * ui_offset); - - // Change FOV - LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / (1.f + mCameraCurrentFOVZoomFactor)); - - // follow camera when in customize mode - if (cameraCustomizeAvatar()) - { - setLookAt(LOOKAT_TARGET_FOCUS, NULL, mCameraPositionAgent); - } - - // update the travel distance stat - // this isn't directly related to the camera - // but this seemed like the best place to do this - LLVector3d global_pos = getPositionGlobal(); - if (! mLastPositionGlobal.isExactlyZero()) - { - LLVector3d delta = global_pos - mLastPositionGlobal; - mDistanceTraveled += delta.magVec(); - } - mLastPositionGlobal = global_pos; - - if (LLVOAvatar::sVisibleInFirstPerson && mAvatarObject.notNull() && !mAvatarObject->isSitting() && cameraMouselook()) - { - LLVector3 head_pos = mAvatarObject->mHeadp->getWorldPosition() + - LLVector3(0.08f, 0.f, 0.05f) * mAvatarObject->mHeadp->getWorldRotation() + - LLVector3(0.1f, 0.f, 0.f) * mAvatarObject->mPelvisp->getWorldRotation(); - LLVector3 diff = mCameraPositionAgent - head_pos; - diff = diff * ~mAvatarObject->mRoot.getWorldRotation(); - - LLJoint* torso_joint = mAvatarObject->mTorsop; - LLJoint* chest_joint = mAvatarObject->mChestp; - LLVector3 torso_scale = torso_joint->getScale(); - LLVector3 chest_scale = chest_joint->getScale(); - - // shorten avatar skeleton to avoid foot interpenetration - if (!mAvatarObject->mInAir) - { - LLVector3 chest_offset = LLVector3(0.f, 0.f, chest_joint->getPosition().mV[VZ]) * torso_joint->getWorldRotation(); - F32 z_compensate = llclamp(-diff.mV[VZ], -0.2f, 1.f); - F32 scale_factor = llclamp(1.f - ((z_compensate * 0.5f) / chest_offset.mV[VZ]), 0.5f, 1.2f); - torso_joint->setScale(LLVector3(1.f, 1.f, scale_factor)); - - LLJoint* neck_joint = mAvatarObject->mNeckp; - LLVector3 neck_offset = LLVector3(0.f, 0.f, neck_joint->getPosition().mV[VZ]) * chest_joint->getWorldRotation(); - scale_factor = llclamp(1.f - ((z_compensate * 0.5f) / neck_offset.mV[VZ]), 0.5f, 1.2f); - chest_joint->setScale(LLVector3(1.f, 1.f, scale_factor)); - diff.mV[VZ] = 0.f; - } - - mAvatarObject->mPelvisp->setPosition(mAvatarObject->mPelvisp->getPosition() + diff); - - mAvatarObject->mRoot.updateWorldMatrixChildren(); - - for (LLVOAvatar::attachment_map_t::iterator iter = mAvatarObject->mAttachmentPoints.begin(); - iter != mAvatarObject->mAttachmentPoints.end(); ) - { - LLVOAvatar::attachment_map_t::iterator curiter = iter++; - LLViewerJointAttachment* attachment = curiter->second; - for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin(); - attachment_iter != attachment->mAttachedObjects.end(); - ++attachment_iter) - { - LLViewerObject *attached_object = (*attachment_iter); - if (attached_object && !attached_object->isDead() && attached_object->mDrawable.notNull()) - { - // clear any existing "early" movements of attachment - attached_object->mDrawable->clearState(LLDrawable::EARLY_MOVE); - gPipeline.updateMoveNormalAsync(attached_object->mDrawable); - attached_object->updateText(); - } - } - } - - torso_joint->setScale(torso_scale); - chest_joint->setScale(chest_scale); - } -} - -void LLAgent::updateFocusOffset() -{ - validateFocusObject(); - if (mFocusObject.notNull()) - { - LLVector3d obj_pos = getPosGlobalFromAgent(mFocusObject->getRenderPosition()); - mFocusObjectOffset.setVec(mFocusTargetGlobal - obj_pos); - } -} - -void LLAgent::validateFocusObject() -{ - if (mFocusObject.notNull() && - (mFocusObject->isDead())) - { - mFocusObjectOffset.clearVec(); - clearFocusObject(); - mCameraFOVZoomFactor = 0.f; - } -} - -//----------------------------------------------------------------------------- -// calcCustomizeAvatarUIOffset() -//----------------------------------------------------------------------------- -F32 LLAgent::calcCustomizeAvatarUIOffset( const LLVector3d& camera_pos_global ) -{ - F32 ui_offset = 0.f; + mAutoPilotTargetDist = target_dist; - if( gFloaterCustomize ) - { - const LLRect& rect = gFloaterCustomize->getRect(); + // Make this a two-dimensional solution + at.mV[VZ] = 0.f; + direction.mV[VZ] = 0.f; - // Move the camera so that the avatar isn't covered up by this floater. - F32 fraction_of_fov = 0.5f - (0.5f * (1.f - llmin(1.f, ((F32)rect.getWidth() / (F32)gViewerWindow->getWindowWidthScaled())))); - F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView() * LLViewerCamera::getInstance()->getAspect(); // radians - F32 offset = tan(apparent_angle); + at.normalize(); + F32 xy_distance = direction.normalize(); - if( rect.mLeft < (gViewerWindow->getWindowWidthScaled() - rect.mRight) ) + F32 yaw = 0.f; + if (mAutoPilotTargetDist > mAutoPilotStopDistance) { - // Move the avatar to the right (camera to the left) - ui_offset = offset; + yaw = angle_between(mFrameAgent.getAtAxis(), direction); } - else + else if (mAutoPilotUseRotation) { - // Move the avatar to the left (camera to the right) - ui_offset = -offset; + // we're close now just aim at target facing + yaw = angle_between(at, mAutoPilotTargetFacing); + direction = mAutoPilotTargetFacing; } - } - F32 range = (F32)dist_vec(camera_pos_global, gAgentCamera.getFocusGlobal()); - gAgentCameraHACK.mUIOffset = lerp(mUIOffset, ui_offset, LLCriticalDamp::getInterpolant(0.05f)); - return mUIOffset * range; -} -//----------------------------------------------------------------------------- -// calcFocusPositionTargetGlobal() -//----------------------------------------------------------------------------- -LLVector3d LLAgent::calcFocusPositionTargetGlobal() -{ - if (mFocusObject.notNull() && mFocusObject->isDead()) - { - clearFocusObject(); - } + yaw = 4.f * yaw / gFPSClamped; - // Ventrella - if ( mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar ) - { - mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedFocus()); - return mFocusTargetGlobal; - }// End Ventrella - else if (mCameraMode == CAMERA_MODE_MOUSELOOK) - { - LLVector3d at_axis(1.0, 0.0, 0.0); - LLQuaternion agent_rot = mFrameAgent.getQuaternion(); - if (mAvatarObject.notNull() && mAvatarObject->getParent()) + // figure out which direction to turn + LLVector3 scratch(at % direction); + + if (scratch.mV[VZ] > 0.f) { - LLViewerObject* root_object = (LLViewerObject*)mAvatarObject->getRoot(); - if (!root_object->flagCameraDecoupled()) - { - agent_rot *= ((LLViewerObject*)(mAvatarObject->getParent()))->getRenderRotation(); - } + setControlFlags(AGENT_CONTROL_YAW_POS); } - at_axis = at_axis * agent_rot; - mFocusTargetGlobal = calcCameraPositionTargetGlobal() + at_axis; - return mFocusTargetGlobal; - } - else if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) - { - return mFocusTargetGlobal; - } - else if (!mFocusOnAvatar) - { - if (mFocusObject.notNull() && !mFocusObject->isDead() && mFocusObject->mDrawable.notNull()) + else { - LLDrawable* drawablep = mFocusObject->mDrawable; - - if (mTrackFocusObject && - drawablep && - drawablep->isActive()) - { - if (!mFocusObject->isAvatar()) - { - if (mFocusObject->isSelected()) - { - gPipeline.updateMoveNormalAsync(drawablep); - } - else - { - if (drawablep->isState(LLDrawable::MOVE_UNDAMPED)) - { - gPipeline.updateMoveNormalAsync(drawablep); - } - else - { - gPipeline.updateMoveDampedAsync(drawablep); - } - } - } - } - // if not tracking object, update offset based on new object position - else - { - updateFocusOffset(); - } - LLVector3 focus_agent = mFocusObject->getRenderPosition() + mFocusObjectOffset; - mFocusTargetGlobal.setVec(getPosGlobalFromAgent(focus_agent)); + yaw = -yaw; + setControlFlags(AGENT_CONTROL_YAW_NEG); } - return mFocusTargetGlobal; - } - else if (mSitCameraEnabled && mAvatarObject.notNull() && mAvatarObject->isSitting() && mSitCameraReferenceObject.notNull()) - { - // sit camera - LLVector3 object_pos = mSitCameraReferenceObject->getRenderPosition(); - LLQuaternion object_rot = mSitCameraReferenceObject->getRenderRotation(); - LLVector3 target_pos = object_pos + (mSitCameraFocus * object_rot); - return getPosGlobalFromAgent(target_pos); - } - else - { - return getPositionGlobal() + calcThirdPersonFocusOffset(); - } -} - -LLVector3d LLAgent::calcThirdPersonFocusOffset() -{ - // ...offset from avatar - LLVector3d focus_offset; - - LLQuaternion agent_rot = mFrameAgent.getQuaternion(); - if (!mAvatarObject.isNull() && mAvatarObject->getParent()) - { - agent_rot *= ((LLViewerObject*)(mAvatarObject->getParent()))->getRenderRotation(); - } - - focus_offset = mFocusOffsetInitial[mCameraPreset] * agent_rot; - return focus_offset; -} - -void LLAgent::setupSitCamera() -{ - // agent frame entering this function is in world coordinates - if (mAvatarObject.notNull() && mAvatarObject->getParent()) - { - LLQuaternion parent_rot = ((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation(); - // slam agent coordinate frame to proper parent local version - LLVector3 at_axis = mFrameAgent.getAtAxis(); - at_axis.mV[VZ] = 0.f; - at_axis.normalize(); - resetAxes(at_axis * ~parent_rot); - } -} - -//----------------------------------------------------------------------------- -// getCameraPositionAgent() -//----------------------------------------------------------------------------- -const LLVector3 &LLAgent::getCameraPositionAgent() const -{ - return LLViewerCamera::getInstance()->getOrigin(); -} - -//----------------------------------------------------------------------------- -// getCameraPositionGlobal() -//----------------------------------------------------------------------------- -LLVector3d LLAgent::getCameraPositionGlobal() const -{ - return getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin()); -} - -//----------------------------------------------------------------------------- -// calcCameraFOVZoomFactor() -//----------------------------------------------------------------------------- -F32 LLAgent::calcCameraFOVZoomFactor() -{ - LLVector3 camera_offset_dir; - camera_offset_dir.setVec(mCameraFocusOffset); - - if (mCameraMode == CAMERA_MODE_MOUSELOOK) - { - return 0.f; - } - else if (mFocusObject.notNull() && !mFocusObject->isAvatar() && !mFocusOnAvatar) - { - // don't FOV zoom on mostly transparent objects - LLVector3 focus_offset = mFocusObjectOffset; - F32 obj_min_dist = 0.f; - calcCameraMinDistance(obj_min_dist); - F32 current_distance = llmax(0.001f, camera_offset_dir.magVec()); - - mFocusObjectDist = obj_min_dist - current_distance; - - F32 new_fov_zoom = llclamp(mFocusObjectDist / current_distance, 0.f, 1000.f); - return new_fov_zoom; - } - else // focusing on land or avatar - { - // keep old field of view until user changes focus explicitly - return mCameraFOVZoomFactor; - //return 0.f; - } -} - -//----------------------------------------------------------------------------- -// calcCameraPositionTargetGlobal() -//----------------------------------------------------------------------------- -LLVector3d LLAgent::calcCameraPositionTargetGlobal(BOOL *hit_limit) -{ - // Compute base camera position and look-at points. - F32 camera_land_height; - LLVector3d frame_center_global = mAvatarObject.isNull() ? getPositionGlobal() - : getPosGlobalFromAgent(mAvatarObject->mRoot.getWorldPosition()); - - BOOL isConstrained = FALSE; - LLVector3d head_offset; - head_offset.setVec(mThirdPersonHeadOffset); - - LLVector3d camera_position_global; + *delta_yaw = yaw; - // Ventrella - if ( mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar ) - { - camera_position_global = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedPosition()); - }// End Ventrella - else if (mCameraMode == CAMERA_MODE_MOUSELOOK) - { - if (mAvatarObject.isNull() || mAvatarObject->mDrawable.isNull()) - { - llwarns << "Null avatar drawable!" << llendl; - return LLVector3d::zero; - } - head_offset.clearVec(); - if (mAvatarObject->isSitting() && mAvatarObject->getParent()) + // Compute when to start slowing down and when to stop + F32 stop_distance = mAutoPilotStopDistance; + F32 slow_distance; + if (getFlying()) { - mAvatarObject->updateHeadOffset(); - head_offset.mdV[VX] = mAvatarObject->mHeadOffset.mV[VX]; - head_offset.mdV[VY] = mAvatarObject->mHeadOffset.mV[VY]; - head_offset.mdV[VZ] = mAvatarObject->mHeadOffset.mV[VZ] + 0.1f; - const LLMatrix4& mat = ((LLViewerObject*) mAvatarObject->getParent())->getRenderMatrix(); - camera_position_global = getPosGlobalFromAgent - ((mAvatarObject->getPosition()+ - LLVector3(head_offset)*mAvatarObject->getRotation()) * mat); + slow_distance = llmax(6.f, mAutoPilotStopDistance + 5.f); + stop_distance = llmax(2.f, mAutoPilotStopDistance); } else { - head_offset.mdV[VZ] = mAvatarObject->mHeadOffset.mV[VZ]; - if (mAvatarObject->isSitting()) - { - head_offset.mdV[VZ] += 0.1; - } - camera_position_global = getPosGlobalFromAgent(mAvatarObject->getRenderPosition());//frame_center_global; - head_offset = head_offset * mAvatarObject->getRenderRotation(); - camera_position_global = camera_position_global + head_offset; + slow_distance = llmax(3.f, mAutoPilotStopDistance + 2.f); } - } - else if (mCameraMode == CAMERA_MODE_THIRD_PERSON && mFocusOnAvatar) - { - LLVector3 local_camera_offset; - F32 camera_distance = 0.f; - if (mSitCameraEnabled - && mAvatarObject.notNull() - && mAvatarObject->isSitting() - && mSitCameraReferenceObject.notNull()) - { - // sit camera - LLVector3 object_pos = mSitCameraReferenceObject->getRenderPosition(); - LLQuaternion object_rot = mSitCameraReferenceObject->getRenderRotation(); - - LLVector3 target_pos = object_pos + (mSitCameraPos * object_rot); - - camera_position_global = getPosGlobalFromAgent(target_pos); - } - else + // If we're flying, handle autopilot points above or below you. + if (getFlying() && xy_distance < AUTOPILOT_HEIGHT_ADJUST_DISTANCE) { - local_camera_offset = mCameraZoomFraction * getCameraOffsetInitial() * gSavedSettings.getF32("CameraOffsetScale"); - - // are we sitting down? - if (mAvatarObject.notNull() && mAvatarObject->getParent()) - { - LLQuaternion parent_rot = ((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation(); - // slam agent coordinate frame to proper parent local version - LLVector3 at_axis = mFrameAgent.getAtAxis() * parent_rot; - at_axis.mV[VZ] = 0.f; - at_axis.normalize(); - resetAxes(at_axis * ~parent_rot); - - local_camera_offset = local_camera_offset * mFrameAgent.getQuaternion() * parent_rot; - } - else - { - local_camera_offset = mFrameAgent.rotateToAbsolute( local_camera_offset ); - } - - if (!mCameraCollidePlane.isExactlyZero() && (mAvatarObject.isNull() || !mAvatarObject->isSitting())) + if (mAvatarObject.notNull()) { - LLVector3 plane_normal; - plane_normal.setVec(mCameraCollidePlane.mV); - - F32 offset_dot_norm = local_camera_offset * plane_normal; - if (llabs(offset_dot_norm) < 0.001f) - { - offset_dot_norm = 0.001f; - } - - camera_distance = local_camera_offset.normalize(); - - F32 pos_dot_norm = getPosAgentFromGlobal(frame_center_global + head_offset) * plane_normal; - - // if agent is outside the colliding half-plane - if (pos_dot_norm > mCameraCollidePlane.mV[VW]) + F64 current_height = mAvatarObject->getPositionGlobal().mdV[VZ]; + F32 delta_z = (F32)(mAutoPilotTargetGlobal.mdV[VZ] - current_height); + F32 slope = delta_z / xy_distance; + if (slope > 0.45f && delta_z > 6.f) { - // check to see if camera is on the opposite side (inside) the half-plane - if (offset_dot_norm + pos_dot_norm < mCameraCollidePlane.mV[VW]) - { - // diminish offset by factor to push it back outside the half-plane - camera_distance *= (pos_dot_norm - mCameraCollidePlane.mV[VW] - CAMERA_COLLIDE_EPSILON) / -offset_dot_norm; - } + setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_POS); } - else + else if (slope > 0.002f && delta_z > 0.5f) { - if (offset_dot_norm + pos_dot_norm > mCameraCollidePlane.mV[VW]) - { - camera_distance *= (mCameraCollidePlane.mV[VW] - pos_dot_norm - CAMERA_COLLIDE_EPSILON) / offset_dot_norm; - } + setControlFlags(AGENT_CONTROL_UP_POS); } - } - else - { - camera_distance = local_camera_offset.normalize(); - } - - mTargetCameraDistance = llmax(camera_distance, MIN_CAMERA_DISTANCE); - - if (mTargetCameraDistance != mCurrentCameraDistance) - { - F32 camera_lerp_amt = LLCriticalDamp::getInterpolant(CAMERA_ZOOM_HALF_LIFE); - - mCurrentCameraDistance = lerp(mCurrentCameraDistance, mTargetCameraDistance, camera_lerp_amt); - } - - // Make the camera distance current - local_camera_offset *= mCurrentCameraDistance; - - // set the global camera position - LLVector3d camera_offset; - - LLVector3 av_pos = mAvatarObject.isNull() ? LLVector3::zero : mAvatarObject->getRenderPosition(); - camera_offset.setVec( local_camera_offset ); - camera_position_global = frame_center_global + head_offset + camera_offset; - - if (mAvatarObject.notNull()) - { - LLVector3d camera_lag_d; - F32 lag_interp = LLCriticalDamp::getInterpolant(CAMERA_LAG_HALF_LIFE); - LLVector3 target_lag; - LLVector3 vel = getVelocity(); - - // lag by appropriate amount for flying - F32 time_in_air = mAvatarObject->mTimeInAir.getElapsedTimeF32(); - if(!mCameraAnimating && mAvatarObject->mInAir && time_in_air > GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME) + else if (slope < -0.45f && delta_z < -6.f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND) { - LLVector3 frame_at_axis = mFrameAgent.getAtAxis(); - frame_at_axis -= projected_vec(frame_at_axis, getReferenceUpVector()); - frame_at_axis.normalize(); - - //transition smoothly in air mode, to avoid camera pop - F32 u = (time_in_air - GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME) / GROUND_TO_AIR_CAMERA_TRANSITION_TIME; - u = llclamp(u, 0.f, 1.f); - - lag_interp *= u; - - if (gViewerWindow->getLeftMouseDown() && gViewerWindow->getLastPick().mObjectID == mAvatarObject->getID()) - { - // disable camera lag when using mouse-directed steering - target_lag.clearVec(); - } - else - { - target_lag = vel * gSavedSettings.getF32("DynamicCameraStrength") / 30.f; - } - - mCameraLag = lerp(mCameraLag, target_lag, lag_interp); - - F32 lag_dist = mCameraLag.magVec(); - if (lag_dist > MAX_CAMERA_LAG) - { - mCameraLag = mCameraLag * MAX_CAMERA_LAG / lag_dist; - } - - // clamp camera lag so that avatar is always in front - F32 dot = (mCameraLag - (frame_at_axis * (MIN_CAMERA_LAG * u))) * frame_at_axis; - if (dot < -(MIN_CAMERA_LAG * u)) - { - mCameraLag -= (dot + (MIN_CAMERA_LAG * u)) * frame_at_axis; - } + setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_NEG); } - else + else if (slope < -0.002f && delta_z < -0.5f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND) { - mCameraLag = lerp(mCameraLag, LLVector3::zero, LLCriticalDamp::getInterpolant(0.15f)); + setControlFlags(AGENT_CONTROL_UP_NEG); } - - camera_lag_d.setVec(mCameraLag); - camera_position_global = camera_position_global - camera_lag_d; } } - } - else - { - LLVector3d focusPosGlobal = calcFocusPositionTargetGlobal(); - // camera gets pushed out later wrt mCameraFOVZoomFactor...this is "raw" value - camera_position_global = focusPosGlobal + mCameraFocusOffset; - } - - if (!gSavedSettings.getBOOL("DisableCameraConstraints") && !gAgent.isGodlike()) - { - LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromPosGlobal( - camera_position_global); - bool constrain = true; - if(regionp && regionp->canManageEstate()) - { - constrain = false; - } - if(constrain) - { - F32 max_dist = ( CAMERA_MODE_CUSTOMIZE_AVATAR == mCameraMode ) ? - APPEARANCE_MAX_ZOOM : mDrawDistance; - LLVector3d camera_offset = camera_position_global - - gAgent.getPositionGlobal(); - F32 camera_distance = (F32)camera_offset.magVec(); + // calculate delta rotation to target heading + F32 delta_target_heading = angle_between(mFrameAgent.getAtAxis(), mAutoPilotTargetFacing); - if(camera_distance > max_dist) - { - camera_position_global = gAgent.getPositionGlobal() + - (max_dist / camera_distance) * camera_offset; - isConstrained = TRUE; - } + if (xy_distance > slow_distance && yaw < (F_PI / 10.f)) + { + // walking/flying fast + setControlFlags(AGENT_CONTROL_FAST_AT | AGENT_CONTROL_AT_POS); } - -// JC - Could constrain camera based on parcel stuff here. -// LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromPosGlobal(camera_position_global); -// -// if (regionp && !regionp->mParcelOverlay->isBuildCameraAllowed(regionp->getPosRegionFromGlobal(camera_position_global))) -// { -// camera_position_global = last_position_global; -// -// isConstrained = TRUE; -// } - } - - // Don't let camera go underground - F32 camera_min_off_ground = getCameraMinOffGround(); - - camera_land_height = LLWorld::getInstance()->resolveLandHeightGlobal(camera_position_global); - - if (camera_position_global.mdV[VZ] < camera_land_height + camera_min_off_ground) - { - camera_position_global.mdV[VZ] = camera_land_height + camera_min_off_ground; - isConstrained = TRUE; - } - - - if (hit_limit) - { - *hit_limit = isConstrained; - } - - return camera_position_global; -} - - -LLVector3 LLAgent::getCameraOffsetInitial() -{ - return mCameraOffsetInitial[mCameraPreset]; -} - -//----------------------------------------------------------------------------- -// handleScrollWheel() -//----------------------------------------------------------------------------- -void LLAgent::handleScrollWheel(S32 clicks) -{ - if ( mCameraMode == CAMERA_MODE_FOLLOW && gAgentCamera.getFocusOnAvatar()) - { - if ( ! mFollowCam.getPositionLocked() ) // not if the followCam position is locked in place + else if (mAutoPilotTargetDist > mAutoPilotStopDistance) { - mFollowCam.zoom( clicks ); - if ( mFollowCam.isZoomedToMinimumDistance() ) + // walking/flying slow + if (at * direction > 0.9f) { - changeCameraToMouselook(FALSE); + setControlFlags(AGENT_CONTROL_AT_POS); + } + else if (at * direction < -0.9f) + { + setControlFlags(AGENT_CONTROL_AT_NEG); } } - } - else - { - LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); - const F32 ROOT_ROOT_TWO = sqrt(F_SQRT2); - - // Block if camera is animating - if (mCameraAnimating) - { - return; - } - - if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) - { - F32 zoom_factor = (F32)pow(0.8, -clicks); - cameraZoomIn(zoom_factor); - } - else if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON) - { - F32 camera_offset_initial_mag = getCameraOffsetInitial().magVec(); - - F32 current_zoom_fraction = mTargetCameraDistance / (camera_offset_initial_mag * gSavedSettings.getF32("CameraOffsetScale")); - current_zoom_fraction *= 1.f - pow(ROOT_ROOT_TWO, clicks); - - cameraOrbitIn(current_zoom_fraction * camera_offset_initial_mag * gSavedSettings.getF32("CameraOffsetScale")); - } - else + + // check to see if we need to keep rotating to target orientation + if (mAutoPilotTargetDist < mAutoPilotStopDistance) { - F32 current_zoom_fraction = (F32)mCameraFocusOffsetTarget.magVec(); - cameraOrbitIn(current_zoom_fraction * (1.f - pow(ROOT_ROOT_TWO, clicks))); + setControlFlags(AGENT_CONTROL_STOP); + if(!mAutoPilotUseRotation || (delta_target_heading < mAutoPilotRotationThreshold)) + { + stopAutoPilot(); + } } } } + //----------------------------------------------------------------------------- -// getCameraMinOffGround() +// propagate() //----------------------------------------------------------------------------- -F32 LLAgent::getCameraMinOffGround() +void LLAgent::propagate(const F32 dt) { - if (mCameraMode == CAMERA_MODE_MOUSELOOK) + // Update UI based on agent motion + LLFloaterMove *floater_move = LLFloaterReg::findTypedInstance("moveview"); + if (floater_move) { - return 0.f; + floater_move->mForwardButton ->setToggleState( mAtKey > 0 || mWalkKey > 0 ); + floater_move->mBackwardButton ->setToggleState( mAtKey < 0 || mWalkKey < 0 ); + floater_move->mTurnLeftButton ->setToggleState( mYawKey > 0.f ); + floater_move->mTurnRightButton ->setToggleState( mYawKey < 0.f ); + floater_move->mMoveUpButton ->setToggleState( mUpKey > 0 ); + floater_move->mMoveDownButton ->setToggleState( mUpKey < 0 ); } - else + + // handle rotation based on keyboard levels + const F32 YAW_RATE = 90.f * DEG_TO_RAD; // radians per second + yaw(YAW_RATE * mYawKey * dt); + + const F32 PITCH_RATE = 90.f * DEG_TO_RAD; // radians per second + pitch(PITCH_RATE * mPitchKey * dt); + + // handle auto-land behavior + if (mAvatarObject.notNull()) { - if (gSavedSettings.getBOOL("DisableCameraConstraints")) - { - return -1000.f; - } - else + BOOL in_air = mAvatarObject->mInAir; + LLVector3 land_vel = getVelocity(); + land_vel.mV[VZ] = 0.f; + + if (!in_air + && mUpKey < 0 + && land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED + && gSavedSettings.getBOOL("AutomaticFly")) { - return 0.5f; + // land automatically + setFlying(FALSE); } } -} - - -//----------------------------------------------------------------------------- -// resetCamera() -//----------------------------------------------------------------------------- -void LLAgent::resetCamera() -{ - // Remove any pitch from the avatar - LLVector3 at = mFrameAgent.getAtAxis(); - at.mV[VZ] = 0.f; - at.normalize(); - gAgent.resetAxes(at); - // have to explicitly clear field of view zoom now - mCameraFOVZoomFactor = 0.f; - updateCamera(); + // clear keys + mAtKey = 0; + mWalkKey = 0; + mLeftKey = 0; + mUpKey = 0; + mYawKey = 0.f; + mPitchKey = 0.f; } //----------------------------------------------------------------------------- -// changeCameraToMouselook() +// updateAgentPosition() //----------------------------------------------------------------------------- -void LLAgent::changeCameraToMouselook(BOOL animate) +void LLAgent::updateAgentPosition(const F32 dt, const F32 yaw_radians, const S32 mouse_x, const S32 mouse_y) { - if (LLViewerJoystick::getInstance()->getOverrideCamera()) - { - return; - } - - // visibility changes at end of animation - gViewerWindow->getWindow()->resetBusyCount(); - - // unpause avatar animation - mPauseRequest = NULL; + propagate(dt); - LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset); + // static S32 cameraUpdateCount = 0; - if (mAvatarObject.notNull()) - { - mAvatarObject->stopMotion( ANIM_AGENT_BODY_NOISE ); - mAvatarObject->stopMotion( ANIM_AGENT_BREATHE_ROT ); - } + rotate(yaw_radians, 0, 0, 1); + + // + // Check for water and land collision, set underwater flag + // - //gViewerWindow->stopGrab(); - LLSelectMgr::getInstance()->deselectAll(); - gViewerWindow->hideCursor(); - gViewerWindow->moveCursorToCenter(); + gAgentCamera.updateLookAt(mouse_x, mouse_y); +} - if( mCameraMode != CAMERA_MODE_MOUSELOOK ) - { - gFocusMgr.setKeyboardFocus( NULL ); - - mLastCameraMode = mCameraMode; - mCameraMode = CAMERA_MODE_MOUSELOOK; - U32 old_flags = mControlFlags; - setControlFlags(AGENT_CONTROL_MOUSELOOK); - if (old_flags != mControlFlags) - { - mbFlagsDirty = TRUE; - } +// friends and operators - if (animate) - { - startCameraAnimation(); - } - else - { - mCameraAnimating = FALSE; - endAnimationUpdateUI(); - } - } +std::ostream& operator<<(std::ostream &s, const LLAgent &agent) +{ + // This is unfinished, but might never be used. + // We'll just leave it for now; we can always delete it. + s << " { " + << " Frame = " << agent.mFrameAgent << "\n" + << " }"; + return s; } +// ------------------- Beginning of legacy LLCamera hack ---------------------- +// This section is included for legacy LLCamera support until +// it is no longer needed. Some legacy code must exist in +// non-legacy functions, and is labeled with "// legacy" comments. + //----------------------------------------------------------------------------- -// changeCameraToDefault() +// setAvatarObject() //----------------------------------------------------------------------------- -void LLAgent::changeCameraToDefault() -{ - if (LLViewerJoystick::getInstance()->getOverrideCamera()) +void LLAgent::setAvatarObject(LLVOAvatarSelf *avatar) +{ + mAvatarObject = avatar; + + if (!avatar) { + llinfos << "Setting LLAgent::mAvatarObject to NULL" << llendl; return; } - if (LLFollowCamMgr::getActiveFollowCamParams()) + if (!gAgentCamera.mLookAt) { - changeCameraToFollow(); + gAgentCamera.mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT); } - else + if (!gAgentCamera.mPointAt) { - changeCameraToThirdPerson(); + gAgentCamera.mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT); + } + + if (!gAgentCamera.mLookAt.isNull()) + { + gAgentCamera.mLookAt->setSourceObject(avatar); + } + if (!gAgentCamera.mPointAt.isNull()) + { + gAgentCamera.mPointAt->setSourceObject(avatar); } } - -// Ventrella +// TRUE if your own avatar needs to be rendered. Usually only +// in third person and build. //----------------------------------------------------------------------------- -// changeCameraToFollow() +// needsRenderAvatar() //----------------------------------------------------------------------------- -void LLAgent::changeCameraToFollow(BOOL animate) +BOOL LLAgent::needsRenderAvatar() { - if (LLViewerJoystick::getInstance()->getOverrideCamera()) + if (gAgentCamera.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson) { - return; + return FALSE; } - if( mCameraMode != CAMERA_MODE_FOLLOW ) - { - if (mCameraMode == CAMERA_MODE_MOUSELOOK) - { - animate = FALSE; - } - startCameraAnimation(); - - mLastCameraMode = mCameraMode; - mCameraMode = CAMERA_MODE_FOLLOW; - - // bang-in the current focus, position, and up vector of the follow cam - mFollowCam.reset( mCameraPositionAgent, LLViewerCamera::getInstance()->getPointOfInterest(), LLVector3::z_axis ); - - if (gBasicToolset) - { - LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); - } - - if (mAvatarObject.notNull()) - { - mAvatarObject->mPelvisp->setPosition(LLVector3::zero); - mAvatarObject->startMotion( ANIM_AGENT_BODY_NOISE ); - mAvatarObject->startMotion( ANIM_AGENT_BREATHE_ROT ); - } - - // unpause avatar animation - mPauseRequest = NULL; - - U32 old_flags = mControlFlags; - clearControlFlags(AGENT_CONTROL_MOUSELOOK); - if (old_flags != mControlFlags) - { - mbFlagsDirty = TRUE; - } + return mShowAvatar && mGenderChosen; +} - if (animate) - { - startCameraAnimation(); - } - else - { - mCameraAnimating = FALSE; - endAnimationUpdateUI(); - } - } +// TRUE if we need to render your own avatar's head. +BOOL LLAgent::needsRenderHead() +{ + return (LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCamera.cameraMouselook()); } //----------------------------------------------------------------------------- -// changeCameraToThirdPerson() +// startTyping() //----------------------------------------------------------------------------- -void LLAgent::changeCameraToThirdPerson(BOOL animate) +void LLAgent::startTyping() { - if (LLViewerJoystick::getInstance()->getOverrideCamera()) - { - return; - } - - gViewerWindow->getWindow()->resetBusyCount(); - - mCameraZoomFraction = INITIAL_ZOOM_FRACTION; + mTypingTimer.reset(); - if (mAvatarObject.notNull()) + if (getRenderState() & AGENT_STATE_TYPING) { - if (!mAvatarObject->isSitting()) - { - mAvatarObject->mPelvisp->setPosition(LLVector3::zero); - } - mAvatarObject->startMotion( ANIM_AGENT_BODY_NOISE ); - mAvatarObject->startMotion( ANIM_AGENT_BREATHE_ROT ); + // already typing, don't trigger a different animation + return; } + setRenderState(AGENT_STATE_TYPING); - LLVector3 at_axis; - - // unpause avatar animation - mPauseRequest = NULL; - - if( mCameraMode != CAMERA_MODE_THIRD_PERSON ) + if (mChatTimer.getElapsedTimeF32() < 2.f) { - if (gBasicToolset) - { - LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); - } - - mCameraLag.clearVec(); - if (mCameraMode == CAMERA_MODE_MOUSELOOK) - { - mCurrentCameraDistance = MIN_CAMERA_DISTANCE; - mTargetCameraDistance = MIN_CAMERA_DISTANCE; - animate = FALSE; - } - mLastCameraMode = mCameraMode; - mCameraMode = CAMERA_MODE_THIRD_PERSON; - U32 old_flags = mControlFlags; - clearControlFlags(AGENT_CONTROL_MOUSELOOK); - if (old_flags != mControlFlags) + LLViewerObject* chatter = gObjectList.findObject(mLastChatterID); + if (chatter && chatter->isAvatar()) { - mbFlagsDirty = TRUE; + gAgentCamera.setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero); } - } - // Remove any pitch from the avatar - if (mAvatarObject.notNull() && mAvatarObject->getParent()) - { - LLQuaternion obj_rot = ((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation(); - at_axis = LLViewerCamera::getInstance()->getAtAxis(); - at_axis.mV[VZ] = 0.f; - at_axis.normalize(); - resetAxes(at_axis * ~obj_rot); - } - else + if (gSavedSettings.getBOOL("PlayTypingAnim")) { - at_axis = mFrameAgent.getAtAxis(); - at_axis.mV[VZ] = 0.f; - at_axis.normalize(); - resetAxes(at_axis); + sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_START); } + LLNearbyChatBar::getInstance()->sendChatFromViewer("", CHAT_TYPE_START, FALSE); +} - - if (animate) - { - startCameraAnimation(); - } - else +//----------------------------------------------------------------------------- +// stopTyping() +//----------------------------------------------------------------------------- +void LLAgent::stopTyping() +{ + if (mRenderState & AGENT_STATE_TYPING) { - mCameraAnimating = FALSE; - endAnimationUpdateUI(); + clearRenderState(AGENT_STATE_TYPING); + sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_STOP); + LLNearbyChatBar::getInstance()->sendChatFromViewer("", CHAT_TYPE_STOP, FALSE); } } //----------------------------------------------------------------------------- -// changeCameraToCustomizeAvatar() +// setRenderState() //----------------------------------------------------------------------------- -void LLAgent::changeCameraToCustomizeAvatar(BOOL avatar_animate, BOOL camera_animate) +void LLAgent::setRenderState(U8 newstate) { - if (LLViewerJoystick::getInstance()->getOverrideCamera()) - { - return; - } + mRenderState |= newstate; +} - standUp(); // force stand up - gViewerWindow->getWindow()->resetBusyCount(); +//----------------------------------------------------------------------------- +// clearRenderState() +//----------------------------------------------------------------------------- +void LLAgent::clearRenderState(U8 clearstate) +{ + mRenderState &= ~clearstate; +} - if (gFaceEditToolset) - { - LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset); - } - if (camera_animate) +//----------------------------------------------------------------------------- +// getRenderState() +//----------------------------------------------------------------------------- +U8 LLAgent::getRenderState() +{ + if (gNoRender || gKeyboard == NULL) { - startCameraAnimation(); + return 0; } - // Remove any pitch from the avatar - //LLVector3 at = mFrameAgent.getAtAxis(); - //at.mV[VZ] = 0.f; - //at.normalize(); - //gAgent.resetAxes(at); - - if( mCameraMode != CAMERA_MODE_CUSTOMIZE_AVATAR ) + // *FIX: don't do stuff in a getter! This is infinite loop city! + if ((mTypingTimer.getElapsedTimeF32() > TYPING_TIMEOUT_SECS) + && (mRenderState & AGENT_STATE_TYPING)) { - mLastCameraMode = mCameraMode; - mCameraMode = CAMERA_MODE_CUSTOMIZE_AVATAR; - U32 old_flags = mControlFlags; - clearControlFlags(AGENT_CONTROL_MOUSELOOK); - if (old_flags != mControlFlags) - { - mbFlagsDirty = TRUE; - } - - gFocusMgr.setKeyboardFocus( NULL ); - gFocusMgr.setMouseCapture( NULL ); - - LLVOAvatarSelf::onCustomizeStart(); + stopTyping(); } - - if (mAvatarObject.notNull()) + + if ((!LLSelectMgr::getInstance()->getSelection()->isEmpty() && LLSelectMgr::getInstance()->shouldShowSelection()) + || LLToolMgr::getInstance()->getCurrentTool()->isEditing() ) { - if(avatar_animate) - { - // Remove any pitch from the avatar - LLVector3 at = mFrameAgent.getAtAxis(); - at.mV[VZ] = 0.f; - at.normalize(); - gAgent.resetAxes(at); - - sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_START); - mCustomAnim = TRUE ; - mAvatarObject->startMotion(ANIM_AGENT_CUSTOMIZE); - LLMotion* turn_motion = mAvatarObject->findMotion(ANIM_AGENT_CUSTOMIZE); - - if (turn_motion) - { - mAnimationDuration = turn_motion->getDuration() + CUSTOMIZE_AVATAR_CAMERA_ANIM_SLOP; - - } - else - { - mAnimationDuration = gSavedSettings.getF32("ZoomTime"); - } - } - - - - gAgentCamera.setFocusGlobal(LLVector3d::zero); + setRenderState(AGENT_STATE_EDITING); } else { - mCameraAnimating = FALSE; - endAnimationUpdateUI(); - } - -} - - -void LLAgent::switchCameraPreset(ECameraPreset preset) -{ - //zoom is supposed to be reset for the front and group views - mCameraZoomFraction = 1.f; - - //focusing on avatar in that case means following him on movements - mFocusOnAvatar = TRUE; - - mCameraPreset = preset; + clearRenderState(AGENT_STATE_EDITING); + } - gSavedSettings.setU32("CameraPreset", mCameraPreset); + return mRenderState; } - -// -// Focus point management -// - //----------------------------------------------------------------------------- -// startCameraAnimation() //----------------------------------------------------------------------------- -void LLAgent::startCameraAnimation() -{ - mAnimationCameraStartGlobal = getCameraPositionGlobal(); - mAnimationFocusStartGlobal = mFocusGlobal; - mAnimationTimer.reset(); - mCameraAnimating = TRUE; - mAnimationDuration = gSavedSettings.getF32("ZoomTime"); -} //----------------------------------------------------------------------------- -// stopCameraAnimation() +// endAnimationUpdateUI() //----------------------------------------------------------------------------- -void LLAgent::stopCameraAnimation() -{ - mCameraAnimating = FALSE; -} - -void LLAgent::clearFocusObject() +void LLAgent::endAnimationUpdateUI() { - if (mFocusObject.notNull()) + if (gAgentCamera.mCameraMode == gAgentCamera.mLastCameraMode) { - startCameraAnimation(); - - setFocusObject(NULL); - mFocusObjectOffset.clearVec(); + // We're already done endAnimationUpdateUI for this transition. + return; } -} -void LLAgent::setFocusObject(LLViewerObject* object) -{ - mFocusObject = object; -} + // clean up UI from mode we're leaving + if (gAgentCamera.mLastCameraMode == CAMERA_MODE_MOUSELOOK ) + { + // show mouse cursor + gViewerWindow->showCursor(); + // show menus + gMenuBarView->setVisible(TRUE); + LLNavigationBar::getInstance()->setVisible(TRUE); + gStatusBar->setVisibleForMouselook(true); -// Focus on a point, but try to keep camera position stable. -//----------------------------------------------------------------------------- -// setFocusGlobal() -//----------------------------------------------------------------------------- -void LLAgent::setFocusGlobal(const LLPickInfo& pick) -{ - LLViewerObject* objectp = gObjectList.findObject(pick.mObjectID); + LLBottomTray::getInstance()->onMouselookModeOut(); - if (objectp) - { - // focus on object plus designated offset - // which may or may not be same as pick.mPosGlobal - setFocusGlobal(objectp->getPositionGlobal() + LLVector3d(pick.mObjectOffset), pick.mObjectID); - } - else - { - // focus directly on point where user clicked - setFocusGlobal(pick.mPosGlobal, pick.mObjectID); - } -} + LLSideTray::getInstance()->getButtonsPanel()->setVisible(TRUE); + LLSideTray::getInstance()->updateSidetrayVisibility(); + LLPanelStandStopFlying::getInstance()->setVisible(TRUE); -void LLAgent::setFocusGlobal(const LLVector3d& focus, const LLUUID &object_id) -{ - setFocusObject(gObjectList.findObject(object_id)); - LLVector3d old_focus = mFocusTargetGlobal; - LLViewerObject *focus_obj = mFocusObject; + LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); - // if focus has changed - if (old_focus != focus) - { - if (focus.isExactlyZero()) + LLFloaterCamera::onLeavingMouseLook(); + + // Only pop if we have pushed... + if (TRUE == mViewsPushed) { - if (mAvatarObject.notNull()) - { - mFocusTargetGlobal = getPosGlobalFromAgent(mAvatarObject->mHeadp->getWorldPosition()); - } - else +#if 0 // Use this once all floaters are registered + LLFloaterReg::restoreVisibleInstances(); +#else // Use this for now + LLFloaterView::skip_list_t skip_list; + if (LLFloaterReg::findInstance("mini_map")) { - mFocusTargetGlobal = getPositionGlobal(); + skip_list.insert(LLFloaterReg::findInstance("mini_map")); } - mCameraFocusOffsetTarget = getCameraPositionGlobal() - mFocusTargetGlobal; - mCameraFocusOffset = mCameraFocusOffsetTarget; - setLookAt(LOOKAT_TARGET_CLEAR); + + gFloaterView->popVisibleAll(skip_list); +#endif + mViewsPushed = FALSE; } - else - { - mFocusTargetGlobal = focus; - if (!focus_obj) - { - mCameraFOVZoomFactor = 0.f; - } - mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(mCameraVirtualPositionAgent) - mFocusTargetGlobal; - - startCameraAnimation(); + + gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR); + if( gMorphView ) + { + gMorphView->setVisible( FALSE ); + } - if (focus_obj) + // Disable mouselook-specific animations + if (mAvatarObject.notNull()) + { + if( mAvatarObject->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) ) { - if (focus_obj->isAvatar()) + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != mAvatarObject->mSignaledAnimations.end()) { - setLookAt(LOOKAT_TARGET_FOCUS, focus_obj); + sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_START); } - else + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != mAvatarObject->mSignaledAnimations.end()) { - setLookAt(LOOKAT_TARGET_FOCUS, focus_obj, (getPosAgentFromGlobal(focus) - focus_obj->getRenderPosition()) * ~focus_obj->getRenderRotation()); + sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_START); + } + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != mAvatarObject->mSignaledAnimations.end()) + { + sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_START); + } + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != mAvatarObject->mSignaledAnimations.end()) + { + sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_START); } - } - else - { - setLookAt(LOOKAT_TARGET_FOCUS, NULL, getPosAgentFromGlobal(mFocusTargetGlobal)); } } } - else // focus == mFocusTargetGlobal + else + if(gAgentCamera.mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) { - if (focus.isExactlyZero()) + // make sure we ask to save changes + + LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); + + if( gMorphView ) { - if (mAvatarObject.notNull()) - { - mFocusTargetGlobal = getPosGlobalFromAgent(mAvatarObject->mHeadp->getWorldPosition()); - } - else - { - mFocusTargetGlobal = getPositionGlobal(); - } + gMorphView->setVisible( FALSE ); } - mCameraFocusOffsetTarget = (getCameraPositionGlobal() - mFocusTargetGlobal) / (1.f + mCameraFOVZoomFactor);; - mCameraFocusOffset = mCameraFocusOffsetTarget; - } - if (mFocusObject.notNull()) - { - // for attachments, make offset relative to avatar, not the attachment - if (mFocusObject->isAttachment()) + if (mAvatarObject.notNull()) { - while (mFocusObject.notNull() // DEV-29123 - can crash with a messed-up attachment - && !mFocusObject->isAvatar()) + if(mCustomAnim) { - mFocusObject = (LLViewerObject*) mFocusObject->getParent(); + sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_CUSTOMIZE_DONE, ANIM_REQUEST_START); + + mCustomAnim = FALSE ; } - setFocusObject((LLViewerObject*)mFocusObject); + } - updateFocusOffset(); + gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR); } -} - -// Used for avatar customization -//----------------------------------------------------------------------------- -// setCameraPosAndFocusGlobal() -//----------------------------------------------------------------------------- -void LLAgent::setCameraPosAndFocusGlobal(const LLVector3d& camera_pos, const LLVector3d& focus, const LLUUID &object_id) -{ - LLVector3d old_focus = mFocusTargetGlobal; - F64 focus_delta_squared = (old_focus - focus).magVecSquared(); - const F64 ANIM_EPSILON_SQUARED = 0.0001; - if( focus_delta_squared > ANIM_EPSILON_SQUARED ) + //--------------------------------------------------------------------- + // Set up UI for mode we're entering + //--------------------------------------------------------------------- + if (gAgentCamera.mCameraMode == CAMERA_MODE_MOUSELOOK) { - startCameraAnimation(); + // hide menus + gMenuBarView->setVisible(FALSE); + LLNavigationBar::getInstance()->setVisible(FALSE); + gStatusBar->setVisibleForMouselook(false); - if( CAMERA_MODE_CUSTOMIZE_AVATAR == mCameraMode ) - { - // Compensate for the fact that the camera has already been offset to make room for LLFloaterCustomize. - mAnimationCameraStartGlobal -= LLVector3d(LLViewerCamera::getInstance()->getLeftAxis() * calcCustomizeAvatarUIOffset( mAnimationCameraStartGlobal )); - } - } - - //LLViewerCamera::getInstance()->setOrigin( gAgent.getPosAgentFromGlobal( camera_pos ) ); - setFocusObject(gObjectList.findObject(object_id)); - mFocusTargetGlobal = focus; - mCameraFocusOffsetTarget = camera_pos - focus; - mCameraFocusOffset = mCameraFocusOffsetTarget; + LLBottomTray::getInstance()->onMouselookModeIn(); - if (mFocusObject) - { - if (mFocusObject->isAvatar()) - { - setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject); - } - else - { - setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject, (getPosAgentFromGlobal(focus) - mFocusObject->getRenderPosition()) * ~mFocusObject->getRenderRotation()); - } - } - else - { - setLookAt(LOOKAT_TARGET_FOCUS, NULL, getPosAgentFromGlobal(mFocusTargetGlobal)); - } + LLSideTray::getInstance()->getButtonsPanel()->setVisible(FALSE); + LLSideTray::getInstance()->updateSidetrayVisibility(); - if( mCameraAnimating ) - { - const F64 ANIM_METERS_PER_SECOND = 10.0; - const F64 MIN_ANIM_SECONDS = 0.5; - const F64 MAX_ANIM_SECONDS = 10.0; - F64 anim_duration = llmax( MIN_ANIM_SECONDS, sqrt(focus_delta_squared) / ANIM_METERS_PER_SECOND ); - anim_duration = llmin( anim_duration, MAX_ANIM_SECONDS ); - setAnimationDuration( (F32)anim_duration ); - } + LLPanelStandStopFlying::getInstance()->setVisible(FALSE); - updateFocusOffset(); -} + // clear out camera lag effect + gAgentCamera.mCameraLag.clearVec(); -//----------------------------------------------------------------------------- -// setSitCamera() -//----------------------------------------------------------------------------- -void LLAgent::setSitCamera(const LLUUID &object_id, const LLVector3 &camera_pos, const LLVector3 &camera_focus) -{ - BOOL camera_enabled = !object_id.isNull(); + // JC - Added for always chat in third person option + gFocusMgr.setKeyboardFocus(NULL); - if (camera_enabled) - { - LLViewerObject *reference_object = gObjectList.findObject(object_id); - if (reference_object) - { - //convert to root object relative? - mSitCameraPos = camera_pos; - mSitCameraFocus = camera_focus; - mSitCameraReferenceObject = reference_object; - mSitCameraEnabled = TRUE; - } - } - else - { - mSitCameraPos.clearVec(); - mSitCameraFocus.clearVec(); - mSitCameraReferenceObject = NULL; - mSitCameraEnabled = FALSE; - } -} + LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset); -//----------------------------------------------------------------------------- -// setFocusOnAvatar() -//----------------------------------------------------------------------------- -void LLAgent::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate) -{ - if (focus_on_avatar != mFocusOnAvatar) - { - if (animate) - { - startCameraAnimation(); - } - else + mViewsPushed = TRUE; + + // hide all floaters except the mini map + +#if 0 // Use this once all floaters are registered + std::set exceptions; + exceptions.insert("mini_map"); + LLFloaterReg::hideVisibleInstances(exceptions); +#else // Use this for now + LLFloaterView::skip_list_t skip_list; + skip_list.insert(LLFloaterReg::findInstance("mini_map")); + gFloaterView->pushVisibleAll(FALSE, skip_list); +#endif + + if( gMorphView ) { - stopCameraAnimation(); + gMorphView->setVisible(FALSE); } - } - - //RN: when focused on the avatar, we're not "looking" at it - // looking implies intent while focusing on avatar means - // you're just walking around with a camera on you...eesh. - if (!mFocusOnAvatar && focus_on_avatar) - { - setFocusGlobal(LLVector3d::zero); - mCameraFOVZoomFactor = 0.f; - if (mCameraMode == CAMERA_MODE_THIRD_PERSON) + + gConsole->setVisible( TRUE ); + + if (mAvatarObject.notNull()) { - LLVector3 at_axis; - if (mAvatarObject.notNull() && mAvatarObject->getParent()) + // Trigger mouselook-specific animations + if( mAvatarObject->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) ) { - LLQuaternion obj_rot = ((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation(); - at_axis = LLViewerCamera::getInstance()->getAtAxis(); - at_axis.mV[VZ] = 0.f; - at_axis.normalize(); - resetAxes(at_axis * ~obj_rot); + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != mAvatarObject->mSignaledAnimations.end()) + { + sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_START); + } + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != mAvatarObject->mSignaledAnimations.end()) + { + sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_START); + } + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != mAvatarObject->mSignaledAnimations.end()) + { + sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_START); + } + if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != mAvatarObject->mSignaledAnimations.end()) + { + sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_STOP); + sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_START); + } } - else + if (mAvatarObject->getParent()) { - at_axis = LLViewerCamera::getInstance()->getAtAxis(); - at_axis.mV[VZ] = 0.f; - at_axis.normalize(); - resetAxes(at_axis); + LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis(); + LLViewerObject* root_object = (LLViewerObject*)mAvatarObject->getRoot(); + if (root_object->flagCameraDecoupled()) + { + resetAxes(at_axis); + } + else + { + resetAxes(at_axis * ~((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation()); + } } } + + } + else if (gAgentCamera.mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) + { + LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset); + + if( gMorphView ) + { + gMorphView->setVisible( TRUE ); + } + + // freeze avatar + if (mAvatarObject.notNull()) + { + mPauseRequest = mAvatarObject->requestPause(); + } } - // unlocking camera from avatar - else if (mFocusOnAvatar && !focus_on_avatar) + + if (getAvatarObject()) { - // keep camera focus point consistent, even though it is now unlocked - setFocusGlobal(getPositionGlobal() + calcThirdPersonFocusOffset(), gAgent.getID()); + getAvatarObject()->updateAttachmentVisibility(gAgentCamera.mCameraMode); } - - mFocusOnAvatar = focus_on_avatar; + + gFloaterTools->dirty(); + + // Don't let this be called more than once if the camera + // mode hasn't changed. --JC + gAgentCamera.mLastCameraMode = gAgentCamera.mCameraMode; + } -*/ //----------------------------------------------------------------------------- // heardChat() @@ -4600,7 +2021,7 @@ void LLAgent::heardChat(const LLUUID& id) if (ll_rand(2) == 0) { LLViewerObject *chatter = gObjectList.findObject(mLastChatterID); - gAgentCameraHACK.setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero); + gAgentCamera.setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero); } mLastChatterID = id; @@ -4613,7 +2034,7 @@ void LLAgent::heardChat(const LLUUID& id) void LLAgent::lookAtLastChat() { // Block if camera is animating or not in normal third person camera mode - if (gAgentCameraHACK.mCameraAnimating || !gAgentCameraHACK.cameraThirdPerson()) + if (gAgentCamera.mCameraAnimating || !gAgentCamera.cameraThirdPerson()) { return; } @@ -4637,7 +2058,7 @@ void LLAgent::lookAtLastChat() setControlFlags(AGENT_CONTROL_STOP); - gAgentCameraHACK.changeCameraToThirdPerson(); + gAgentCamera.changeCameraToThirdPerson(); LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition(); LLVector3 left = delta_pos % LLVector3::z_axis; @@ -4649,15 +2070,15 @@ void LLAgent::lookAtLastChat() new_camera_pos += up * 0.2f; if (chatter_av->mHeadp) { - gAgentCameraHACK.setFocusGlobal(getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()), mLastChatterID); - gAgentCameraHACK.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()); + gAgentCamera.setFocusGlobal(getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()), mLastChatterID); + gAgentCamera.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()); } else { - gAgentCameraHACK.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); - gAgentCameraHACK.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); + gAgentCamera.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); + gAgentCamera.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); } - gAgentCameraHACK.setFocusOnAvatar(FALSE, TRUE); + gAgentCamera.setFocusOnAvatar(FALSE, TRUE); } else { @@ -4666,7 +2087,7 @@ void LLAgent::lookAtLastChat() setControlFlags(AGENT_CONTROL_STOP); - gAgentCameraHACK.changeCameraToThirdPerson(); + gAgentCamera.changeCameraToThirdPerson(); LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition(); LLVector3 left = delta_pos % LLVector3::z_axis; @@ -4677,9 +2098,9 @@ void LLAgent::lookAtLastChat() new_camera_pos += left * 0.3f; new_camera_pos += up * 0.2f; - gAgentCameraHACK.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); - gAgentCameraHACK.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); - gAgentCameraHACK.setFocusOnAvatar(FALSE, TRUE); + gAgentCamera.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); + gAgentCamera.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); + gAgentCamera.setFocusOnAvatar(FALSE, TRUE); } } } @@ -5190,7 +2611,7 @@ LLQuaternion LLAgent::getHeadRotation() return LLQuaternion::DEFAULT; } - if (!gAgentCameraHACK.cameraMouselook()) + if (!gAgentCamera.cameraMouselook()) { return mAvatarObject->getRotation(); } @@ -5361,7 +2782,7 @@ void LLAgent::initOriginGlobal(const LLVector3d &origin_global) BOOL LLAgent::leftButtonGrabbed() const { - const BOOL camera_mouse_look = gAgentCameraHACK.cameraMouselook(); + const BOOL camera_mouse_look = gAgentCamera.cameraMouselook(); return (!camera_mouse_look && mControlsTakenCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) || (camera_mouse_look && mControlsTakenCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0) || (!camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) @@ -5833,7 +3254,7 @@ void LLAgent::processAgentCachedTextureResponse(LLMessageSystem *mesgsys, void * return; } - if (gAgentCameraHACK.cameraCustomizeAvatar()) + if (gAgentCamera.cameraCustomizeAvatar()) { // ignore baked textures when in customize mode return; @@ -5990,7 +3411,7 @@ bool LLAgent::teleportCore(bool is_local) // Close all pie menus, deselect land, etc. // Don't change the camera until we know teleport succeeded. JC - gAgentCameraHACK.resetView(FALSE); + gAgentCamera.resetView(FALSE); // local logic LLViewerStats::getInstance()->incStat(LLViewerStats::ST_TELEPORT_COUNT); @@ -6291,7 +3712,7 @@ void LLAgent::sendAgentSetAppearance() { if (mAvatarObject.isNull()) return; - if (gAgentQueryManager.mNumPendingQueries > 0 && !gAgentCameraHACK.cameraCustomizeAvatar()) + if (gAgentQueryManager.mNumPendingQueries > 0 && !gAgentCamera.cameraCustomizeAvatar()) { return; } @@ -6540,9 +3961,7 @@ void LLAgent::renderAutoPilotTarget() } } -/******************************************************************************** - * - */ +/********************************************************************************/ LLAgentQueryManager gAgentQueryManager; -- cgit v1.2.3 From 504cf0870d964de5b286621a44098af6afdf13cd Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Thu, 25 Mar 2010 15:06:48 -0400 Subject: EXT-2959 : Pull out camera functions from llagent to llagentcamera #3 checkin. Took out llagent "friend llagentcamera" and added accessors instead. Did some superficial formatting cleanup. --- indra/newview/llagent.cpp | 99 +---------------------------------------------- 1 file changed, 2 insertions(+), 97 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 5dd4215206..68b5a3401e 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -296,7 +296,6 @@ void LLAgent::cleanup() { mAvatarObject = NULL; mRegionp = NULL; - gAgentCamera.cleanup(); } //----------------------------------------------------------------------------- @@ -1645,24 +1644,8 @@ void LLAgent::setAvatarObject(LLVOAvatarSelf *avatar) llinfos << "Setting LLAgent::mAvatarObject to NULL" << llendl; return; } - - if (!gAgentCamera.mLookAt) - { - gAgentCamera.mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT); - } - if (!gAgentCamera.mPointAt) - { - gAgentCamera.mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT); - } - if (!gAgentCamera.mLookAt.isNull()) - { - gAgentCamera.mLookAt->setSourceObject(avatar); - } - if (!gAgentCamera.mPointAt.isNull()) - { - gAgentCamera.mPointAt->setSourceObject(avatar); - } + gAgentCamera.setCameraAvatarObject(avatar); } // TRUE if your own avatar needs to be rendered. Usually only @@ -1863,8 +1846,7 @@ void LLAgent::endAnimationUpdateUI() } } } - else - if(gAgentCamera.mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) + else if(gAgentCamera.mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) { // make sure we ask to save changes @@ -2028,83 +2010,6 @@ void LLAgent::heardChat(const LLUUID& id) mChatTimer.reset(); } -//----------------------------------------------------------------------------- -// lookAtLastChat() -//----------------------------------------------------------------------------- -void LLAgent::lookAtLastChat() -{ - // Block if camera is animating or not in normal third person camera mode - if (gAgentCamera.mCameraAnimating || !gAgentCamera.cameraThirdPerson()) - { - return; - } - - LLViewerObject *chatter = gObjectList.findObject(mLastChatterID); - if (chatter) - { - LLVector3 delta_pos; - if (chatter->isAvatar()) - { - LLVOAvatar *chatter_av = (LLVOAvatar*)chatter; - if (mAvatarObject.notNull() && chatter_av->mHeadp) - { - delta_pos = chatter_av->mHeadp->getWorldPosition() - mAvatarObject->mHeadp->getWorldPosition(); - } - else - { - delta_pos = chatter->getPositionAgent() - getPositionAgent(); - } - delta_pos.normalize(); - - setControlFlags(AGENT_CONTROL_STOP); - - gAgentCamera.changeCameraToThirdPerson(); - - LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition(); - LLVector3 left = delta_pos % LLVector3::z_axis; - left.normalize(); - LLVector3 up = left % delta_pos; - up.normalize(); - new_camera_pos -= delta_pos * 0.4f; - new_camera_pos += left * 0.3f; - new_camera_pos += up * 0.2f; - if (chatter_av->mHeadp) - { - gAgentCamera.setFocusGlobal(getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()), mLastChatterID); - gAgentCamera.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()); - } - else - { - gAgentCamera.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); - gAgentCamera.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); - } - gAgentCamera.setFocusOnAvatar(FALSE, TRUE); - } - else - { - delta_pos = chatter->getRenderPosition() - getPositionAgent(); - delta_pos.normalize(); - - setControlFlags(AGENT_CONTROL_STOP); - - gAgentCamera.changeCameraToThirdPerson(); - - LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition(); - LLVector3 left = delta_pos % LLVector3::z_axis; - left.normalize(); - LLVector3 up = left % delta_pos; - up.normalize(); - new_camera_pos -= delta_pos * 0.4f; - new_camera_pos += left * 0.3f; - new_camera_pos += up * 0.2f; - - gAgentCamera.setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID); - gAgentCamera.mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal(); - gAgentCamera.setFocusOnAvatar(FALSE, TRUE); - } - } -} - const F32 SIT_POINT_EXTENTS = 0.2f; LLSD ll_sdmap_from_vector3(const LLVector3& vec) -- cgit v1.2.3 From 853d9e44534f568d4a17033c7b8ecbafddf7bd69 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Thu, 25 Mar 2010 17:27:50 -0400 Subject: EXT-6539 : Take out mAvatarObject from LLAgentWearables Removed mAvatarObject / gAgentWearables.mAvatarObject since it's redundant with gAgent.mAvatarObject. --- indra/newview/llagent.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 68b5a3401e..da16136652 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -1645,7 +1645,8 @@ void LLAgent::setAvatarObject(LLVOAvatarSelf *avatar) return; } - gAgentCamera.setCameraAvatarObject(avatar); + gAgentCamera.setAvatarObject(avatar); + gAgentWearables.setAvatarObject(avatar); } // TRUE if your own avatar needs to be rendered. Usually only -- cgit v1.2.3 From 885fc3f9b54cca33e134bcfb65c1d2a9c0aeec7a Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Thu, 25 Mar 2010 19:56:52 -0400 Subject: EXT-6536 : Make LLVOAvatarSelf a singleton Minor superficial cleanup to have all references to getAvatarObject use LLVOAvatarSelf *avatarp = gAgent.getAvatarObject() --- indra/newview/llagent.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index da16136652..7a34112807 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -3260,7 +3260,7 @@ BOOL LLAgent::getHomePosGlobal( LLVector3d* pos_global ) void LLAgent::clearVisualParams(void *data) { - LLVOAvatar* avatarp = gAgent.getAvatarObject(); + LLVOAvatarSelf* avatarp = gAgent.getAvatarObject(); if (avatarp) { avatarp->clearVisualParamWeights(); @@ -3288,7 +3288,7 @@ bool LLAgent::teleportCore(bool is_local) // sync with other viewers. Discuss in DEV-14145/VWR-6744 before reenabling. // Stop all animation before actual teleporting - LLVOAvatar* avatarp = gAgent.getAvatarObject(); + LLVOAvatarSelf* avatarp = gAgent.getAvatarObject(); if (avatarp) { for ( LLVOAvatar::AnimIterator anim_it= avatarp->mPlayingAnimations.begin(); @@ -3491,7 +3491,7 @@ void LLAgent::stopCurrentAnimations() // This function stops all current overriding animations on this // avatar, propagating this change back to the server. - LLVOAvatar* avatarp = gAgent.getAvatarObject(); + LLVOAvatarSelf* avatarp = gAgent.getAvatarObject(); if (avatarp) { for ( LLVOAvatar::AnimIterator anim_it = -- cgit v1.2.3 From 0bcfbde3a4265d7963ea501622e512de8eab7f61 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Fri, 26 Mar 2010 13:58:19 -0400 Subject: EXT-6536 : Make LLVOAvatarSelf a singleton Lots of superficial cleanup, particularly around "if (" formatting. Removed LLAgent as a friend of LLAgentCamera and refactored to use accessors. --- indra/newview/llagent.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 7a34112807..a1b2a9fc44 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -315,7 +315,7 @@ LLAgent::~LLAgent() //----------------------------------------------------------------------------- void LLAgent::onAppFocusGained() { - if (CAMERA_MODE_MOUSELOOK == gAgentCamera.mCameraMode) + if (CAMERA_MODE_MOUSELOOK == gAgentCamera.getCameraMode()) { gAgentCamera.changeCameraToDefault(); LLToolMgr::getInstance()->clearSavedTool(); @@ -952,7 +952,7 @@ LLVector3 LLAgent::getReferenceUpVector() mAvatarObject->getParent() && mAvatarObject->mDrawable.notNull()) { - U32 camera_mode = gAgentCamera.mCameraAnimating ? gAgentCamera.mLastCameraMode : gAgentCamera.mCameraMode; + U32 camera_mode = gAgentCamera.getCameraAnimating() ? gAgentCamera.getLastCameraMode() : gAgentCamera.getCameraMode(); // and in third person... if (camera_mode == CAMERA_MODE_THIRD_PERSON) { @@ -1076,17 +1076,6 @@ void LLAgent::setKey(const S32 direction, S32 &key) //----------------------------------------------------------------------------- U32 LLAgent::getControlFlags() { -/* - // HACK -- avoids maintenance of control flags when camera mode is turned on or off, - // only worries about it when the flags are measured - if (mCameraMode == CAMERA_MODE_MOUSELOOK) - { - if ( !(mControlFlags & AGENT_CONTROL_MOUSELOOK) ) - { - mControlFlags |= AGENT_CONTROL_MOUSELOOK; - } - } -*/ return mControlFlags; } @@ -1768,14 +1757,14 @@ U8 LLAgent::getRenderState() //----------------------------------------------------------------------------- void LLAgent::endAnimationUpdateUI() { - if (gAgentCamera.mCameraMode == gAgentCamera.mLastCameraMode) + if (gAgentCamera.getCameraMode() == gAgentCamera.getLastCameraMode()) { // We're already done endAnimationUpdateUI for this transition. return; } // clean up UI from mode we're leaving - if (gAgentCamera.mLastCameraMode == CAMERA_MODE_MOUSELOOK ) + if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_MOUSELOOK ) { // show mouse cursor gViewerWindow->showCursor(); @@ -1847,7 +1836,7 @@ void LLAgent::endAnimationUpdateUI() } } } - else if(gAgentCamera.mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) + else if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR) { // make sure we ask to save changes @@ -1875,7 +1864,7 @@ void LLAgent::endAnimationUpdateUI() //--------------------------------------------------------------------- // Set up UI for mode we're entering //--------------------------------------------------------------------- - if (gAgentCamera.mCameraMode == CAMERA_MODE_MOUSELOOK) + if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK) { // hide menus gMenuBarView->setVisible(FALSE); @@ -1890,7 +1879,7 @@ void LLAgent::endAnimationUpdateUI() LLPanelStandStopFlying::getInstance()->setVisible(FALSE); // clear out camera lag effect - gAgentCamera.mCameraLag.clearVec(); + gAgentCamera.clearCameraLag(); // JC - Added for always chat in third person option gFocusMgr.setKeyboardFocus(NULL); @@ -1960,7 +1949,7 @@ void LLAgent::endAnimationUpdateUI() } } - else if (gAgentCamera.mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR) + else if (gAgentCamera.getCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR) { LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset); @@ -1978,15 +1967,14 @@ void LLAgent::endAnimationUpdateUI() if (getAvatarObject()) { - getAvatarObject()->updateAttachmentVisibility(gAgentCamera.mCameraMode); + getAvatarObject()->updateAttachmentVisibility(gAgentCamera.getCameraMode()); } gFloaterTools->dirty(); // Don't let this be called more than once if the camera // mode hasn't changed. --JC - gAgentCamera.mLastCameraMode = gAgentCamera.mCameraMode; - + gAgentCamera.updateLastCamera(); } //----------------------------------------------------------------------------- -- cgit v1.2.3 From 94e6e10739c8321b6fb651a109901380ef92975a Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Mon, 29 Mar 2010 12:00:26 -0400 Subject: EXT-6536 : Make LLVOAvatarSelf a singleton Superficial cleanup to replace all instances of "LLVOAvatarSelf *avatarp = gAgent.getAvatarObject" with "gAgentAvatar". --- indra/newview/llagent.cpp | 217 +++++++++++++++++++--------------------------- 1 file changed, 91 insertions(+), 126 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index a1b2a9fc44..645acca4ae 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -159,11 +159,11 @@ bool handleSlowMotionAnimation(const LLSD& newvalue) { if (newvalue.asBoolean()) { - gAgent.getAvatarObject()->setAnimTimeFactor(0.2f); + gAgentAvatar->setAnimTimeFactor(0.2f); } else { - gAgent.getAvatarObject()->setAnimTimeFactor(1.0f); + gAgentAvatar->setAnimTimeFactor(1.0f); } return true; } @@ -207,8 +207,6 @@ LLAgent::LLAgent() : mDistanceTraveled(0.F), mLastPositionGlobal(LLVector3d::zero), - mAvatarObject(NULL), - mRenderState(0), mTypingTimer(), @@ -294,7 +292,6 @@ void LLAgent::init() //----------------------------------------------------------------------------- void LLAgent::cleanup() { - mAvatarObject = NULL; mRegionp = NULL; } @@ -325,12 +322,12 @@ void LLAgent::onAppFocusGained() void LLAgent::ageChat() { - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { // get amount of time since I last chatted - F64 elapsed_time = (F64)mAvatarObject->mChatTimer.getElapsedTimeF32(); + F64 elapsed_time = (F64)gAgentAvatar->mChatTimer.getElapsedTimeF32(); // add in frame time * 3 (so it ages 4x) - mAvatarObject->mChatTimer.setAge(elapsed_time + (F64)gFrameDTClamped * (CHAT_AGE_FAST_RATE - 1.0)); + gAgentAvatar->mChatTimer.setAge(elapsed_time + (F64)gFrameDTClamped * (CHAT_AGE_FAST_RATE - 1.0)); } } @@ -517,20 +514,20 @@ BOOL LLAgent::getFlying() const //----------------------------------------------------------------------------- void LLAgent::setFlying(BOOL fly) { - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { // *HACK: Don't allow to start the flying mode if we got ANIM_AGENT_STANDUP signal // because in this case we won't get a signal to start avatar flying animation and // it will be walking with flying mode "ON" indication. However we allow to switch // the flying mode off if we get ANIM_AGENT_STANDUP signal. See process_avatar_animation(). // See EXT-2781. - if(fly && mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_STANDUP) != mAvatarObject->mSignaledAnimations.end()) + if(fly && gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_STANDUP) != gAgentAvatar->mSignaledAnimations.end()) { return; } // don't allow taking off while sitting - if (fly && mAvatarObject->isSitting()) + if (fly && gAgentAvatar->isSitting()) { return; } @@ -583,9 +580,9 @@ void LLAgent::toggleFlying() bool LLAgent::enableFlying() { BOOL sitting = FALSE; - if (gAgent.getAvatarObject()) + if (isAgentAvatarValid()) { - sitting = gAgent.getAvatarObject()->isSitting(); + sitting = gAgentAvatar->isSitting(); } return !sitting; } @@ -755,9 +752,9 @@ void LLAgent::sendReliableMessage() //----------------------------------------------------------------------------- LLVector3 LLAgent::getVelocity() const { - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { - return mAvatarObject->getVelocity(); + return gAgentAvatar->getVelocity(); } else { @@ -776,13 +773,13 @@ void LLAgent::setPositionAgent(const LLVector3 &pos_agent) llerrs << "setPositionAgent is not a number" << llendl; } - if (mAvatarObject.notNull() && mAvatarObject->getParent()) + if (isAgentAvatarValid() && gAgentAvatar->getParent()) { LLVector3 pos_agent_sitting; LLVector3d pos_agent_d; - LLViewerObject *parent = (LLViewerObject*)mAvatarObject->getParent(); + LLViewerObject *parent = (LLViewerObject*)gAgentAvatar->getParent(); - pos_agent_sitting = mAvatarObject->getPosition() * parent->getRotation() + parent->getPositionAgent(); + pos_agent_sitting = gAgentAvatar->getPosition() * parent->getRotation() + parent->getPositionAgent(); pos_agent_d.setVec(pos_agent_sitting); mFrameAgent.setOrigin(pos_agent_sitting); @@ -803,9 +800,9 @@ void LLAgent::setPositionAgent(const LLVector3 &pos_agent) //----------------------------------------------------------------------------- const LLVector3d &LLAgent::getPositionGlobal() const { - if (mAvatarObject.notNull() && !mAvatarObject->mDrawable.isNull()) + if (isAgentAvatarValid() && !gAgentAvatar->mDrawable.isNull()) { - mPositionGlobal = getPosGlobalFromAgent(mAvatarObject->getRenderPosition()); + mPositionGlobal = getPosGlobalFromAgent(gAgentAvatar->getRenderPosition()); } else { @@ -820,9 +817,9 @@ const LLVector3d &LLAgent::getPositionGlobal() const //----------------------------------------------------------------------------- const LLVector3 &LLAgent::getPositionAgent() { - if(mAvatarObject.notNull() && !mAvatarObject->mDrawable.isNull()) + if (isAgentAvatarValid() && !gAgentAvatar->mDrawable.isNull()) { - mFrameAgent.setOrigin(mAvatarObject->getRenderPosition()); + mFrameAgent.setOrigin(gAgentAvatar->getRenderPosition()); } return mFrameAgent.getOrigin(); @@ -948,21 +945,21 @@ LLVector3 LLAgent::getReferenceUpVector() { // this vector is in the coordinate frame of the avatar's parent object, or the world if none LLVector3 up_vector = LLVector3::z_axis; - if (mAvatarObject.notNull() && - mAvatarObject->getParent() && - mAvatarObject->mDrawable.notNull()) + if (isAgentAvatarValid() && + gAgentAvatar->getParent() && + gAgentAvatar->mDrawable.notNull()) { U32 camera_mode = gAgentCamera.getCameraAnimating() ? gAgentCamera.getLastCameraMode() : gAgentCamera.getCameraMode(); // and in third person... if (camera_mode == CAMERA_MODE_THIRD_PERSON) { // make the up vector point to the absolute +z axis - up_vector = up_vector * ~((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation(); + up_vector = up_vector * ~((LLViewerObject*)gAgentAvatar->getParent())->getRenderRotation(); } else if (camera_mode == CAMERA_MODE_MOUSELOOK) { // make the up vector point to the avatar's +z axis - up_vector = up_vector * mAvatarObject->mDrawable->getRotation(); + up_vector = up_vector * gAgentAvatar->mDrawable->getRotation(); } } @@ -998,7 +995,7 @@ F32 LLAgent::clampPitchToLimits(F32 angle) F32 angle_from_skyward = acos( mFrameAgent.getAtAxis() * skyward ); - if (mAvatarObject.notNull() && mAvatarObject->isSitting()) + if (isAgentAvatarValid() && gAgentAvatar->isSitting()) { look_down_limit = 130.f * DEG_TO_RAD; } @@ -1171,10 +1168,9 @@ void LLAgent::clearAFK() // Gods can sometimes get into away state (via gestures) // without setting the appropriate control flag. JC - LLVOAvatar* av = mAvatarObject; if (mControlFlags & AGENT_CONTROL_AWAY - || (av - && (av->mSignaledAnimations.find(ANIM_AGENT_AWAY) != av->mSignaledAnimations.end()))) + || (isAgentAvatarValid() + && (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AWAY) != gAgentAvatar->mSignaledAnimations.end()))) { sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP); clearControlFlags(AGENT_CONTROL_AWAY); @@ -1235,7 +1231,7 @@ BOOL LLAgent::getBusy() const //----------------------------------------------------------------------------- void LLAgent::startAutoPilotGlobal(const LLVector3d &target_global, const std::string& behavior_name, const LLQuaternion *target_rotation, void (*finish_callback)(BOOL, void *), void *callback_data, F32 stop_distance, F32 rot_threshold) { - if (!gAgent.getAvatarObject()) + if (!isAgentAvatarValid()) { return; } @@ -1296,7 +1292,7 @@ void LLAgent::startAutoPilotGlobal(const LLVector3d &target_global, const std::s LLViewerObject *obj; LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, traceEndPt, targetOnGround, groundNorm, &obj); - F64 target_height = llmax((F64)gAgent.getAvatarObject()->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]); + F64 target_height = llmax((F64)gAgentAvatar->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]); // clamp z value of target to minimum height above ground mAutoPilotTargetGlobal.mdV[VZ] = targetOnGround.mdV[VZ] + target_height; @@ -1396,12 +1392,9 @@ void LLAgent::autoPilot(F32 *delta_yaw) mAutoPilotTargetGlobal = object->getPositionGlobal(); } - if (mAvatarObject.isNull()) - { - return; - } + if (!isAgentAvatarValid()) return; - if (mAvatarObject->mInAir) + if (gAgentAvatar->mInAir) { setFlying(TRUE); } @@ -1477,9 +1470,9 @@ void LLAgent::autoPilot(F32 *delta_yaw) // If we're flying, handle autopilot points above or below you. if (getFlying() && xy_distance < AUTOPILOT_HEIGHT_ADJUST_DISTANCE) { - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { - F64 current_height = mAvatarObject->getPositionGlobal().mdV[VZ]; + F64 current_height = gAgentAvatar->getPositionGlobal().mdV[VZ]; F32 delta_z = (F32)(mAutoPilotTargetGlobal.mdV[VZ] - current_height); F32 slope = delta_z / xy_distance; if (slope > 0.45f && delta_z > 6.f) @@ -1560,9 +1553,9 @@ void LLAgent::propagate(const F32 dt) pitch(PITCH_RATE * mPitchKey * dt); // handle auto-land behavior - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { - BOOL in_air = mAvatarObject->mInAir; + BOOL in_air = gAgentAvatar->mInAir; LLVector3 land_vel = getVelocity(); land_vel.mV[VZ] = 0.f; @@ -1615,29 +1608,6 @@ std::ostream& operator<<(std::ostream &s, const LLAgent &agent) return s; } - -// ------------------- Beginning of legacy LLCamera hack ---------------------- -// This section is included for legacy LLCamera support until -// it is no longer needed. Some legacy code must exist in -// non-legacy functions, and is labeled with "// legacy" comments. - -//----------------------------------------------------------------------------- -// setAvatarObject() -//----------------------------------------------------------------------------- -void LLAgent::setAvatarObject(LLVOAvatarSelf *avatar) -{ - mAvatarObject = avatar; - - if (!avatar) - { - llinfos << "Setting LLAgent::mAvatarObject to NULL" << llendl; - return; - } - - gAgentCamera.setAvatarObject(avatar); - gAgentWearables.setAvatarObject(avatar); -} - // TRUE if your own avatar needs to be rendered. Usually only // in third person and build. //----------------------------------------------------------------------------- @@ -1809,26 +1779,26 @@ void LLAgent::endAnimationUpdateUI() } // Disable mouselook-specific animations - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { - if( mAvatarObject->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) ) + if( gAgentAvatar->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) ) { - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_START); } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_START); } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_START); } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_START); @@ -1847,7 +1817,7 @@ void LLAgent::endAnimationUpdateUI() gMorphView->setVisible( FALSE ); } - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { if(mCustomAnim) { @@ -1907,43 +1877,43 @@ void LLAgent::endAnimationUpdateUI() gConsole->setVisible( TRUE ); - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { // Trigger mouselook-specific animations - if( mAvatarObject->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) ) + if( gAgentAvatar->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) ) { - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_START); } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_START); } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_START); } - if (mAvatarObject->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != mAvatarObject->mSignaledAnimations.end()) + if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != gAgentAvatar->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_START); } } - if (mAvatarObject->getParent()) + if (gAgentAvatar->getParent()) { LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis(); - LLViewerObject* root_object = (LLViewerObject*)mAvatarObject->getRoot(); + LLViewerObject* root_object = (LLViewerObject*)gAgentAvatar->getRoot(); if (root_object->flagCameraDecoupled()) { resetAxes(at_axis); } else { - resetAxes(at_axis * ~((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation()); + resetAxes(at_axis * ~((LLViewerObject*)gAgentAvatar->getParent())->getRenderRotation()); } } } @@ -1959,15 +1929,15 @@ void LLAgent::endAnimationUpdateUI() } // freeze avatar - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { - mPauseRequest = mAvatarObject->requestPause(); + mPauseRequest = gAgentAvatar->requestPause(); } } - if (getAvatarObject()) + if (isAgentAvatarValid()) { - getAvatarObject()->updateAttachmentVisibility(gAgentCamera.getCameraMode()); + gAgentAvatar->updateAttachmentVisibility(gAgentCamera.getCameraMode()); } gFloaterTools->dirty(); @@ -2043,10 +2013,10 @@ void LLAgent::setStartPosition( U32 location_id ) LLVector3 agent_pos = getPositionAgent(); - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { // the z height is at the agent's feet - agent_pos.mV[VZ] -= 0.5f * mAvatarObject->mBodySize.mV[VZ]; + agent_pos.mV[VZ] -= 0.5f * gAgentAvatar->mBodySize.mV[VZ]; } agent_pos.mV[VX] = llclamp( agent_pos.mV[VX], INSET, REGION_WIDTH - INSET ); @@ -2153,7 +2123,7 @@ void LLAgent::onAnimStop(const LLUUID& id) setControlFlags(AGENT_CONTROL_FINISH_ANIM); // now trigger dusting self off animation - if (mAvatarObject.notNull() && !mAvatarObject->mBelowWater && rand() % 3 == 0) + if (isAgentAvatarValid() && !gAgentAvatar->mBelowWater && rand() % 3 == 0) sendAnimationRequest( ANIM_AGENT_BRUSH, ANIM_REQUEST_START ); } else if (id == ANIM_AGENT_PRE_JUMP || id == ANIM_AGENT_LAND || id == ANIM_AGENT_MEDIUM_LAND) @@ -2352,9 +2322,9 @@ void LLAgent::buildFullnameAndTitle(std::string& name) const name.erase(0, name.length()); } - if (mAvatarObject.notNull()) + if (isAgentAvatarValid()) { - name += mAvatarObject->getFullname(); + name += gAgentAvatar->getFullname(); } } @@ -2500,14 +2470,14 @@ BOOL LLAgent::canJoinGroups() const LLQuaternion LLAgent::getHeadRotation() { - if (mAvatarObject.isNull() || !mAvatarObject->mPelvisp || !mAvatarObject->mHeadp) + if (!isAgentAvatarValid() || !gAgentAvatar->mPelvisp || !gAgentAvatar->mHeadp) { return LLQuaternion::DEFAULT; } if (!gAgentCamera.cameraMouselook()) { - return mAvatarObject->getRotation(); + return gAgentAvatar->getRotation(); } // We must be in mouselook @@ -2516,9 +2486,9 @@ LLQuaternion LLAgent::getHeadRotation() LLVector3 left = up % look_dir; LLQuaternion rot(look_dir, left, up); - if (mAvatarObject->getParent()) + if (gAgentAvatar->getParent()) { - rot = rot * ~mAvatarObject->getParent()->getRotation(); + rot = rot * ~gAgentAvatar->getParent()->getRotation(); } return rot; @@ -3141,8 +3111,7 @@ void LLAgent::processAgentCachedTextureResponse(LLMessageSystem *mesgsys, void * { gAgentQueryManager.mNumPendingQueries--; - LLVOAvatarSelf* avatarp = gAgent.getAvatarObject(); - if (!avatarp || avatarp->isDead()) + if (!isAgentAvatarValid() || gAgentAvatar->isDead()) { llwarns << "No avatar for user in cached texture update!" << llendl; return; @@ -3175,27 +3144,27 @@ void LLAgent::processAgentCachedTextureResponse(LLMessageSystem *mesgsys, void * if (texture_id.notNull()) { //llinfos << "Received cached texture " << (U32)texture_index << ": " << texture_id << llendl; - avatarp->setCachedBakedTexture(LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)texture_index), texture_id); - //avatarp->setTETexture( LLVOAvatar::sBakedTextureIndices[texture_index], texture_id ); + gAgentAvatar->setCachedBakedTexture(LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)texture_index), texture_id); + //gAgentAvatar->setTETexture( LLVOAvatar::sBakedTextureIndices[texture_index], texture_id ); gAgentQueryManager.mActiveCacheQueries[texture_index] = 0; num_results++; } else { // no cache of this bake. request upload. - avatarp->requestLayerSetUpload((EBakedTextureIndex)texture_index); + gAgentAvatar->requestLayerSetUpload((EBakedTextureIndex)texture_index); } } } llinfos << "Received cached texture response for " << num_results << " textures." << llendl; - avatarp->updateMeshTextures(); + gAgentAvatar->updateMeshTextures(); if (gAgentQueryManager.mNumPendingQueries == 0) { // RN: not sure why composites are disabled at this point - avatarp->setCompositeUpdatesEnabled(TRUE); + gAgentAvatar->setCompositeUpdatesEnabled(TRUE); gAgent.sendAgentSetAppearance(); } } @@ -3248,11 +3217,10 @@ BOOL LLAgent::getHomePosGlobal( LLVector3d* pos_global ) void LLAgent::clearVisualParams(void *data) { - LLVOAvatarSelf* avatarp = gAgent.getAvatarObject(); - if (avatarp) + if (isAgentAvatarValid()) { - avatarp->clearVisualParamWeights(); - avatarp->updateVisualParams(); + gAgentAvatar->clearVisualParamWeights(); + gAgentAvatar->updateVisualParams(); } } @@ -3276,16 +3244,15 @@ bool LLAgent::teleportCore(bool is_local) // sync with other viewers. Discuss in DEV-14145/VWR-6744 before reenabling. // Stop all animation before actual teleporting - LLVOAvatarSelf* avatarp = gAgent.getAvatarObject(); - if (avatarp) + if (isAgentAvatarValid()) { - for ( LLVOAvatar::AnimIterator anim_it= avatarp->mPlayingAnimations.begin(); - anim_it != avatarp->mPlayingAnimations.end(); + for ( LLVOAvatar::AnimIterator anim_it= gAgentAvatar->mPlayingAnimations.begin(); + anim_it != gAgentAvatar->mPlayingAnimations.end(); ++anim_it) { - avatarp->stopMotion(anim_it->first); + gAgentAvatar->stopMotion(anim_it->first); } - avatarp->processAnimationStateChanges(); + gAgentAvatar->processAnimationStateChanges(); } #endif @@ -3478,13 +3445,11 @@ void LLAgent::stopCurrentAnimations() { // This function stops all current overriding animations on this // avatar, propagating this change back to the server. - - LLVOAvatarSelf* avatarp = gAgent.getAvatarObject(); - if (avatarp) + if (isAgentAvatarValid()) { for ( LLVOAvatar::AnimIterator anim_it = - avatarp->mPlayingAnimations.begin(); - anim_it != avatarp->mPlayingAnimations.end(); + gAgentAvatar->mPlayingAnimations.begin(); + anim_it != gAgentAvatar->mPlayingAnimations.end(); anim_it++) { if (anim_it->first == @@ -3497,7 +3462,7 @@ void LLAgent::stopCurrentAnimations() else { // stop this animation locally - avatarp->stopMotion(anim_it->first, TRUE); + gAgentAvatar->stopMotion(anim_it->first, TRUE); // ...and tell the server to tell everyone. sendAnimationRequest(anim_it->first, ANIM_REQUEST_STOP); } @@ -3604,7 +3569,7 @@ void LLAgent::requestLeaveGodMode() //----------------------------------------------------------------------------- void LLAgent::sendAgentSetAppearance() { - if (mAvatarObject.isNull()) return; + if (!isAgentAvatarValid()) return; if (gAgentQueryManager.mNumPendingQueries > 0 && !gAgentCamera.cameraCustomizeAvatar()) { @@ -3612,7 +3577,7 @@ void LLAgent::sendAgentSetAppearance() } - llinfos << "TAT: Sent AgentSetAppearance: " << mAvatarObject->getBakedStatusForPrintout() << llendl; + llinfos << "TAT: Sent AgentSetAppearance: " << gAgentAvatar->getBakedStatusForPrintout() << llendl; //dumpAvatarTEs( "sendAgentSetAppearance()" ); LLMessageSystem* msg = gMessageSystem; @@ -3626,7 +3591,7 @@ void LLAgent::sendAgentSetAppearance() // NOTE -- when we start correcting all of the other Havok geometry // to compensate for the COLLISION_TOLERANCE ugliness we will have // to tweak this number again - const LLVector3 body_size = mAvatarObject->mBodySize; + const LLVector3 body_size = gAgentAvatar->mBodySize; msg->addVector3Fast(_PREHASH_Size, body_size); // To guard against out of order packets @@ -3636,20 +3601,20 @@ void LLAgent::sendAgentSetAppearance() // is texture data current relative to wearables? // KLW - TAT this will probably need to check the local queue. - BOOL textures_current = mAvatarObject->areTexturesCurrent(); + BOOL textures_current = gAgentAvatar->areTexturesCurrent(); for(U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++ ) { const ETextureIndex texture_index = LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)baked_index); // if we're not wearing a skirt, we don't need the texture to be baked - if (texture_index == TEX_SKIRT_BAKED && !mAvatarObject->isWearingWearableType(WT_SKIRT)) + if (texture_index == TEX_SKIRT_BAKED && !gAgentAvatar->isWearingWearableType(WT_SKIRT)) { continue; } // IMG_DEFAULT_AVATAR means not baked. 0 index should be ignored for baked textures - if (!mAvatarObject->isTextureDefined(texture_index, 0)) + if (!gAgentAvatar->isTextureDefined(texture_index, 0)) { textures_current = FALSE; break; @@ -3687,7 +3652,7 @@ void LLAgent::sendAgentSetAppearance() msg->addU8Fast(_PREHASH_TextureIndex, (U8)texture_index); } msg->nextBlockFast(_PREHASH_ObjectData); - mAvatarObject->sendAppearanceMessage( gMessageSystem ); + gAgentAvatar->sendAppearanceMessage( gMessageSystem ); } else { @@ -3700,9 +3665,9 @@ void LLAgent::sendAgentSetAppearance() S32 transmitted_params = 0; - for (LLViewerVisualParam* param = (LLViewerVisualParam*)mAvatarObject->getFirstVisualParam(); + for (LLViewerVisualParam* param = (LLViewerVisualParam*)gAgentAvatar->getFirstVisualParam(); param; - param = (LLViewerVisualParam*)mAvatarObject->getNextVisualParam()) + param = (LLViewerVisualParam*)gAgentAvatar->getNextVisualParam()) { if (param->getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE) { -- cgit v1.2.3 From 58d76a9ecf83b49e42fabfada27ca20814f93cf3 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Mon, 29 Mar 2010 12:11:51 -0400 Subject: EXT-6536 : Make LLVOAvatarSelf a singleton Superficial cleanup to replace all instances of "gAgentAvatar" with "gAgentAvatarp". --- indra/newview/llagent.cpp | 140 +++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 70 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 645acca4ae..3eeaacf93b 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -159,11 +159,11 @@ bool handleSlowMotionAnimation(const LLSD& newvalue) { if (newvalue.asBoolean()) { - gAgentAvatar->setAnimTimeFactor(0.2f); + gAgentAvatarp->setAnimTimeFactor(0.2f); } else { - gAgentAvatar->setAnimTimeFactor(1.0f); + gAgentAvatarp->setAnimTimeFactor(1.0f); } return true; } @@ -325,9 +325,9 @@ void LLAgent::ageChat() if (isAgentAvatarValid()) { // get amount of time since I last chatted - F64 elapsed_time = (F64)gAgentAvatar->mChatTimer.getElapsedTimeF32(); + F64 elapsed_time = (F64)gAgentAvatarp->mChatTimer.getElapsedTimeF32(); // add in frame time * 3 (so it ages 4x) - gAgentAvatar->mChatTimer.setAge(elapsed_time + (F64)gFrameDTClamped * (CHAT_AGE_FAST_RATE - 1.0)); + gAgentAvatarp->mChatTimer.setAge(elapsed_time + (F64)gFrameDTClamped * (CHAT_AGE_FAST_RATE - 1.0)); } } @@ -521,13 +521,13 @@ void LLAgent::setFlying(BOOL fly) // it will be walking with flying mode "ON" indication. However we allow to switch // the flying mode off if we get ANIM_AGENT_STANDUP signal. See process_avatar_animation(). // See EXT-2781. - if(fly && gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_STANDUP) != gAgentAvatar->mSignaledAnimations.end()) + if(fly && gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_STANDUP) != gAgentAvatarp->mSignaledAnimations.end()) { return; } // don't allow taking off while sitting - if (fly && gAgentAvatar->isSitting()) + if (fly && gAgentAvatarp->isSitting()) { return; } @@ -582,7 +582,7 @@ bool LLAgent::enableFlying() BOOL sitting = FALSE; if (isAgentAvatarValid()) { - sitting = gAgentAvatar->isSitting(); + sitting = gAgentAvatarp->isSitting(); } return !sitting; } @@ -754,7 +754,7 @@ LLVector3 LLAgent::getVelocity() const { if (isAgentAvatarValid()) { - return gAgentAvatar->getVelocity(); + return gAgentAvatarp->getVelocity(); } else { @@ -773,13 +773,13 @@ void LLAgent::setPositionAgent(const LLVector3 &pos_agent) llerrs << "setPositionAgent is not a number" << llendl; } - if (isAgentAvatarValid() && gAgentAvatar->getParent()) + if (isAgentAvatarValid() && gAgentAvatarp->getParent()) { LLVector3 pos_agent_sitting; LLVector3d pos_agent_d; - LLViewerObject *parent = (LLViewerObject*)gAgentAvatar->getParent(); + LLViewerObject *parent = (LLViewerObject*)gAgentAvatarp->getParent(); - pos_agent_sitting = gAgentAvatar->getPosition() * parent->getRotation() + parent->getPositionAgent(); + pos_agent_sitting = gAgentAvatarp->getPosition() * parent->getRotation() + parent->getPositionAgent(); pos_agent_d.setVec(pos_agent_sitting); mFrameAgent.setOrigin(pos_agent_sitting); @@ -800,9 +800,9 @@ void LLAgent::setPositionAgent(const LLVector3 &pos_agent) //----------------------------------------------------------------------------- const LLVector3d &LLAgent::getPositionGlobal() const { - if (isAgentAvatarValid() && !gAgentAvatar->mDrawable.isNull()) + if (isAgentAvatarValid() && !gAgentAvatarp->mDrawable.isNull()) { - mPositionGlobal = getPosGlobalFromAgent(gAgentAvatar->getRenderPosition()); + mPositionGlobal = getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition()); } else { @@ -817,9 +817,9 @@ const LLVector3d &LLAgent::getPositionGlobal() const //----------------------------------------------------------------------------- const LLVector3 &LLAgent::getPositionAgent() { - if (isAgentAvatarValid() && !gAgentAvatar->mDrawable.isNull()) + if (isAgentAvatarValid() && !gAgentAvatarp->mDrawable.isNull()) { - mFrameAgent.setOrigin(gAgentAvatar->getRenderPosition()); + mFrameAgent.setOrigin(gAgentAvatarp->getRenderPosition()); } return mFrameAgent.getOrigin(); @@ -946,20 +946,20 @@ LLVector3 LLAgent::getReferenceUpVector() // this vector is in the coordinate frame of the avatar's parent object, or the world if none LLVector3 up_vector = LLVector3::z_axis; if (isAgentAvatarValid() && - gAgentAvatar->getParent() && - gAgentAvatar->mDrawable.notNull()) + gAgentAvatarp->getParent() && + gAgentAvatarp->mDrawable.notNull()) { U32 camera_mode = gAgentCamera.getCameraAnimating() ? gAgentCamera.getLastCameraMode() : gAgentCamera.getCameraMode(); // and in third person... if (camera_mode == CAMERA_MODE_THIRD_PERSON) { // make the up vector point to the absolute +z axis - up_vector = up_vector * ~((LLViewerObject*)gAgentAvatar->getParent())->getRenderRotation(); + up_vector = up_vector * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation(); } else if (camera_mode == CAMERA_MODE_MOUSELOOK) { // make the up vector point to the avatar's +z axis - up_vector = up_vector * gAgentAvatar->mDrawable->getRotation(); + up_vector = up_vector * gAgentAvatarp->mDrawable->getRotation(); } } @@ -995,7 +995,7 @@ F32 LLAgent::clampPitchToLimits(F32 angle) F32 angle_from_skyward = acos( mFrameAgent.getAtAxis() * skyward ); - if (isAgentAvatarValid() && gAgentAvatar->isSitting()) + if (isAgentAvatarValid() && gAgentAvatarp->isSitting()) { look_down_limit = 130.f * DEG_TO_RAD; } @@ -1170,7 +1170,7 @@ void LLAgent::clearAFK() // without setting the appropriate control flag. JC if (mControlFlags & AGENT_CONTROL_AWAY || (isAgentAvatarValid() - && (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AWAY) != gAgentAvatar->mSignaledAnimations.end()))) + && (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AWAY) != gAgentAvatarp->mSignaledAnimations.end()))) { sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP); clearControlFlags(AGENT_CONTROL_AWAY); @@ -1292,7 +1292,7 @@ void LLAgent::startAutoPilotGlobal(const LLVector3d &target_global, const std::s LLViewerObject *obj; LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, traceEndPt, targetOnGround, groundNorm, &obj); - F64 target_height = llmax((F64)gAgentAvatar->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]); + F64 target_height = llmax((F64)gAgentAvatarp->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]); // clamp z value of target to minimum height above ground mAutoPilotTargetGlobal.mdV[VZ] = targetOnGround.mdV[VZ] + target_height; @@ -1394,7 +1394,7 @@ void LLAgent::autoPilot(F32 *delta_yaw) if (!isAgentAvatarValid()) return; - if (gAgentAvatar->mInAir) + if (gAgentAvatarp->mInAir) { setFlying(TRUE); } @@ -1472,7 +1472,7 @@ void LLAgent::autoPilot(F32 *delta_yaw) { if (isAgentAvatarValid()) { - F64 current_height = gAgentAvatar->getPositionGlobal().mdV[VZ]; + F64 current_height = gAgentAvatarp->getPositionGlobal().mdV[VZ]; F32 delta_z = (F32)(mAutoPilotTargetGlobal.mdV[VZ] - current_height); F32 slope = delta_z / xy_distance; if (slope > 0.45f && delta_z > 6.f) @@ -1555,7 +1555,7 @@ void LLAgent::propagate(const F32 dt) // handle auto-land behavior if (isAgentAvatarValid()) { - BOOL in_air = gAgentAvatar->mInAir; + BOOL in_air = gAgentAvatarp->mInAir; LLVector3 land_vel = getVelocity(); land_vel.mV[VZ] = 0.f; @@ -1781,24 +1781,24 @@ void LLAgent::endAnimationUpdateUI() // Disable mouselook-specific animations if (isAgentAvatarValid()) { - if( gAgentAvatar->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) ) + if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) ) { - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_START); } - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_START); } - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_START); } - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_START); @@ -1880,40 +1880,40 @@ void LLAgent::endAnimationUpdateUI() if (isAgentAvatarValid()) { // Trigger mouselook-specific animations - if( gAgentAvatar->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) ) + if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) ) { - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_START); } - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_START); } - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_START); } - if (gAgentAvatar->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != gAgentAvatar->mSignaledAnimations.end()) + if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != gAgentAvatarp->mSignaledAnimations.end()) { sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_STOP); sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_START); } } - if (gAgentAvatar->getParent()) + if (gAgentAvatarp->getParent()) { LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis(); - LLViewerObject* root_object = (LLViewerObject*)gAgentAvatar->getRoot(); + LLViewerObject* root_object = (LLViewerObject*)gAgentAvatarp->getRoot(); if (root_object->flagCameraDecoupled()) { resetAxes(at_axis); } else { - resetAxes(at_axis * ~((LLViewerObject*)gAgentAvatar->getParent())->getRenderRotation()); + resetAxes(at_axis * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation()); } } } @@ -1931,13 +1931,13 @@ void LLAgent::endAnimationUpdateUI() // freeze avatar if (isAgentAvatarValid()) { - mPauseRequest = gAgentAvatar->requestPause(); + mPauseRequest = gAgentAvatarp->requestPause(); } } if (isAgentAvatarValid()) { - gAgentAvatar->updateAttachmentVisibility(gAgentCamera.getCameraMode()); + gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode()); } gFloaterTools->dirty(); @@ -2016,7 +2016,7 @@ void LLAgent::setStartPosition( U32 location_id ) if (isAgentAvatarValid()) { // the z height is at the agent's feet - agent_pos.mV[VZ] -= 0.5f * gAgentAvatar->mBodySize.mV[VZ]; + agent_pos.mV[VZ] -= 0.5f * gAgentAvatarp->mBodySize.mV[VZ]; } agent_pos.mV[VX] = llclamp( agent_pos.mV[VX], INSET, REGION_WIDTH - INSET ); @@ -2123,7 +2123,7 @@ void LLAgent::onAnimStop(const LLUUID& id) setControlFlags(AGENT_CONTROL_FINISH_ANIM); // now trigger dusting self off animation - if (isAgentAvatarValid() && !gAgentAvatar->mBelowWater && rand() % 3 == 0) + if (isAgentAvatarValid() && !gAgentAvatarp->mBelowWater && rand() % 3 == 0) sendAnimationRequest( ANIM_AGENT_BRUSH, ANIM_REQUEST_START ); } else if (id == ANIM_AGENT_PRE_JUMP || id == ANIM_AGENT_LAND || id == ANIM_AGENT_MEDIUM_LAND) @@ -2324,7 +2324,7 @@ void LLAgent::buildFullnameAndTitle(std::string& name) const if (isAgentAvatarValid()) { - name += gAgentAvatar->getFullname(); + name += gAgentAvatarp->getFullname(); } } @@ -2470,14 +2470,14 @@ BOOL LLAgent::canJoinGroups() const LLQuaternion LLAgent::getHeadRotation() { - if (!isAgentAvatarValid() || !gAgentAvatar->mPelvisp || !gAgentAvatar->mHeadp) + if (!isAgentAvatarValid() || !gAgentAvatarp->mPelvisp || !gAgentAvatarp->mHeadp) { return LLQuaternion::DEFAULT; } if (!gAgentCamera.cameraMouselook()) { - return gAgentAvatar->getRotation(); + return gAgentAvatarp->getRotation(); } // We must be in mouselook @@ -2486,9 +2486,9 @@ LLQuaternion LLAgent::getHeadRotation() LLVector3 left = up % look_dir; LLQuaternion rot(look_dir, left, up); - if (gAgentAvatar->getParent()) + if (gAgentAvatarp->getParent()) { - rot = rot * ~gAgentAvatar->getParent()->getRotation(); + rot = rot * ~gAgentAvatarp->getParent()->getRotation(); } return rot; @@ -3111,7 +3111,7 @@ void LLAgent::processAgentCachedTextureResponse(LLMessageSystem *mesgsys, void * { gAgentQueryManager.mNumPendingQueries--; - if (!isAgentAvatarValid() || gAgentAvatar->isDead()) + if (!isAgentAvatarValid() || gAgentAvatarp->isDead()) { llwarns << "No avatar for user in cached texture update!" << llendl; return; @@ -3144,27 +3144,27 @@ void LLAgent::processAgentCachedTextureResponse(LLMessageSystem *mesgsys, void * if (texture_id.notNull()) { //llinfos << "Received cached texture " << (U32)texture_index << ": " << texture_id << llendl; - gAgentAvatar->setCachedBakedTexture(LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)texture_index), texture_id); - //gAgentAvatar->setTETexture( LLVOAvatar::sBakedTextureIndices[texture_index], texture_id ); + gAgentAvatarp->setCachedBakedTexture(LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)texture_index), texture_id); + //gAgentAvatarp->setTETexture( LLVOAvatar::sBakedTextureIndices[texture_index], texture_id ); gAgentQueryManager.mActiveCacheQueries[texture_index] = 0; num_results++; } else { // no cache of this bake. request upload. - gAgentAvatar->requestLayerSetUpload((EBakedTextureIndex)texture_index); + gAgentAvatarp->requestLayerSetUpload((EBakedTextureIndex)texture_index); } } } llinfos << "Received cached texture response for " << num_results << " textures." << llendl; - gAgentAvatar->updateMeshTextures(); + gAgentAvatarp->updateMeshTextures(); if (gAgentQueryManager.mNumPendingQueries == 0) { // RN: not sure why composites are disabled at this point - gAgentAvatar->setCompositeUpdatesEnabled(TRUE); + gAgentAvatarp->setCompositeUpdatesEnabled(TRUE); gAgent.sendAgentSetAppearance(); } } @@ -3219,8 +3219,8 @@ void LLAgent::clearVisualParams(void *data) { if (isAgentAvatarValid()) { - gAgentAvatar->clearVisualParamWeights(); - gAgentAvatar->updateVisualParams(); + gAgentAvatarp->clearVisualParamWeights(); + gAgentAvatarp->updateVisualParams(); } } @@ -3246,13 +3246,13 @@ bool LLAgent::teleportCore(bool is_local) // Stop all animation before actual teleporting if (isAgentAvatarValid()) { - for ( LLVOAvatar::AnimIterator anim_it= gAgentAvatar->mPlayingAnimations.begin(); - anim_it != gAgentAvatar->mPlayingAnimations.end(); + for ( LLVOAvatar::AnimIterator anim_it= gAgentAvatarp->mPlayingAnimations.begin(); + anim_it != gAgentAvatarp->mPlayingAnimations.end(); ++anim_it) { - gAgentAvatar->stopMotion(anim_it->first); + gAgentAvatarp->stopMotion(anim_it->first); } - gAgentAvatar->processAnimationStateChanges(); + gAgentAvatarp->processAnimationStateChanges(); } #endif @@ -3448,8 +3448,8 @@ void LLAgent::stopCurrentAnimations() if (isAgentAvatarValid()) { for ( LLVOAvatar::AnimIterator anim_it = - gAgentAvatar->mPlayingAnimations.begin(); - anim_it != gAgentAvatar->mPlayingAnimations.end(); + gAgentAvatarp->mPlayingAnimations.begin(); + anim_it != gAgentAvatarp->mPlayingAnimations.end(); anim_it++) { if (anim_it->first == @@ -3462,7 +3462,7 @@ void LLAgent::stopCurrentAnimations() else { // stop this animation locally - gAgentAvatar->stopMotion(anim_it->first, TRUE); + gAgentAvatarp->stopMotion(anim_it->first, TRUE); // ...and tell the server to tell everyone. sendAnimationRequest(anim_it->first, ANIM_REQUEST_STOP); } @@ -3577,7 +3577,7 @@ void LLAgent::sendAgentSetAppearance() } - llinfos << "TAT: Sent AgentSetAppearance: " << gAgentAvatar->getBakedStatusForPrintout() << llendl; + llinfos << "TAT: Sent AgentSetAppearance: " << gAgentAvatarp->getBakedStatusForPrintout() << llendl; //dumpAvatarTEs( "sendAgentSetAppearance()" ); LLMessageSystem* msg = gMessageSystem; @@ -3591,7 +3591,7 @@ void LLAgent::sendAgentSetAppearance() // NOTE -- when we start correcting all of the other Havok geometry // to compensate for the COLLISION_TOLERANCE ugliness we will have // to tweak this number again - const LLVector3 body_size = gAgentAvatar->mBodySize; + const LLVector3 body_size = gAgentAvatarp->mBodySize; msg->addVector3Fast(_PREHASH_Size, body_size); // To guard against out of order packets @@ -3601,20 +3601,20 @@ void LLAgent::sendAgentSetAppearance() // is texture data current relative to wearables? // KLW - TAT this will probably need to check the local queue. - BOOL textures_current = gAgentAvatar->areTexturesCurrent(); + BOOL textures_current = gAgentAvatarp->areTexturesCurrent(); for(U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++ ) { const ETextureIndex texture_index = LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)baked_index); // if we're not wearing a skirt, we don't need the texture to be baked - if (texture_index == TEX_SKIRT_BAKED && !gAgentAvatar->isWearingWearableType(WT_SKIRT)) + if (texture_index == TEX_SKIRT_BAKED && !gAgentAvatarp->isWearingWearableType(WT_SKIRT)) { continue; } // IMG_DEFAULT_AVATAR means not baked. 0 index should be ignored for baked textures - if (!gAgentAvatar->isTextureDefined(texture_index, 0)) + if (!gAgentAvatarp->isTextureDefined(texture_index, 0)) { textures_current = FALSE; break; @@ -3652,7 +3652,7 @@ void LLAgent::sendAgentSetAppearance() msg->addU8Fast(_PREHASH_TextureIndex, (U8)texture_index); } msg->nextBlockFast(_PREHASH_ObjectData); - gAgentAvatar->sendAppearanceMessage( gMessageSystem ); + gAgentAvatarp->sendAppearanceMessage( gMessageSystem ); } else { @@ -3665,9 +3665,9 @@ void LLAgent::sendAgentSetAppearance() S32 transmitted_params = 0; - for (LLViewerVisualParam* param = (LLViewerVisualParam*)gAgentAvatar->getFirstVisualParam(); + for (LLViewerVisualParam* param = (LLViewerVisualParam*)gAgentAvatarp->getFirstVisualParam(); param; - param = (LLViewerVisualParam*)gAgentAvatar->getNextVisualParam()) + param = (LLViewerVisualParam*)gAgentAvatarp->getNextVisualParam()) { if (param->getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE) { -- cgit v1.2.3 From b15e34b94207c52d81e310f962e72f4d8030bd94 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 30 Mar 2010 14:21:20 -0400 Subject: EXT-6630 : INFRASTRUCTURE: Pull out -Keys functions from llagent into llagentcamera Orbit/Pan keys were already in llagentcamera. Pulled alt/walk/left/up/yaw/pitch into llagentcamera. --- indra/newview/llagent.cpp | 67 ++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 50 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 3eeaacf93b..0215dc1309 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -218,13 +218,6 @@ LLAgent::LLAgent() : mIsBusy(FALSE), - mAtKey(0), // Either 1, 0, or -1... indicates that movement-key is pressed - mWalkKey(0), // like AtKey, but causes less forward thrust - mLeftKey(0), - mUpKey(0), - mYawKey(0.f), - mPitchKey(0.f), - mControlFlags(0x00000000), mbFlagsDirty(FALSE), mbFlagsNeedReset(FALSE), @@ -339,7 +332,7 @@ void LLAgent::moveAt(S32 direction, bool reset) // age chat timer so it fades more quickly when you are intentionally moving ageChat(); - setKey(direction, mAtKey); + gAgentCamera.setAtKey(LLAgentCamera::directionToKey(direction)); if (direction > 0) { @@ -364,7 +357,7 @@ void LLAgent::moveAtNudge(S32 direction) // age chat timer so it fades more quickly when you are intentionally moving ageChat(); - setKey(direction, mWalkKey); + gAgentCamera.setWalkKey(LLAgentCamera::directionToKey(direction)); if (direction > 0) { @@ -386,7 +379,7 @@ void LLAgent::moveLeft(S32 direction) // age chat timer so it fades more quickly when you are intentionally moving ageChat(); - setKey(direction, mLeftKey); + gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction)); if (direction > 0) { @@ -408,7 +401,7 @@ void LLAgent::moveLeftNudge(S32 direction) // age chat timer so it fades more quickly when you are intentionally moving ageChat(); - setKey(direction, mLeftKey); + gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction)); if (direction > 0) { @@ -430,7 +423,7 @@ void LLAgent::moveUp(S32 direction) // age chat timer so it fades more quickly when you are intentionally moving ageChat(); - setKey(direction, mUpKey); + gAgentCamera.setUpKey(LLAgentCamera::directionToKey(direction)); if (direction > 0) { @@ -449,7 +442,7 @@ void LLAgent::moveUp(S32 direction) //----------------------------------------------------------------------------- void LLAgent::moveYaw(F32 mag, bool reset_view) { - mYawKey = mag; + gAgentCamera.setYawKey(mag); if (mag > 0) { @@ -471,7 +464,7 @@ void LLAgent::moveYaw(F32 mag, bool reset_view) //----------------------------------------------------------------------------- void LLAgent::movePitch(F32 mag) { - mPitchKey = mag; + gAgentCamera.setPitchKey(mag); if (mag > 0) { @@ -1048,26 +1041,6 @@ LLQuaternion LLAgent::getQuat() const return mFrameAgent.getQuaternion(); } -//----------------------------------------------------------------------------- -// setKey() -//----------------------------------------------------------------------------- -void LLAgent::setKey(const S32 direction, S32 &key) -{ - if (direction > 0) - { - key = 1; - } - else if (direction < 0) - { - key = -1; - } - else - { - key = 0; - } -} - - //----------------------------------------------------------------------------- // getControlFlags() //----------------------------------------------------------------------------- @@ -1537,20 +1510,20 @@ void LLAgent::propagate(const F32 dt) LLFloaterMove *floater_move = LLFloaterReg::findTypedInstance("moveview"); if (floater_move) { - floater_move->mForwardButton ->setToggleState( mAtKey > 0 || mWalkKey > 0 ); - floater_move->mBackwardButton ->setToggleState( mAtKey < 0 || mWalkKey < 0 ); - floater_move->mTurnLeftButton ->setToggleState( mYawKey > 0.f ); - floater_move->mTurnRightButton ->setToggleState( mYawKey < 0.f ); - floater_move->mMoveUpButton ->setToggleState( mUpKey > 0 ); - floater_move->mMoveDownButton ->setToggleState( mUpKey < 0 ); + floater_move->mForwardButton ->setToggleState( gAgentCamera.getAtKey() > 0 || gAgentCamera.getWalkKey() > 0 ); + floater_move->mBackwardButton ->setToggleState( gAgentCamera.getAtKey() < 0 || gAgentCamera.getWalkKey() < 0 ); + floater_move->mTurnLeftButton ->setToggleState( gAgentCamera.getYawKey() > 0.f ); + floater_move->mTurnRightButton ->setToggleState( gAgentCamera.getYawKey() < 0.f ); + floater_move->mMoveUpButton ->setToggleState( gAgentCamera.getUpKey() > 0 ); + floater_move->mMoveDownButton ->setToggleState( gAgentCamera.getUpKey() < 0 ); } // handle rotation based on keyboard levels const F32 YAW_RATE = 90.f * DEG_TO_RAD; // radians per second - yaw(YAW_RATE * mYawKey * dt); + yaw(YAW_RATE * gAgentCamera.getYawKey() * dt); const F32 PITCH_RATE = 90.f * DEG_TO_RAD; // radians per second - pitch(PITCH_RATE * mPitchKey * dt); + pitch(PITCH_RATE * gAgentCamera.getPitchKey() * dt); // handle auto-land behavior if (isAgentAvatarValid()) @@ -1560,7 +1533,7 @@ void LLAgent::propagate(const F32 dt) land_vel.mV[VZ] = 0.f; if (!in_air - && mUpKey < 0 + && gAgentCamera.getUpKey() < 0 && land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED && gSavedSettings.getBOOL("AutomaticFly")) { @@ -1569,13 +1542,7 @@ void LLAgent::propagate(const F32 dt) } } - // clear keys - mAtKey = 0; - mWalkKey = 0; - mLeftKey = 0; - mUpKey = 0; - mYawKey = 0.f; - mPitchKey = 0.f; + gAgentCamera.clearGeneralKeys(); } //----------------------------------------------------------------------------- -- cgit v1.2.3 From b0d2cd38f0fe0ba6c63141259062f2552f817145 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 30 Mar 2010 15:21:53 -0400 Subject: EXT-6634 : INFRASTRUCTURE: Generic header file / #include cleanup LLAgent.* cleanup Also took out some constants from llagent.cpp that aren't being used. --- indra/newview/llagent.cpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'indra/newview/llagent.cpp') diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 0215dc1309..69d4bba16d 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -44,7 +44,6 @@ #include "llcallingcard.h" #include "llchannelmanager.h" #include "llconsole.h" -//#include "llfirstuse.h" #include "llfloatercamera.h" #include "llfloatercustomize.h" #include "llfloaterreg.h" @@ -90,41 +89,18 @@ const BOOL ANIMATE = TRUE; const U8 AGENT_STATE_TYPING = 0x04; const U8 AGENT_STATE_EDITING = 0x10; -//drone wandering constants -const F32 MAX_WANDER_TIME = 20.f; // seconds -const F32 MAX_HEADING_HALF_ERROR = 0.2f; // radians -const F32 WANDER_MAX_SLEW_RATE = 2.f * DEG_TO_RAD; // radians / frame -const F32 WANDER_TARGET_MIN_DISTANCE = 10.f; // meters - // Autopilot constants -const F32 AUTOPILOT_HEADING_HALF_ERROR = 10.f * DEG_TO_RAD; // radians -const F32 AUTOPILOT_MAX_SLEW_RATE = 1.f * DEG_TO_RAD; // radians / frame -const F32 AUTOPILOT_STOP_DISTANCE = 2.f; // meters const F32 AUTOPILOT_HEIGHT_ADJUST_DISTANCE = 8.f; // meters const F32 AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND = 1.f; // meters const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS = 1.5f; // seconds -// face editing constants -const LLVector3d FACE_EDIT_CAMERA_OFFSET(0.4f, -0.05f, 0.07f); -const LLVector3d FACE_EDIT_TARGET_OFFSET(0.f, 0.f, 0.05f); - -const F32 METERS_PER_WHEEL_CLICK = 1.f; - -const F32 MAX_TIME_DELTA = 1.f; +const F32 MAX_VELOCITY_AUTO_LAND_SQUARED = 4.f * 4.f; +const F64 CHAT_AGE_FAST_RATE = 3.0; // fidget constants const F32 MIN_FIDGET_TIME = 8.f; // seconds const F32 MAX_FIDGET_TIME = 20.f; // seconds -const S32 MAX_NUM_CHAT_POSITIONS = 10; - -const F32 MAX_VELOCITY_AUTO_LAND_SQUARED = 4.f * 4.f; - -const F32 MAX_FOCUS_OFFSET = 20.f; - -const F32 MIN_RADIUS_ALPHA_SIZZLE = 0.5f; - -const F64 CHAT_AGE_FAST_RATE = 3.0; // The agent instance. LLAgent gAgent; -- cgit v1.2.3