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 ++++++ indra/llui/llvirtualtrackball.h | 3 + indra/newview/llpaneleditsky.cpp | 119 +++++++++++++-- indra/newview/llpaneleditsky.h | 2 + .../default/xui/en/floater_fixedenvironment.xml | 2 +- .../skins/default/xui/en/menu_favorites.xml | 12 +- .../default/xui/en/panel_settings_sky_sunmoon.xml | 162 ++++++++++++++++----- 7 files changed, 294 insertions(+), 52 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&); diff --git a/indra/newview/llpaneleditsky.cpp b/indra/newview/llpaneleditsky.cpp index 2e26b69144..06e406e2ab 100644 --- a/indra/newview/llpaneleditsky.cpp +++ b/indra/newview/llpaneleditsky.cpp @@ -69,11 +69,15 @@ namespace const std::string FIELD_SKY_GLOW_SIZE("glow_size"); const std::string FIELD_SKY_STAR_BRIGHTNESS("star_brightness"); const std::string FIELD_SKY_SUN_ROTATION("sun_rotation"); + const std::string FIELD_SKY_SUN_AZIMUTH("sun_azimuth"); + const std::string FIELD_SKY_SUN_ELEVATION("sun_elevation"); const std::string FIELD_SKY_SUN_IMAGE("sun_image"); const std::string FIELD_SKY_SUN_SCALE("sun_scale"); const std::string FIELD_SKY_SUN_BEACON("sunbeacon"); const std::string FIELD_SKY_MOON_BEACON("moonbeacon"); const std::string FIELD_SKY_MOON_ROTATION("moon_rotation"); + const std::string FIELD_SKY_MOON_AZIMUTH("moon_azimuth"); + const std::string FIELD_SKY_MOON_ELEVATION("moon_elevation"); const std::string FIELD_SKY_MOON_IMAGE("moon_image"); const std::string FIELD_SKY_MOON_SCALE("moon_scale"); const std::string FIELD_SKY_MOON_BRIGHTNESS("moon_brightness"); @@ -473,12 +477,16 @@ BOOL LLPanelSettingsSkySunMoonTab::postBuild() getChild(FIELD_SKY_GLOW_SIZE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onGlowChanged(); }); getChild(FIELD_SKY_STAR_BRIGHTNESS)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onStarBrightnessChanged(); }); getChild(FIELD_SKY_SUN_ROTATION)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSunRotationChanged(); }); + getChild(FIELD_SKY_SUN_AZIMUTH)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSunAzimElevChanged(); }); + getChild(FIELD_SKY_SUN_ELEVATION)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSunAzimElevChanged(); }); getChild(FIELD_SKY_SUN_IMAGE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSunImageChanged(); }); getChild(FIELD_SKY_SUN_SCALE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onSunScaleChanged(); }); getChild(FIELD_SKY_SUN_IMAGE)->setBlankImageAssetID(LLSettingsSky::GetBlankSunTextureId()); getChild(FIELD_SKY_SUN_IMAGE)->setDefaultImageAssetID(LLSettingsSky::GetBlankSunTextureId()); getChild(FIELD_SKY_SUN_IMAGE)->setAllowNoTexture(TRUE); getChild(FIELD_SKY_MOON_ROTATION)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onMoonRotationChanged(); }); + getChild(FIELD_SKY_MOON_AZIMUTH)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onMoonAzimElevChanged(); }); + getChild(FIELD_SKY_MOON_ELEVATION)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onMoonAzimElevChanged(); }); getChild(FIELD_SKY_MOON_IMAGE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onMoonImageChanged(); }); getChild(FIELD_SKY_MOON_IMAGE)->setDefaultImageAssetID(LLSettingsSky::GetDefaultMoonTextureId()); getChild(FIELD_SKY_MOON_IMAGE)->setBlankImageAssetID(LLSettingsSky::GetDefaultMoonTextureId()); @@ -537,13 +545,29 @@ void LLPanelSettingsSkySunMoonTab::refresh() getChild(FIELD_SKY_GLOW_FOCUS)->setValue(glow.mV[2] / SLIDER_SCALE_GLOW_B); getChild(FIELD_SKY_STAR_BRIGHTNESS)->setValue(mSkySettings->getStarBrightness()); - getChild(FIELD_SKY_SUN_ROTATION)->setRotation(mSkySettings->getSunRotation()); getChild(FIELD_SKY_SUN_IMAGE)->setValue(mSkySettings->getSunTextureId()); getChild(FIELD_SKY_SUN_SCALE)->setValue(mSkySettings->getSunScale()); - getChild(FIELD_SKY_MOON_ROTATION)->setRotation(mSkySettings->getMoonRotation()); getChild(FIELD_SKY_MOON_IMAGE)->setValue(mSkySettings->getMoonTextureId()); getChild(FIELD_SKY_MOON_SCALE)->setValue(mSkySettings->getMoonScale()); getChild(FIELD_SKY_MOON_BRIGHTNESS)->setValue(mSkySettings->getMoonBrightness()); + + // Sun rotation values + F32 azimuth, elevation; + LLQuaternion quat = mSkySettings->getSunRotation(); + LLVirtualTrackball::getAzimuthAndElevationDeg(quat, azimuth, elevation); + + getChild(FIELD_SKY_SUN_ROTATION)->setRotation(quat); + getChild(FIELD_SKY_SUN_AZIMUTH)->setValue(azimuth); + getChild(FIELD_SKY_SUN_ELEVATION)->setValue(elevation); + + // Moon rotation values + quat = mSkySettings->getMoonRotation(); + LLVirtualTrackball::getAzimuthAndElevationDeg(quat, azimuth, elevation); + + getChild(FIELD_SKY_MOON_ROTATION)->setRotation(quat); + getChild(FIELD_SKY_MOON_AZIMUTH)->setValue(azimuth); + getChild(FIELD_SKY_MOON_ELEVATION)->setValue(elevation); + } //------------------------------------------------------------------------- @@ -583,10 +607,47 @@ void LLPanelSettingsSkySunMoonTab::onStarBrightnessChanged() void LLPanelSettingsSkySunMoonTab::onSunRotationChanged() { - if (!mSkySettings) return; - mSkySettings->setSunRotation(getChild(FIELD_SKY_SUN_ROTATION)->getRotation()); - mSkySettings->update(); - setIsDirty(); + LLQuaternion quat = getChild(FIELD_SKY_SUN_ROTATION)->getRotation(); + + F32 azimuth, elevation; + LLVirtualTrackball::getAzimuthAndElevationDeg(quat, azimuth, elevation); + getChild(FIELD_SKY_SUN_AZIMUTH)->setValue(azimuth); + getChild(FIELD_SKY_SUN_ELEVATION)->setValue(elevation); + if (mSkySettings) + { + mSkySettings->setSunRotation(quat); + mSkySettings->update(); + setIsDirty(); + } +} + +void LLPanelSettingsSkySunMoonTab::onSunAzimElevChanged() +{ + F32 azimuth = getChild(FIELD_SKY_SUN_AZIMUTH)->getValue().asReal(); + F32 elevation = getChild(FIELD_SKY_SUN_ELEVATION)->getValue().asReal(); + LLQuaternion quat = mSkySettings->getSunRotation(); + + azimuth *= DEG_TO_RAD; + elevation *= DEG_TO_RAD; + + if (is_approx_zero(elevation)) + { + elevation = F_APPROXIMATELY_ZERO; + } + + quat.setAngleAxis(-elevation, 0, 1, 0); + LLQuaternion az_quat; + az_quat.setAngleAxis(F_TWO_PI - azimuth, 0, 0, 1); + quat *= az_quat; + + getChild(FIELD_SKY_SUN_ROTATION)->setRotation(quat); + + if (mSkySettings) + { + mSkySettings->setSunRotation(quat); + mSkySettings->update(); + setIsDirty(); + } } void LLPanelSettingsSkySunMoonTab::onSunScaleChanged() @@ -607,10 +668,48 @@ void LLPanelSettingsSkySunMoonTab::onSunImageChanged() void LLPanelSettingsSkySunMoonTab::onMoonRotationChanged() { - if (!mSkySettings) return; - mSkySettings->setMoonRotation(getChild(FIELD_SKY_MOON_ROTATION)->getRotation()); - mSkySettings->update(); - setIsDirty(); + LLQuaternion quat = getChild(FIELD_SKY_MOON_ROTATION)->getRotation(); + + F32 azimuth, elevation; + LLVirtualTrackball::getAzimuthAndElevationDeg(quat, azimuth, elevation); + getChild(FIELD_SKY_MOON_AZIMUTH)->setValue(azimuth); + getChild(FIELD_SKY_MOON_ELEVATION)->setValue(elevation); + + if (mSkySettings) + { + mSkySettings->setMoonRotation(quat); + mSkySettings->update(); + setIsDirty(); + } +} + +void LLPanelSettingsSkySunMoonTab::onMoonAzimElevChanged() +{ + F32 azimuth = getChild(FIELD_SKY_MOON_AZIMUTH)->getValue().asReal(); + F32 elevation = getChild(FIELD_SKY_MOON_ELEVATION)->getValue().asReal(); + LLQuaternion quat = mSkySettings->getMoonRotation(); + + azimuth *= DEG_TO_RAD; + elevation *= DEG_TO_RAD; + + if (is_approx_zero(elevation)) + { + elevation = F_APPROXIMATELY_ZERO; + } + + quat.setAngleAxis(-elevation, 0, 1, 0); + LLQuaternion az_quat; + az_quat.setAngleAxis(F_TWO_PI- azimuth, 0, 0, 1); + quat *= az_quat; + + getChild(FIELD_SKY_MOON_ROTATION)->setRotation(quat); + + if (mSkySettings) + { + mSkySettings->setMoonRotation(quat); + mSkySettings->update(); + setIsDirty(); + } } void LLPanelSettingsSkySunMoonTab::onMoonImageChanged() diff --git a/indra/newview/llpaneleditsky.h b/indra/newview/llpaneleditsky.h index c02c9c95a0..d1c558c902 100644 --- a/indra/newview/llpaneleditsky.h +++ b/indra/newview/llpaneleditsky.h @@ -124,9 +124,11 @@ private: void onGlowChanged(); void onStarBrightnessChanged(); void onSunRotationChanged(); + void onSunAzimElevChanged(); void onSunScaleChanged(); void onSunImageChanged(); void onMoonRotationChanged(); + void onMoonAzimElevChanged(); void onMoonScaleChanged(); void onMoonBrightnessChanged(); void onMoonImageChanged(); diff --git a/indra/newview/skins/default/xui/en/floater_fixedenvironment.xml b/indra/newview/skins/default/xui/en/floater_fixedenvironment.xml index dbf91b0834..2cc73361f5 100644 --- a/indra/newview/skins/default/xui/en/floater_fixedenvironment.xml +++ b/indra/newview/skins/default/xui/en/floater_fixedenvironment.xml @@ -89,7 +89,7 @@ follows="left|top|right|bottom" auto_resize="false" user_resize="false" - height="40" + height="35" visible="true"> + name="Show On Map"> + parameter="show_on_map" /> + name="Copy slurl"> + parameter="copy_slurl" /> Position: @@ -93,7 +93,7 @@ follows="left|top" height="10" layout="topleft" - left_delta="-5" + left_delta="65" top_delta="20" width="80"> Color: @@ -108,12 +108,58 @@ name="sun_moon_color" top_pad="5" width="60" /> + + Azimuth: + + + + Elevation: + + Glow Focus: @@ -128,8 +174,8 @@ min_val="-2" max_val="2" name="glow_focus" - top_delta="15" - width="250" + top_delta="13" + width="215" can_edit_text="true"/> Position: @@ -278,30 +324,76 @@ top_delta="15" width="130" can_edit_text="true"/> - - Brightness: - - - + Azimuth: + + + + Elevation: + + + + Brightness: + + +