From 58827cb2752b9a184d638ed6a4f0efa0e9740d64 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Sat, 13 Feb 2021 01:50:04 +0200 Subject: SL-14725 Rotation sliders for sun and moon panels --- indra/llui/llvirtualtrackball.cpp | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'indra/llui/llvirtualtrackball.cpp') 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()) -- cgit v1.2.3 From fa35eeecd7854b92e52f7bac2dc31bfc07ce012b Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 15 Feb 2021 22:53:54 +0200 Subject: SL-14725 Add elevation and azimuth to local lighting --- indra/llui/llvirtualtrackball.cpp | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'indra/llui/llvirtualtrackball.cpp') diff --git a/indra/llui/llvirtualtrackball.cpp b/indra/llui/llvirtualtrackball.cpp index 15847a7282..728e86af08 100644 --- a/indra/llui/llvirtualtrackball.cpp +++ b/indra/llui/llvirtualtrackball.cpp @@ -352,7 +352,6 @@ LLQuaternion LLVirtualTrackball::getRotation() const 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])) @@ -371,19 +370,7 @@ void LLVirtualTrackball::getAzimuthAndElevation(const LLQuaternion &quat, F32 &a 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; - } + elevation = asin(point.mV[VZ]); // because VectorZero is '1' } // static -- cgit v1.2.3 From 9eae41e5825662564125b9f5edf87e1aa3c0c508 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 16 Feb 2021 21:47:34 +0200 Subject: SL-14725 Validate trackball elevation --- indra/llui/llvirtualtrackball.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'indra/llui/llvirtualtrackball.cpp') diff --git a/indra/llui/llvirtualtrackball.cpp b/indra/llui/llvirtualtrackball.cpp index 728e86af08..6e0aef740d 100644 --- a/indra/llui/llvirtualtrackball.cpp +++ b/indra/llui/llvirtualtrackball.cpp @@ -370,7 +370,10 @@ void LLVirtualTrackball::getAzimuthAndElevation(const LLQuaternion &quat, F32 &a azimuth += F_PI * 2; } - elevation = asin(point.mV[VZ]); // because VectorZero is '1' + // while vector is '1', F32 is not sufficiently precise and we can get + // values like 1.0000012 which will result in -90deg angle instead of 90deg + F32 z = llclamp(point.mV[VZ], -1.f, 1.f); + elevation = asin(z); // because VectorZero's length is '1' } // static @@ -442,6 +445,10 @@ BOOL LLVirtualTrackball::handleHover(S32 x, S32 y, MASK mask) mValue *= az_quat; } + // we are doing a lot of F32 mathematical operations with loss of precision, + // re-normalize to compensate + mValue.normalize(); + mPrevX = x; mPrevY = y; onCommit(); -- cgit v1.2.3