SL-12904 FIXED Camera Preset does not restore correctly when sitting

meow-7.2.2
Mnikolenko Productengine 2020-04-20 14:27:22 +03:00
parent 70d340a1bf
commit 74d6e6b65c
15 changed files with 232 additions and 8 deletions

View File

@ -28,6 +28,7 @@
#define LLQUATERNION_H
#include <iostream>
#include <llsd.h>
#ifndef LLMATH_H //enforce specific include order to avoid tangling inline dependencies
#error "Please include llmath.h first."
@ -64,6 +65,29 @@ public:
const LLVector3 &y_axis,
const LLVector3 &z_axis); // Initializes Quaternion from Matrix3 = [x_axis ; y_axis ; z_axis]
explicit LLQuaternion(const LLSD& sd)
{
setValue(sd);
}
void setValue(const LLSD& sd)
{
mQ[VX] = (F32) sd[0].asReal();
mQ[VY] = (F32) sd[1].asReal();
mQ[VZ] = (F32) sd[2].asReal();
mQ[VS] = (F32) sd[3].asReal();
}
LLSD getValue() const
{
LLSD ret;
ret[0] = mQ[VX];
ret[1] = mQ[VY];
ret[2] = mQ[VZ];
ret[3] = mQ[VS];
return ret;
}
BOOL isIdentity() const;
BOOL isNotIdentity() const;
BOOL isFinite() const; // checks to see if all values of LLQuaternion are finite

View File

@ -40,6 +40,7 @@
#include "v4coloru.h"
#include "v4color.h"
#include "v3color.h"
#include "llquaternion.h"
#include "llrect.h"
#include "llxmltree.h"
#include "llsdserialize.h"
@ -125,6 +126,9 @@ bool LLControlVariable::llsd_compare(const LLSD& a, const LLSD & b)
case TYPE_VEC3D:
result = LLVector3d(a) == LLVector3d(b);
break;
case TYPE_QUAT:
result = LLQuaternion(a) == LLQuaternion(b);
break;
case TYPE_RECT:
result = LLRect(a) == LLRect(b);
break;
@ -361,6 +365,7 @@ const std::string LLControlGroup::mTypeString[TYPE_COUNT] = { "U32"
,"String"
,"Vector3"
,"Vector3D"
,"Quaternion"
,"Rect"
,"Color4"
,"Color3"
@ -523,6 +528,11 @@ LLControlVariable* LLControlGroup::declareVec3d(const std::string& name, const L
return declareControl(name, TYPE_VEC3D, initial_val.getValue(), comment, persist);
}
LLControlVariable* LLControlGroup::declareQuat(const std::string& name, const LLQuaternion &initial_val, const std::string& comment, LLControlVariable::ePersist persist)
{
return declareControl(name, TYPE_QUAT, initial_val.getValue(), comment, persist);
}
LLControlVariable* LLControlGroup::declareRect(const std::string& name, const LLRect &initial_val, const std::string& comment, LLControlVariable::ePersist persist)
{
return declareControl(name, TYPE_RECT, initial_val.getValue(), comment, persist);
@ -600,6 +610,11 @@ LLVector3d LLControlGroup::getVector3d(const std::string& name)
return get<LLVector3d>(name);
}
LLQuaternion LLControlGroup::getQuaternion(const std::string& name)
{
return get<LLQuaternion>(name);
}
LLRect LLControlGroup::getRect(const std::string& name)
{
return get<LLRect>(name);
@ -677,6 +692,11 @@ void LLControlGroup::setVector3d(const std::string& name, const LLVector3d &val)
set(name, val);
}
void LLControlGroup::setQuaternion(const std::string& name, const LLQuaternion &val)
{
set(name, val);
}
void LLControlGroup::setRect(const std::string& name, const LLRect &val)
{
set(name, val);
@ -859,6 +879,16 @@ U32 LLControlGroup::loadFromFileLegacy(const std::string& filename, BOOL require
validitems++;
}
break;
case TYPE_QUAT:
{
LLQuaternion quat;
child_nodep->getAttributeQuat("value", quat);
control->set(quat.getValue());
validitems++;
}
break;
case TYPE_RECT:
{
//RN: hack to support reading rectangles from a string
@ -1201,6 +1231,11 @@ template <> eControlType get_control_type<LLVector3d>()
return TYPE_VEC3D;
}
template <> eControlType get_control_type<LLQuaternion>()
{
return TYPE_QUAT;
}
template <> eControlType get_control_type<LLRect>()
{
return TYPE_RECT;
@ -1236,6 +1271,10 @@ template <> LLSD convert_to_llsd<LLVector3d>(const LLVector3d& in)
{
return in.getValue();
}
template <> LLSD convert_to_llsd<LLQuaternion>(const LLQuaternion& in)
{
return in.getValue();
}
template <> LLSD convert_to_llsd<LLRect>(const LLRect& in)
{
@ -1348,6 +1387,18 @@ LLVector3d convert_from_llsd<LLVector3d>(const LLSD& sd, eControlType type, cons
}
}
template<>
LLQuaternion convert_from_llsd<LLQuaternion>(const LLSD& sd, eControlType type, const std::string& control_name)
{
if (type == TYPE_QUAT)
return (LLQuaternion)sd;
else
{
CONTROL_ERRS << "Invalid LLQuaternion value for " << control_name << ": " << LLControlGroup::typeEnumToString(type) << " " << sd << LL_ENDL;
return LLQuaternion();
}
}
template<>
LLRect convert_from_llsd<LLRect>(const LLSD& sd, eControlType type, const std::string& control_name)
{

View File

@ -67,6 +67,7 @@
class LLVector3;
class LLVector3d;
class LLQuaternion;
class LLColor4;
class LLColor3;
@ -80,6 +81,7 @@ typedef enum e_control_type
TYPE_STRING,
TYPE_VEC3,
TYPE_VEC3D,
TYPE_QUAT,
TYPE_RECT,
TYPE_COL4,
TYPE_COL3,
@ -220,6 +222,7 @@ public:
LLControlVariable* declareString(const std::string& name, const std::string &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT);
LLControlVariable* declareVec3(const std::string& name, const LLVector3 &initial_val,const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT);
LLControlVariable* declareVec3d(const std::string& name, const LLVector3d &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT);
LLControlVariable* declareQuat(const std::string& name, const LLQuaternion &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT);
LLControlVariable* declareRect(const std::string& name, const LLRect &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT);
LLControlVariable* declareColor4(const std::string& name, const LLColor4 &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT);
LLControlVariable* declareColor3(const std::string& name, const LLColor3 &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT);
@ -234,10 +237,10 @@ public:
LLWString getWString(const std::string& name);
LLVector3 getVector3(const std::string& name);
LLVector3d getVector3d(const std::string& name);
LLVector3d getVector3d(const std::string& name);
LLRect getRect(const std::string& name);
LLSD getLLSD(const std::string& name);
LLQuaternion getQuaternion(const std::string& name);
LLColor4 getColor(const std::string& name);
LLColor4 getColor4(const std::string& name);
@ -270,6 +273,7 @@ public:
void setString(const std::string& name, const std::string& val);
void setVector3(const std::string& name, const LLVector3 &val);
void setVector3d(const std::string& name, const LLVector3d &val);
void setQuaternion(const std::string& name, const LLQuaternion &val);
void setRect(const std::string& name, const LLRect &val);
void setColor4(const std::string& name, const LLColor4 &val);
void setLLSD(const std::string& name, const LLSD& val);
@ -436,7 +440,8 @@ template <> eControlType get_control_type<bool>();
//template <> eControlType get_control_type<BOOL> ()
template <> eControlType get_control_type<std::string>();
template <> eControlType get_control_type<LLVector3>();
template <> eControlType get_control_type<LLVector3d>();
template <> eControlType get_control_type<LLVector3d>();
template <> eControlType get_control_type<LLQuaternion>();
template <> eControlType get_control_type<LLRect>();
template <> eControlType get_control_type<LLColor4>();
template <> eControlType get_control_type<LLColor3>();
@ -444,7 +449,8 @@ template <> eControlType get_control_type<LLSD>();
template <> LLSD convert_to_llsd<U32>(const U32& in);
template <> LLSD convert_to_llsd<LLVector3>(const LLVector3& in);
template <> LLSD convert_to_llsd<LLVector3d>(const LLVector3d& in);
template <> LLSD convert_to_llsd<LLVector3d>(const LLVector3d& in);
template <> LLSD convert_to_llsd<LLQuaternion>(const LLQuaternion& in);
template <> LLSD convert_to_llsd<LLRect>(const LLRect& in);
template <> LLSD convert_to_llsd<LLColor4>(const LLColor4& in);
template <> LLSD convert_to_llsd<LLColor3>(const LLColor3& in);
@ -453,6 +459,7 @@ template<> std::string convert_from_llsd<std::string>(const LLSD& sd, eControlTy
template<> LLWString convert_from_llsd<LLWString>(const LLSD& sd, eControlType type, const std::string& control_name);
template<> LLVector3 convert_from_llsd<LLVector3>(const LLSD& sd, eControlType type, const std::string& control_name);
template<> LLVector3d convert_from_llsd<LLVector3d>(const LLSD& sd, eControlType type, const std::string& control_name);
template<> LLQuaternion convert_from_llsd<LLQuaternion>(const LLSD& sd, eControlType type, const std::string& control_name);
template<> LLRect convert_from_llsd<LLRect>(const LLSD& sd, eControlType type, const std::string& control_name);
template<> bool convert_from_llsd<bool>(const LLSD& sd, eControlType type, const std::string& control_name);
template<> S32 convert_from_llsd<S32>(const LLSD& sd, eControlType type, const std::string& control_name);

View File

@ -65,6 +65,7 @@ public:
virtual void setString(const std::string& name, const std::string& val) {}
virtual void setVector3(const std::string& name, const LLVector3 &val) {}
virtual void setVector3d(const std::string& name, const LLVector3d &val) {}
virtual void setQuaternion(const std::string& name, const LLQuaternion &val) {}
virtual void setRect(const std::string& name, const LLRect &val) {}
virtual void setColor4(const std::string& name, const LLColor4 &val) {}
virtual void setLLSD(const std::string& name, const LLSD& val) {}

View File

@ -11,6 +11,22 @@
<key>Value</key>
<integer>1</integer>
</map>
<key>AvatarSitRotation</key>
<map>
<key>Comment</key>
<string>Avatar real sitting rotation used in preset</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Quaternion</string>
<key>Value</key>
<array>
<real>0</real>
<real>0</real>
<real>0</real>
<real>1</real>
</array>
</map>
<key>CameraAngle</key>
<map>
<key>Comment</key>

View File

@ -11,6 +11,22 @@
<key>Value</key>
<integer>1</integer>
</map>
<key>AvatarSitRotation</key>
<map>
<key>Comment</key>
<string>Avatar real sitting rotation used in preset</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Quaternion</string>
<key>Value</key>
<array>
<real>0</real>
<real>0</real>
<real>0</real>
<real>1</real>
</array>
</map>
<key>CameraAngle</key>
<map>
<key>Comment</key>

View File

@ -11,6 +11,22 @@
<key>Value</key>
<integer>1</integer>
</map>
<key>AvatarSitRotation</key>
<map>
<key>Comment</key>
<string>Avatar real sitting rotation used in preset</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Quaternion</string>
<key>Value</key>
<array>
<real>0</real>
<real>0</real>
<real>0</real>
<real>1</real>
</array>
</map>
<key>CameraAngle</key>
<map>
<key>Comment</key>

View File

@ -4397,6 +4397,22 @@
<real>1.0</real>
</array>
</map>
<key>AvatarSitRotation</key>
<map>
<key>Comment</key>
<string>Avatar real sitting rotation used in preset</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Quaternion</string>
<key>Value</key>
<array>
<real>0</real>
<real>0</real>
<real>0</real>
<real>1</real>
</array>
</map>
<key>FocusPosOnLogout</key>
<map>
<key>Comment</key>

View File

@ -1804,8 +1804,8 @@ 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 * parent_rot;
local_camera_offset = local_camera_offset * gAgent.getFrameAgent().getQuaternion() * parent_rot;
}
else
{
@ -1998,7 +1998,10 @@ LLVector3d LLAgentCamera::getCurrentFocusOffset()
LLQuaternion LLAgentCamera::getCurrentAvatarRotation()
{
LLViewerObject* sit_object = (LLViewerObject*)gAgentAvatarp->getParent();
return sit_object ? sit_object->getRenderRotation() : gAgent.getFrameAgent().getQuaternion();
LLQuaternion av_rot = gAgent.getFrameAgent().getQuaternion();
LLQuaternion obj_rot = sit_object ? sit_object->getRenderRotation() : LLQuaternion::DEFAULT;
return av_rot * obj_rot;
}
bool LLAgentCamera::isJoystickCameraUsed()
@ -2828,6 +2831,12 @@ 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;

View File

@ -121,6 +121,8 @@ public:
LLVector3d getCurrentFocusOffset();
LLQuaternion getCurrentAvatarRotation();
bool isJoystickCameraUsed();
void setInitSitRot(LLQuaternion sit_rot) { mInitSitRot = sit_rot; };
void rotateToInitSitRot();
private:
/** Determines maximum camera distance from target for mouselook, opposite to LAND_MIN_ZOOM */
@ -135,6 +137,8 @@ private:
/** Initial focus offset */
LLPointer<LLControlVariable> mFocusOffsetInitial;
LLQuaternion mInitSitRot;
//--------------------------------------------------------------------
// Position
//--------------------------------------------------------------------

View File

@ -44,6 +44,7 @@
#include "llfirstuse.h"
#include "llhints.h"
#include "lltabcontainer.h"
#include "llvoavatarself.h"
static LLDefaultChildRegistry::Register<LLPanelCameraItem> r("panel_camera_item");
@ -566,6 +567,19 @@ void LLFloaterCamera::switchToPreset(const std::string& name)
LLPresetsManager::getInstance()->loadPreset(PRESETS_CAMERA, name);
}
if (isAgentAvatarValid() && gAgentAvatarp->getParent())
{
LLQuaternion sit_rot = gSavedSettings.getQuaternion("AvatarSitRotation");
if (sit_rot != LLQuaternion())
{
gAgent.rotate(~gAgent.getFrameAgent().getQuaternion());
gAgent.rotate(sit_rot);
}
else
{
gAgentCamera.rotateToInitSitRot();
}
}
gAgentCamera.resetCameraZoomFraction();
LLFloaterCamera* camera_floater = LLFloaterCamera::findInstance();

View File

@ -28,6 +28,7 @@
#include "llfloatersavecamerapreset.h"
#include "llagent.h"
#include "llagentcamera.h"
#include "llbutton.h"
#include "llcombobox.h"
@ -38,6 +39,7 @@
#include "llpresetsmanager.h"
#include "llradiogroup.h"
#include "lltrans.h"
#include "llvoavatarself.h"
LLFloaterSaveCameraPreset::LLFloaterSaveCameraPreset(const LLSD &key)
: LLModalDialog(key)
@ -102,6 +104,10 @@ void LLFloaterSaveCameraPreset::onBtnSave()
}
else
{
if (isAgentAvatarValid() && gAgentAvatarp->getParent())
{
gSavedSettings.setQuaternion("AvatarSitRotation", gAgent.getFrameAgent().getQuaternion());
}
if (gAgentCamera.isJoystickCameraUsed())
{
gSavedSettings.setVector3("CameraOffsetRearView", gAgentCamera.getCurrentCameraOffset());

View File

@ -111,6 +111,7 @@ void LLFloaterSettingsDebug::onCommitSettings()
LLVector3 vector;
LLVector3d vectord;
LLQuaternion quat;
LLRect rect;
LLColor4 col4;
LLColor3 col3;
@ -146,6 +147,13 @@ void LLFloaterSettingsDebug::onCommitSettings()
vectord.mdV[VZ] = getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
controlp->set(vectord.getValue());
break;
case TYPE_QUAT:
quat.mQ[VX] = getChild<LLUICtrl>("val_spinner_1")->getValue().asReal();
quat.mQ[VY] = getChild<LLUICtrl>("val_spinner_2")->getValue().asReal();
quat.mQ[VZ] = getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
quat.mQ[VS] = getChild<LLUICtrl>("val_spinner_4")->getValue().asReal();;
controlp->set(quat.getValue());
break;
case TYPE_RECT:
rect.mLeft = getChild<LLUICtrl>("val_spinner_1")->getValue().asInteger();
rect.mRight = getChild<LLUICtrl>("val_spinner_2")->getValue().asInteger();
@ -351,6 +359,40 @@ void LLFloaterSettingsDebug::updateControl(LLControlVariable* controlp)
}
break;
}
case TYPE_QUAT:
{
LLQuaternion q;
q.setValue(sd);
spinner1->setVisible(TRUE);
spinner1->setLabel(std::string("X"));
spinner2->setVisible(TRUE);
spinner2->setLabel(std::string("Y"));
spinner3->setVisible(TRUE);
spinner3->setLabel(std::string("Z"));
spinner4->setVisible(TRUE);
spinner4->setLabel(std::string("S"));
if (!spinner1->hasFocus())
{
spinner1->setPrecision(4);
spinner1->setValue(q.mQ[VX]);
}
if (!spinner2->hasFocus())
{
spinner2->setPrecision(4);
spinner2->setValue(q.mQ[VY]);
}
if (!spinner3->hasFocus())
{
spinner3->setPrecision(4);
spinner3->setValue(q.mQ[VZ]);
}
if (!spinner4->hasFocus())
{
spinner4->setPrecision(4);
spinner4->setValue(q.mQ[VS]);
}
break;
}
case TYPE_RECT:
{
LLRect r;

View File

@ -261,6 +261,7 @@ void LLPresetsManager::getControlNames(std::vector<std::string>& names)
("TrackFocusObject")
("CameraOffsetRearView")
("FocusOffsetRearView")
("AvatarSitRotation")
;
names = camera_controls;
}

View File

@ -7336,7 +7336,8 @@ void LLVOAvatar::sitOnObject(LLViewerObject *sit_object)
mRoot->updateWorldMatrixChildren();
stopMotion(ANIM_AGENT_BODY_NOISE);
gAgentCamera.setInitSitRot(gAgent.getFrameAgent().getQuaternion());
}
//-----------------------------------------------------------------------------