Skip to content
Snippets Groups Projects
Commit 8b2d5cb6 authored by Graham Linden's avatar Graham Linden
Browse files

Better method for deriving sun/moon quaternions from east/sun angle defs in...

Better method for deriving sun/moon quaternions from east/sun angle defs in legacy sky settings XML.

Avoid using static const DUE_EAST due to CRT init order issues w/ GCC.
parent 02ffb064
No related branches found
No related tags found
No related merge requests found
...@@ -35,12 +35,29 @@ ...@@ -35,12 +35,29 @@
//========================================================================= //=========================================================================
static const F32 NIGHTTIME_ELEVATION = -8.0f; // degrees static const F32 NIGHTTIME_ELEVATION = -8.0f; // degrees
static const F32 NIGHTTIME_ELEVATION_SIN = (F32)sinf(NIGHTTIME_ELEVATION * DEG_TO_RAD); 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) 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; LLQuaternion quat;
quat.setEulerAngles(0.0f, altitude, azimuth); quat.setAngleAxis(angle, axis);
return quat; return quat;
} }
...@@ -772,21 +789,15 @@ LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy) ...@@ -772,21 +789,15 @@ LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy)
} }
if (legacy.has(SETTING_LEGACY_EAST_ANGLE) && legacy.has(SETTING_LEGACY_SUN_ANGLE)) 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... // get counter-clockwise radian angle from clockwise legacy WL east angle...
F32 azimuth = two_pi - legacy[SETTING_LEGACY_EAST_ANGLE].asReal(); F32 azimuth = -legacy[SETTING_LEGACY_EAST_ANGLE].asReal();
F32 altitude = legacy[SETTING_LEGACY_SUN_ANGLE].asReal();
F32 altitude = legacy[SETTING_LEGACY_SUN_ANGLE].asReal();
LLQuaternion sunquat = convert_azimuth_and_altitude_to_quat(azimuth, altitude); LLQuaternion sunquat = convert_azimuth_and_altitude_to_quat(azimuth, altitude);
// original WL moon dir was diametrically opposed to the sun dir // original WL moon dir was diametrically opposed to the sun dir
LLQuaternion moonquat = convert_azimuth_and_altitude_to_quat(azimuth + F_PI, -altitude); LLQuaternion moonquat = convert_azimuth_and_altitude_to_quat(azimuth + F_PI, altitude + F_PI);
//LLVector3 sundir = DUE_EAST * sunquat;
//LLVector3 moondir = DUE_EAST * moonquat;
newsettings[SETTING_SUN_ROTATION] = sunquat.getValue(); newsettings[SETTING_SUN_ROTATION] = sunquat.getValue();
newsettings[SETTING_MOON_ROTATION] = moonquat.getValue(); newsettings[SETTING_MOON_ROTATION] = moonquat.getValue();
...@@ -826,15 +837,20 @@ void LLSettingsSky::calculateHeavenlyBodyPositions() const ...@@ -826,15 +837,20 @@ void LLSettingsSky::calculateHeavenlyBodyPositions() const
LLQuaternion sunq = getSunRotation(); LLQuaternion sunq = getSunRotation();
LLQuaternion moonq = getMoonRotation(); LLQuaternion moonq = getMoonRotation();
mSunDirection = DUE_EAST * sunq; mSunDirection = LLVector3::x_axis * sunq;
mMoonDirection = DUE_EAST * moonq; mMoonDirection = LLVector3::x_axis * moonq;
mSunDirection.normalize(); mSunDirection.normalize();
mMoonDirection.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; //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(mSunDirection.lengthSquared() > 0.01f);
llassert(mMoonDirection.lengthSquared() > 0.01f); llassert(mMoonDirection.lengthSquared() > 0.01f);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment