// // Update the position of the moon image in the sky // void CMoonImage::Reposition (sgVec3 p, double theta, double lst, double lat, double ra, double dec, double spin) { sgMat4 LST, LAT, RA, DEC, D, SCALE, ECLIPTIC, SPIN; sgVec3 axis; sgVec3 v; // Create scaling matrix for moon illusion (appears larger near horizon) float scale = 1.0f; sgMakeIdentMat4 (SCALE); float maxMagnification = 0.5f; float minThreshold = DegToRad (80.0f); float maxThreshold = DegToRad (95.0f); float span = maxThreshold - minThreshold; if ((theta >= minThreshold) && (theta <= maxThreshold)) { sgMat4 I; sgMakeIdentMat4 (I); scale = 1.0f + (maxMagnification * (theta - minThreshold) / span); sgScaleMat4 (SCALE, I, scale); } // Rotation matrix for latitude sgSetVec3 (axis, -1.0f, 0, 0); sgMakeRotMat4 (LAT, 90.0f-(float)lat, axis); // Rotation matrix for local sidereal time, converted from h to deg sgSetVec3 (axis, 0, 0, -1.0f); sgMakeRotMat4 (LST, ((float)lst * 15), axis); // Rotation matrix for right ascension sgSetVec3 (axis, 0, 0, 1); sgMakeRotMat4 (RA, RadToDeg ((float)ra), axis); // Rotation matrix for declination sgSetVec3 (axis, 1, 0, 0); sgMakeRotMat4 (DEC, 90.0f - RadToDeg ((float)dec), axis); // Translate moon distance sgSetVec3 (v, 0, 0, distance); sgMakeTransMat4 (D, v); // Rotate to align moon equator with ecliptic sgSetVec3 (axis, 1.0f, 0, 0); sgMakeRotMat4 (ECLIPTIC, 90.0f, axis); /// Rotate the moon image accurately towards the sun position sgSetVec3 (axis, 0, 0, 1); sgMakeRotMat4 (SPIN, spin, axis); // Combine all transforms sgMakeIdentMat4 (T); sgPreMultMat4 (T, LAT); sgPreMultMat4 (T, LST); sgPreMultMat4 (T, RA); sgPreMultMat4 (T, DEC); sgPreMultMat4 (T, D); sgPreMultMat4 (T, ECLIPTIC); sgPreMultMat4 (T, SPIN); }
// // Update the position of the moon image in the sky // void CMoonImage::Reposition (sgVec3 p, double theta, double lst, double lat, double ra, double dec, double spin) { sgMat4 LST, LAT, RA, DEC, D, SCALE, ECLIPTIC, SPIN; sgVec3 axis; sgVec3 v; // Create scaling matrix for moon illusion (appears larger near horizon) float scale = 1.0f; sgMakeIdentMat4 (SCALE); float maxMagnification = 0.5f; float minThreshold = DegToRad (80.0f); float maxThreshold = DegToRad (95.0f); float span = maxThreshold - minThreshold; if ((theta >= minThreshold) && (theta <= maxThreshold)) { sgMat4 I; sgMakeIdentMat4 (I); scale = 1.0f + (maxMagnification * (theta - minThreshold) / span); sgScaleMat4 (SCALE, I, scale); } // Rotation matrix for latitude sgSetVec3 (axis, -1.0f, 0, 0); sgMakeRotMat4 (LAT, 90.0f-(float)lat, axis); // Rotation matrix for local sidereal time, converted from h to deg sgSetVec3 (axis, 0, 0, -1.0f); sgMakeRotMat4 (LST, ((float)lst * 15), axis); // Rotation matrix for right ascension sgSetVec3 (axis, 0, 0, 1); sgMakeRotMat4 (RA, RadToDeg ((float)ra), axis); // Rotation matrix for declination sgSetVec3 (axis, 1, 0, 0); sgMakeRotMat4 (DEC, 90.0f - RadToDeg ((float)dec), axis); // Translate moon distance sgSetVec3 (v, 0, 0, distance); sgMakeTransMat4 (D, v); // Rotate to align moon equator with ecliptic sgSetVec3 (axis, 1.0f, 0, 0); sgMakeRotMat4 (ECLIPTIC, 90.0f, axis); /// Rotate the moon image accurately towards the sun position sgSetVec3 (axis, 0, 0, 1); sgMakeRotMat4 (SPIN, spin, axis); // Combine all transforms sgMakeIdentMat4 (T); sgPreMultMat4 (T, LAT); sgPreMultMat4 (T, LST); sgPreMultMat4 (T, RA); sgPreMultMat4 (T, DEC); sgPreMultMat4 (T, D); sgPreMultMat4 (T, ECLIPTIC); sgPreMultMat4 (T, SPIN); /* char debug[256]; double jd = CTimeManager::Instance().GetJulianDate(); SDateTime dt = CTimeManager::Instance().GetLocalDateTime (); sprintf (debug, "JD=%f D=%d/%d/%d T=%d:%d RA=%f Dec=%f", jd, dt.date.year, dt.date.month, dt.date.day, dt.time.hour, dt.time.minute, RadToDeg(ra), RadToDeg(dec)); DrawNoticeToUser (debug, 1); */ }