summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2021-02-13 01:50:04 +0200
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2021-02-15 22:02:21 +0200
commit58827cb2752b9a184d638ed6a4f0efa0e9740d64 (patch)
treef72d8fe77e9fdaa4a636aeb06a1defb91c594323 /indra/llui
parent5971c647e4abd11c4c4f055f124ac2251b720c25 (diff)
SL-14725 Rotation sliders for sun and moon panels
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llvirtualtrackball.cpp46
-rw-r--r--indra/llui/llvirtualtrackball.h3
2 files changed, 49 insertions, 0 deletions
diff --git a/indra/llui/llvirtualtrackball.cpp b/indra/llui/llvirtualtrackball.cpp
index 723643dd25..15847a7282 100644
--- a/indra/llui/llvirtualtrackball.cpp
+++ b/indra/llui/llvirtualtrackball.cpp
@@ -348,6 +348,52 @@ LLQuaternion LLVirtualTrackball::getRotation() const
return mValue;
}
+// static
+void LLVirtualTrackball::getAzimuthAndElevation(const LLQuaternion &quat, F32 &azimuth, F32 &elevation)
+{
+ // LLQuaternion has own function to get azimuth, but it doesn't appear to return correct values (meant for 2d?)
+ const LLVector3 VectorZero(10000.0f, 0.0f, 0.0f);
+ LLVector3 point = VectorZero * quat;
+
+ if (!is_approx_zero(point.mV[VX]) || !is_approx_zero(point.mV[VY]))
+ {
+ azimuth = atan2f(point.mV[VX], point.mV[VY]);
+ }
+ else
+ {
+ azimuth = 0;
+ }
+
+ azimuth -= F_PI_BY_TWO;
+
+ if (azimuth < 0)
+ {
+ azimuth += F_PI * 2;
+ }
+
+ if (abs(point.mV[VY]) > abs(point.mV[VX]) && !is_approx_zero(point.mV[VY])) // to avoid precision drop
+ {
+ elevation = atanl((F64)point.mV[VZ] / (F64)abs(point.mV[VY]));
+ }
+ else if (!is_approx_zero(point.mV[VX]))
+ {
+ elevation = atanl((F64)point.mV[VZ] / (F64)abs(point.mV[VX]));
+ }
+ else
+ {
+ // both VX and VY are near zero, VZ should be high
+ elevation = point.mV[VZ] > 0 ? F_PI_BY_TWO : -F_PI_BY_TWO;
+ }
+}
+
+// static
+void LLVirtualTrackball::getAzimuthAndElevationDeg(const LLQuaternion &quat, F32 &azimuth, F32 &elevation)
+{
+ getAzimuthAndElevation(quat, azimuth, elevation);
+ azimuth *= RAD_TO_DEG;
+ elevation *= RAD_TO_DEG;
+}
+
BOOL LLVirtualTrackball::handleHover(S32 x, S32 y, MASK mask)
{
if (hasMouseCapture())
diff --git a/indra/llui/llvirtualtrackball.h b/indra/llui/llvirtualtrackball.h
index 2d4b1ece17..c7a893877b 100644
--- a/indra/llui/llvirtualtrackball.h
+++ b/indra/llui/llvirtualtrackball.h
@@ -96,6 +96,9 @@ public:
void setRotation(const LLQuaternion &value);
LLQuaternion getRotation() const;
+ static void getAzimuthAndElevation(const LLQuaternion &quat, F32 &azimuth, F32 &elevation);
+ static void getAzimuthAndElevationDeg(const LLQuaternion &quat, F32 &azimuth, F32 &elevation);
+
protected:
friend class LLUICtrlFactory;
LLVirtualTrackball(const Params&);