summaryrefslogtreecommitdiff
path: root/indra/newview/llagentcamera.cpp
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2020-05-19 22:37:41 +0300
committerAndrey Lihatskiy <alihatskiy@productengine.com>2020-05-19 22:37:41 +0300
commitaaaf3189c400e491c6adc533f8b03dfecddb1dd9 (patch)
tree57872267bb777945a568574ee19bcda578738d76 /indra/newview/llagentcamera.cpp
parent847cce915dd54166ca3b4fd6bfb8b3c697433abf (diff)
parentb86fdf1c316a49bab69d7ef6b3751565bedf8f59 (diff)
Merge branch 'DRTVWR-501-maint' into DRTVWR-503-maint
Diffstat (limited to 'indra/newview/llagentcamera.cpp')
-rw-r--r--indra/newview/llagentcamera.cpp168
1 files changed, 126 insertions, 42 deletions
diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp
index 26b60b89f5..672104dd70 100644
--- a/indra/newview/llagentcamera.cpp
+++ b/indra/newview/llagentcamera.cpp
@@ -184,6 +184,9 @@ LLAgentCamera::LLAgentCamera() :
clearGeneralKeys();
clearOrbitKeys();
clearPanKeys();
+
+ resetPanDiff();
+ resetOrbitDiff();
}
// Requires gSavedSettings to be initialized.
@@ -205,15 +208,10 @@ void LLAgentCamera::init()
mCameraFocusOffsetTarget = LLVector4(gSavedSettings.getVector3("CameraOffsetBuild"));
- mCameraPreset = (ECameraPreset) gSavedSettings.getU32("CameraPreset");
-
- mCameraOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getControl("CameraOffsetRearView");
- mCameraOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getControl("CameraOffsetFrontView");
- mCameraOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getControl("CameraOffsetGroupView");
+ mCameraPreset = (ECameraPreset) gSavedSettings.getU32("CameraPresetType");
- mFocusOffsetInitial[CAMERA_PRESET_REAR_VIEW] = gSavedSettings.getControl("FocusOffsetRearView");
- mFocusOffsetInitial[CAMERA_PRESET_FRONT_VIEW] = gSavedSettings.getControl("FocusOffsetFrontView");
- mFocusOffsetInitial[CAMERA_PRESET_GROUP_VIEW] = gSavedSettings.getControl("FocusOffsetGroupView");
+ mCameraOffsetInitial = gSavedSettings.getControl("CameraOffsetRearView");
+ mFocusOffsetInitial = gSavedSettings.getControl("FocusOffsetRearView");
mCameraCollidePlane.clearVec();
mCurrentCameraDistance = getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale");
@@ -353,7 +351,8 @@ void LLAgentCamera::resetView(BOOL reset_camera, BOOL change_camera)
mCameraFOVZoomFactor = 0.f;
}
-
+ resetPanDiff();
+ resetOrbitDiff();
mHUDTargetZoom = 1.f;
if (LLSelectMgr::getInstance()->mAllowSelectAvatar)
@@ -735,7 +734,7 @@ BOOL LLAgentCamera::calcCameraMinDistance(F32 &obj_min_distance)
return TRUE;
}
-F32 LLAgentCamera::getCameraZoomFraction()
+F32 LLAgentCamera::getCameraZoomFraction(bool get_third_person)
{
// 0.f -> camera zoomed all the way out
// 1.f -> camera zoomed all the way in
@@ -745,7 +744,7 @@ F32 LLAgentCamera::getCameraZoomFraction()
// already [0,1]
return mHUDTargetZoom;
}
- else if (mFocusOnAvatar && cameraThirdPerson())
+ else if (get_third_person || (mFocusOnAvatar && cameraThirdPerson()))
{
return clamp_rescale(mCameraZoomFraction, MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION, 1.f, 0.f);
}
@@ -807,13 +806,16 @@ void LLAgentCamera::setCameraZoomFraction(F32 fraction)
if (mFocusObject.notNull())
{
- if (mFocusObject->isAvatar())
+ if (mFocusObject.notNull())
{
- min_zoom = AVATAR_MIN_ZOOM;
- }
- else
- {
- min_zoom = OBJECT_MIN_ZOOM;
+ if (mFocusObject->isAvatar())
+ {
+ min_zoom = AVATAR_MIN_ZOOM;
+ }
+ else
+ {
+ min_zoom = OBJECT_MIN_ZOOM;
+ }
}
}
@@ -847,6 +849,7 @@ void LLAgentCamera::cameraOrbitAround(const F32 radians)
}
else
{
+ mOrbitAroundRadians += radians;
mCameraFocusOffsetTarget.rotVec(radians, 0.f, 0.f, 1.f);
cameraZoomIn(1.f);
@@ -878,12 +881,34 @@ void LLAgentCamera::cameraOrbitOver(const F32 angle)
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);
+ mOrbitOverAngle += angle_from_up - new_angle;
mCameraFocusOffsetTarget.rotVec(angle_from_up - new_angle, left_axis);
cameraZoomIn(1.f);
}
}
+void LLAgentCamera::resetCameraOrbit()
+{
+ LLVector3 camera_offset_unit(mCameraFocusOffsetTarget);
+ camera_offset_unit.normalize();
+
+ LLVector3d left_axis;
+ left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
+ mCameraFocusOffsetTarget.rotVec(-mOrbitOverAngle, left_axis);
+
+ mCameraFocusOffsetTarget.rotVec(-mOrbitAroundRadians, 0.f, 0.f, 1.f);
+
+ cameraZoomIn(1.f);
+ resetOrbitDiff();
+}
+
+void LLAgentCamera::resetOrbitDiff()
+{
+ mOrbitAroundRadians = 0;
+ mOrbitOverAngle = 0;
+}
+
//-----------------------------------------------------------------------------
// cameraZoomIn()
//-----------------------------------------------------------------------------
@@ -1022,6 +1047,8 @@ void LLAgentCamera::cameraPanIn(F32 meters)
LLVector3d at_axis;
at_axis.setVec(LLViewerCamera::getInstance()->getAtAxis());
+ mPanFocusDiff += meters * at_axis;
+
mFocusTargetGlobal += meters * at_axis;
mFocusGlobal = mFocusTargetGlobal;
// don't enforce zoom constraints as this is the only way for users to get past them easily
@@ -1038,6 +1065,8 @@ void LLAgentCamera::cameraPanLeft(F32 meters)
LLVector3d left_axis;
left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
+ mPanFocusDiff += meters * left_axis;
+
mFocusTargetGlobal += meters * left_axis;
mFocusGlobal = mFocusTargetGlobal;
@@ -1058,6 +1087,8 @@ void LLAgentCamera::cameraPanUp(F32 meters)
LLVector3d up_axis;
up_axis.setVec(LLViewerCamera::getInstance()->getUpAxis());
+ mPanFocusDiff += meters * up_axis;
+
mFocusTargetGlobal += meters * up_axis;
mFocusGlobal = mFocusTargetGlobal;
@@ -1070,6 +1101,26 @@ void LLAgentCamera::cameraPanUp(F32 meters)
mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
}
+void LLAgentCamera::resetCameraPan()
+{
+ mFocusTargetGlobal -= mPanFocusDiff;
+
+ mFocusGlobal = mFocusTargetGlobal;
+ mCameraSmoothingStop = true;
+
+ cameraZoomIn(1.f);
+ updateFocusOffset();
+
+ mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
+
+ resetPanDiff();
+}
+
+void LLAgentCamera::resetPanDiff()
+{
+ mPanFocusDiff.clear();
+}
+
//-----------------------------------------------------------------------------
// updateLookAt()
//-----------------------------------------------------------------------------
@@ -1621,7 +1672,7 @@ LLVector3d LLAgentCamera::calcThirdPersonFocusOffset()
agent_rot *= ((LLViewerObject*)(gAgentAvatarp->getParent()))->getRenderRotation();
}
- focus_offset = convert_from_llsd<LLVector3d>(mFocusOffsetInitial[mCameraPreset]->get(), TYPE_VEC3D, "");
+ focus_offset = convert_from_llsd<LLVector3d>(mFocusOffsetInitial->get(), TYPE_VEC3D, "");
return focus_offset * agent_rot;
}
@@ -1696,7 +1747,7 @@ LLVector3d LLAgentCamera::calcCameraPositionTargetGlobal(BOOL *hit_limit)
F32 camera_land_height;
LLVector3d frame_center_global = !isAgentAvatarValid() ?
gAgent.getPositionGlobal() :
- gAgent.getPosGlobalFromAgent(gAgentAvatarp->mRoot->getWorldPosition());
+ gAgent.getPosGlobalFromAgent(getAvatarRootPosition());
BOOL isConstrained = FALSE;
LLVector3d head_offset;
@@ -1770,7 +1821,7 @@ LLVector3d LLAgentCamera::calcCameraPositionTargetGlobal(BOOL *hit_limit)
at_axis.mV[VZ] = 0.f;
at_axis.normalize();
gAgent.resetAxes(at_axis * ~parent_rot);
-
+
local_camera_offset = local_camera_offset * gAgent.getFrameAgent().getQuaternion() * parent_rot;
}
else
@@ -1951,9 +2002,38 @@ LLVector3d LLAgentCamera::calcCameraPositionTargetGlobal(BOOL *hit_limit)
}
+LLVector3 LLAgentCamera::getCurrentCameraOffset()
+{
+ return (LLViewerCamera::getInstance()->getOrigin() - getAvatarRootPosition() - mThirdPersonHeadOffset) * ~getCurrentAvatarRotation();
+}
+
+LLVector3d LLAgentCamera::getCurrentFocusOffset()
+{
+ return (mFocusTargetGlobal - gAgent.getPositionGlobal()) * ~getCurrentAvatarRotation();
+}
+
+LLQuaternion LLAgentCamera::getCurrentAvatarRotation()
+{
+ LLViewerObject* sit_object = (LLViewerObject*)gAgentAvatarp->getParent();
+
+ LLQuaternion av_rot = gAgent.getFrameAgent().getQuaternion();
+ LLQuaternion obj_rot = sit_object ? sit_object->getRenderRotation() : LLQuaternion::DEFAULT;
+ return av_rot * obj_rot;
+}
+
+bool LLAgentCamera::isJoystickCameraUsed()
+{
+ return ((mOrbitAroundRadians != 0) || (mOrbitOverAngle != 0) || !mPanFocusDiff.isNull());
+}
+
LLVector3 LLAgentCamera::getCameraOffsetInitial()
{
- return convert_from_llsd<LLVector3>(mCameraOffsetInitial[mCameraPreset]->get(), TYPE_VEC3, "");
+ return convert_from_llsd<LLVector3>(mCameraOffsetInitial->get(), TYPE_VEC3, "");
+}
+
+LLVector3d LLAgentCamera::getFocusOffsetInitial()
+{
+ return convert_from_llsd<LLVector3d>(mFocusOffsetInitial->get(), TYPE_VEC3D, "");
}
F32 LLAgentCamera::getCameraMaxZoomDistance()
@@ -1964,6 +2044,12 @@ F32 LLAgentCamera::getCameraMaxZoomDistance()
LLWorld::getInstance()->getRegionWidthInMeters() - CAMERA_FUDGE_FROM_OBJECT);
}
+LLVector3 LLAgentCamera::getAvatarRootPosition()
+{
+ static LLCachedControl<bool> use_hover_height(gSavedSettings, "HoverHeightAffectsCamera");
+ return use_hover_height ? gAgentAvatarp->mRoot->getWorldPosition() : gAgentAvatarp->mRoot->getWorldPosition() - gAgentAvatarp->getHoverOffset();
+
+}
//-----------------------------------------------------------------------------
// handleScrollWheel()
//-----------------------------------------------------------------------------
@@ -2243,15 +2329,7 @@ void LLAgentCamera::changeCameraToThirdPerson(BOOL animate)
}
// Remove any pitch from the avatar
- if (isAgentAvatarValid() && gAgentAvatarp->getParent())
- {
- LLQuaternion obj_rot = ((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
- at_axis = LLViewerCamera::getInstance()->getAtAxis();
- at_axis.mV[VZ] = 0.f;
- at_axis.normalize();
- gAgent.resetAxes(at_axis * ~obj_rot);
- }
- else
+ if (!isAgentAvatarValid() || !gAgentAvatarp->getParent())
{
at_axis = gAgent.getFrameAgent().getAtAxis();
at_axis.mV[VZ] = 0.f;
@@ -2350,7 +2428,10 @@ void LLAgentCamera::switchCameraPreset(ECameraPreset preset)
mCameraPreset = preset;
- gSavedSettings.setU32("CameraPreset", mCameraPreset);
+ resetPanDiff();
+ resetOrbitDiff();
+
+ gSavedSettings.setU32("CameraPresetType", mCameraPreset);
}
@@ -2595,7 +2676,7 @@ void LLAgentCamera::setSitCamera(const LLUUID &object_id, const LLVector3 &camer
//-----------------------------------------------------------------------------
// setFocusOnAvatar()
//-----------------------------------------------------------------------------
-void LLAgentCamera::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate)
+void LLAgentCamera::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate, BOOL reset_axes)
{
if (focus_on_avatar != mFocusOnAvatar)
{
@@ -2612,22 +2693,14 @@ void LLAgentCamera::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate)
//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)
+ if (!mFocusOnAvatar && focus_on_avatar && reset_axes)
{
setFocusGlobal(LLVector3d::zero);
mCameraFOVZoomFactor = 0.f;
if (mCameraMode == CAMERA_MODE_THIRD_PERSON)
{
LLVector3 at_axis;
- if (isAgentAvatarValid() && gAgentAvatarp->getParent())
- {
- LLQuaternion obj_rot = ((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
- at_axis = LLViewerCamera::getInstance()->getAtAxis();
- at_axis.mV[VZ] = 0.f;
- at_axis.normalize();
- gAgent.resetAxes(at_axis * ~obj_rot);
- }
- else
+ if (!isAgentAvatarValid() || !gAgentAvatarp->getParent())
{
at_axis = LLViewerCamera::getInstance()->getAtAxis();
at_axis.mV[VZ] = 0.f;
@@ -2775,6 +2848,17 @@ BOOL LLAgentCamera::setPointAt(EPointAtType target_type, LLViewerObject *object,
return mPointAt->setPointAt(target_type, object, position);
}
+void LLAgentCamera::rotateToInitSitRot()
+{
+ gAgent.rotate(~gAgent.getFrameAgent().getQuaternion());
+ gAgent.rotate(mInitSitRot);
+}
+
+void LLAgentCamera::resetCameraZoomFraction()
+{
+ mCameraZoomFraction = INITIAL_ZOOM_FRACTION;
+}
+
ELookAtType LLAgentCamera::getLookAtType()
{
if (mLookAt)