From: <sv...@ww...> - 2005-06-12 03:18:42
|
Author: mkrose Date: 2005-06-11 20:18:33 -0700 (Sat, 11 Jun 2005) New Revision: 1562 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Include/Systems/AircraftFlightSensors.h trunk/CSP/CSPSim/Source/Atmosphere.cpp trunk/CSP/CSPSim/Source/Systems/AircraftFlightSensors.cpp Log: Fix a bug that caused absurdly large turbulence. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1562 Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2005-06-08 00:50:13 UTC (rev 1561) +++ trunk/CSP/CSPSim/CHANGES.current 2005-06-12 03:18:33 UTC (rev 1562) @@ -1,6 +1,9 @@ Version 0.4.0 (in progress) =========================== +2005-06-11: onsight + * Fix a bug that caused absurdly large turbulence. + 2005-06-06: onsight * Partially fix depth buffer problem with airbase structures. The floor of the open hangars will still z-fight with the Modified: trunk/CSP/CSPSim/Include/Systems/AircraftFlightSensors.h =================================================================== --- trunk/CSP/CSPSim/Include/Systems/AircraftFlightSensors.h 2005-06-08 00:50:13 UTC (rev 1561) +++ trunk/CSP/CSPSim/Include/Systems/AircraftFlightSensors.h 2005-06-12 03:18:33 UTC (rev 1562) @@ -35,6 +35,8 @@ EXTEND_SIMDATA_XML_INTERFACE(AircraftFlightSensors, System) END_SIMDATA_XML_INTERFACE + AircraftFlightSensors(); + protected: virtual double onUpdate(double dt); virtual void importChannels(Bus *bus); Modified: trunk/CSP/CSPSim/Source/Atmosphere.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Atmosphere.cpp 2005-06-08 00:50:13 UTC (rev 1561) +++ trunk/CSP/CSPSim/Source/Atmosphere.cpp 2005-06-12 03:18:33 UTC (rev 1562) @@ -171,7 +171,7 @@ m_TurbulenceZ = noise.generate(1000, true, 10.0, 1.0, 0.0); for (i = 0; i < 1000; i++) { float a; - a= m_TurbulenceX[i]; + a = m_TurbulenceX[i]; m_TurbulenceX[i] *= 10.0f * a * fabsf(a); a = m_TurbulenceY[i]; m_TurbulenceY[i] *= 10.0f * a * fabsf(a); @@ -234,18 +234,27 @@ const double f = h - idx; wind.x() += m_WindAltX[idx]*(1.0-f) + m_WindAltX[idx+1]*f; wind.y() += m_WindAltY[idx]*(1.0-f) + m_WindAltY[idx+1]*f; - return wind * m_WindScale * m_GustModulation; + wind *= m_WindScale * m_GustModulation; + if (wind.length() > 100.0) { // XXX remove me + std::cout << "strong wind! " << m_WindScale << " " << m_GustModulation << " " << wind << "\n"; + } + return wind; } simdata::Vector3 Atmosphere::getTurbulence(simdata::Vector3 const &p, double dist) const { + assert(dist >= 0.0 && dist < 2e+9); int idx = simdata::clampTo(static_cast<int>(p.z() * (1000.0 / 15000.0)), 0, 999); double a = std::max(m_TurbulenceAltA[idx], 0.0f); float b = std::max(m_TurbulenceAltB[idx], 0.0f); + assert(m_TurbulenceBlend >= 0.0 && m_TurbulenceBlend <= 1.0); a = a * (1.0 - m_TurbulenceBlend) + b * m_TurbulenceBlend; if (a <= 0.0) return simdata::Vector3::ZERO; - if (dist < 0.0) dist = - dist; - idx = static_cast<int>(dist * 0.1) % 1000; - return simdata::Vector3(a * m_TurbulenceX[idx], a * m_TurbulenceY[idx], a * m_TurbulenceZ[idx]); + idx = std::max(0, static_cast<int>(dist * 0.1)) % 1000; + const simdata::Vector3 turbulence(a * m_TurbulenceX[idx], a * m_TurbulenceY[idx], a * m_TurbulenceZ[idx]); + if (turbulence.length() > 100.0) { // XXX remove me + std::cout << "strong turbulence! " << a << " " << turbulence << " " << m_TurbulenceX[idx] << " " << idx << " " << dist << " " << m_TurbulenceBlend << "\n"; + } + return turbulence; } void Atmosphere::setPosition(double lat, double lon) { @@ -306,11 +315,9 @@ const float f = static_cast<float>(m_GustIndex - index); const float gust = m_GustTime[index%1000] * (1.0f - f) + m_GustTime[(index+1)%1000] * f; m_GustModulation = std::max(1.0, 1.0 + gust); - //std::cout << getWind(simdata::Vector3::ZERO) << " " << m_GustModulation << std::endl; if (m_FastUpdate < 3.0) return false; dt = m_FastUpdate; m_FastUpdate = 0.0; - std::cout << "wind scale = " << m_WindScale << ", gust = " << m_GustModulation << "\n"; return true; } @@ -351,7 +358,7 @@ } } } else { - m_TurbulenceBlend += dt * 0.0003; + m_TurbulenceBlend -= dt * 0.0003; if (m_TurbulenceBlend < 0.0) { Perlin1D noise; noise.set(0.9, 6); Modified: trunk/CSP/CSPSim/Source/Systems/AircraftFlightSensors.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Systems/AircraftFlightSensors.cpp 2005-06-08 00:50:13 UTC (rev 1561) +++ trunk/CSP/CSPSim/Source/Systems/AircraftFlightSensors.cpp 2005-06-12 03:18:33 UTC (rev 1562) @@ -34,10 +34,11 @@ #include <CSPSim.h> - SIMDATA_REGISTER_INTERFACE(AircraftFlightSensors) +AircraftFlightSensors::AircraftFlightSensors(): m_Distance(0) { } + double AircraftFlightSensors::onUpdate(double dt) { simdata::Vector3 pos = b_Position->value(); double speed = b_Velocity->value().length(); |