diff options
author | Rider Linden <rider@lindenlab.com> | 2018-06-25 18:49:27 +0000 |
---|---|---|
committer | Rider Linden <rider@lindenlab.com> | 2018-06-25 18:49:27 +0000 |
commit | 138f3edf749e7ffcc8cafd8170f38d2d12120339 (patch) | |
tree | bdffafbb677eca59ddea1cb6c1c124e91a6eedbc /indra | |
parent | 4356b8dc0ea7754ce643596d99f3f051a8f8917a (diff) | |
parent | 8a2532ee55fb1c1bf78318e954bd25a0853cc2e3 (diff) |
Merged in graham_linden/viewer-eep-graham (pull request #7)
Better legacy sky setting sun rot conversion
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llinventory/llsettingssky.cpp | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp index bf0115b80b..ad863b5671 100644 --- a/indra/llinventory/llsettingssky.cpp +++ b/indra/llinventory/llsettingssky.cpp @@ -35,12 +35,28 @@ //========================================================================= static const F32 NIGHTTIME_ELEVATION = -8.0f; // degrees static const F32 NIGHTTIME_ELEVATION_SIN = (F32)sinf(NIGHTTIME_ELEVATION * DEG_TO_RAD); -static const LLVector3 DUE_EAST = LLVector3::x_axis; static LLQuaternion convert_azimuth_and_altitude_to_quat(F32 azimuth, F32 altitude) { + F32 sinTheta = sin(azimuth); + F32 cosTheta = cos(azimuth); + F32 sinPhi = sin(altitude); + F32 cosPhi = cos(altitude); + + LLVector3 dir; + // +x right, +z up, +y at... + dir.mV[0] = cosTheta * cosPhi; + dir.mV[1] = sinTheta * cosPhi; + dir.mV[2] = sinPhi; + + LLVector3 axis = LLVector3::x_axis % dir; + axis.normalize(); + + F32 angle = acos(LLVector3::x_axis * dir); + LLQuaternion quat; - quat.setEulerAngles(0.0f, altitude, azimuth); + quat.setAngleAxis(angle, axis); + return quat; } @@ -772,21 +788,15 @@ LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy) } if (legacy.has(SETTING_LEGACY_EAST_ANGLE) && legacy.has(SETTING_LEGACY_SUN_ANGLE)) - { // convert the east and sun angles into a quaternion. - F32 two_pi = F_PI * 2.0f; - + { // get counter-clockwise radian angle from clockwise legacy WL east angle... - F32 azimuth = two_pi - legacy[SETTING_LEGACY_EAST_ANGLE].asReal(); - - F32 altitude = legacy[SETTING_LEGACY_SUN_ANGLE].asReal(); + F32 azimuth = -legacy[SETTING_LEGACY_EAST_ANGLE].asReal(); + F32 altitude = legacy[SETTING_LEGACY_SUN_ANGLE].asReal(); LLQuaternion sunquat = convert_azimuth_and_altitude_to_quat(azimuth, altitude); // original WL moon dir was diametrically opposed to the sun dir - LLQuaternion moonquat = convert_azimuth_and_altitude_to_quat(azimuth + F_PI, -altitude); - - //LLVector3 sundir = DUE_EAST * sunquat; - //LLVector3 moondir = DUE_EAST * moonquat; + LLQuaternion moonquat = convert_azimuth_and_altitude_to_quat(azimuth + F_PI, altitude + F_PI); newsettings[SETTING_SUN_ROTATION] = sunquat.getValue(); newsettings[SETTING_MOON_ROTATION] = moonquat.getValue(); @@ -826,15 +836,20 @@ void LLSettingsSky::calculateHeavenlyBodyPositions() const LLQuaternion sunq = getSunRotation(); LLQuaternion moonq = getMoonRotation(); - mSunDirection = DUE_EAST * sunq; - mMoonDirection = DUE_EAST * moonq; + mSunDirection = LLVector3::x_axis * sunq; + mMoonDirection = LLVector3::x_axis * moonq; mSunDirection.normalize(); mMoonDirection.normalize(); - //LL_WARNS("LAPRAS") << "Sun info: Rotation=" << sunq << " Vector=" << mSunDirection << LL_ENDL; + //LL_WARNS("LAPRAS") << "Sun info: Rotation=" << sunq << " Vector=" << mSunDirection << LL_ENDL; //LL_WARNS("LAPRAS") << "Moon info: Rotation=" << moonq << " Vector=" << mMoonDirection << LL_ENDL; + if (mSunDirection.lengthSquared() < 0.01f) + LL_WARNS("SETTINGS") << "Zero length sun direction. Wailing and gnashing of teeth may follow... or not." << LL_ENDL; + if (mMoonDirection.lengthSquared() < 0.01f) + LL_WARNS("SETTINGS") << "Zero length moon direction. Wailing and gnashing of teeth may follow... or not." << LL_ENDL; + llassert(mSunDirection.lengthSquared() > 0.01f); llassert(mMoonDirection.lengthSquared() > 0.01f); } |