diff --git a/application/drivermode.cpp b/application/drivermode.cpp index 51c31a7c..33f1bcd5 100644 --- a/application/drivermode.cpp +++ b/application/drivermode.cpp @@ -569,7 +569,7 @@ void driver_mode::update_camera(double const Deltatime) Camera.Reset(); // likwidacja obrotów - patrzy horyzontalnie na południe if (Camera.m_owner == nullptr) { - if (controlled && glm::length(controlled->GetPosition() - Camera.Pos) < 1500) + if (controlled && glm::length2(controlled->GetPosition() - Camera.Pos) < 1500 * 1500) // length2 is better than length for comparing because it does not require sqrt function { // gdy bliżej niż 1.5km Camera.LookAt = controlled->GetPosition() + 0.4 * controlled->VectorUp() * controlled->MoverParameters->Dim.H; @@ -583,7 +583,7 @@ void driver_mode::update_camera(double const Deltatime) if (d && pDynamicNearest) { // jeśli jakiś jest znaleziony wcześniej - if (100.0 * glm::length(d->GetPosition() - Camera.Pos) > glm::length(pDynamicNearest->GetPosition() - Camera.Pos)) + if (100.0 * glm::length2(d->GetPosition() - Camera.Pos) > glm::length2(pDynamicNearest->GetPosition() - Camera.Pos)) // length2 is better than length for comparing because it does not require sqrt function { d = pDynamicNearest; // jeśli najbliższy nie jest 10 razy bliżej niż } diff --git a/audio/audiorenderer.cpp b/audio/audiorenderer.cpp index 821a0161..6c60ebff 100644 --- a/audio/audiorenderer.cpp +++ b/audio/audiorenderer.cpp @@ -406,7 +406,7 @@ openal_renderer::update( double const Deltatime ) { cameramove = glm::dvec3{ 0.0 }; } // ... from camera jump to another location - if( glm::length( cameramove ) > 100.0 ) { + if( glm::length2( cameramove ) > 100.0 * 100.0) { // length2 is better than length for comparing because it does not require sqrt function cameramove = glm::dvec3{ 0.0 }; } m_listenervelocity = limit_velocity( cameramove / Deltatime ); diff --git a/model/Model3d.cpp b/model/Model3d.cpp index 2cdb6501..9b867bb4 100644 --- a/model/Model3d.cpp +++ b/model/Model3d.cpp @@ -630,8 +630,9 @@ std::pair TSubModel::Load(cParser &parser, bool dynamic) if (idx > 0) { // jeśli pierwszy trójkąt będzie zdegenerowany, to zostanie usunięty i nie ma co sprawdzać - if ((glm::length((vertex)->position - (vertex - 1)->position) > 1000.0) || (glm::length((vertex - 1)->position - (vertex - 2)->position) > 1000.0) || - (glm::length((vertex - 2)->position - (vertex)->position) > 1000.0)) + // length2 is better than length for comparing because it does not require sqrt function + if ((glm::length2((vertex)->position - (vertex - 1)->position) > 1000.0 * 1000.0) || (glm::length2((vertex - 1)->position - (vertex - 2)->position) > 1000.0 * 1000.0) || + (glm::length2((vertex - 2)->position - (vertex)->position) > 1000.0 * 1000.0)) { // jeżeli są dalej niż 2km od siebie //Ra 15-01: // obiekt wstawiany nie powinien być większy niż 300m (trójkąty terenu w E3D mogą mieć 1.5km) diff --git a/rendering/opengl33renderer.cpp b/rendering/opengl33renderer.cpp index 88181cef..be59d298 100644 --- a/rendering/opengl33renderer.cpp +++ b/rendering/opengl33renderer.cpp @@ -1293,7 +1293,8 @@ bool opengl33_renderer::Render_reflections(viewport_config &vp) auto const timestamp{ Timer::GetRenderTime() }; if( ( timestamp - m_environmentupdatetime < Global.reflectiontune.update_interval ) - && ( glm::length( m_renderpass.pass_camera.position() - m_environmentupdatelocation ) < 1000.0 ) ) { + && ( glm::length2( m_renderpass.pass_camera.position() - m_environmentupdatelocation ) < 1000.0 * 1000.0 ) ) // length2 is better than length for comparing because it does not require sqrt function + { // run update every 5+ mins of simulation time, or at least 1km from the last location return false; } @@ -4620,7 +4621,7 @@ void opengl33_renderer::Update_Lights(light_array &Lights) break; } auto const lightoffset = glm::vec3{scenelight.position - camera}; - if (glm::length(lightoffset) > 1000.f) { + if (glm::length2(lightoffset) > 1000.f * 1000.f) { // we don't care about lights past arbitrary limit of 1 km. // but there could still be weaker lights which are closer, so keep looking continue; diff --git a/rendering/openglrenderer.cpp b/rendering/openglrenderer.cpp index b1db5312..1919219a 100644 --- a/rendering/openglrenderer.cpp +++ b/rendering/openglrenderer.cpp @@ -892,7 +892,7 @@ opengl_renderer::Render_reflections() { auto const timestamp { Timer::GetRenderTime() }; if( ( timestamp - m_environmentupdatetime < Global.reflectiontune.update_interval ) - && ( glm::length( m_renderpass.camera.position() - m_environmentupdatelocation ) < 1000.0 ) ) { + && ( glm::length2( m_renderpass.camera.position() - m_environmentupdatelocation ) < 1000.0 * 1000.0 ) ) { // run update every 5+ mins of simulation time, or at least 1km from the last location return false; } @@ -4341,7 +4341,8 @@ opengl_renderer::Update_Lights( light_array &Lights ) { break; } auto const lightoffset = glm::vec3{ scenelight.position - camera }; - if( glm::length( lightoffset ) > 1000.f ) { + // length2 is better than length for comparing because it does not require sqrt function + if( glm::length2( lightoffset ) > 1000.f * 1000.f ) { // we don't care about lights past arbitrary limit of 1 km. // but there could still be weaker lights which are closer, so keep looking continue; diff --git a/rendering/precipitation.cpp b/rendering/precipitation.cpp index fdb4d3d1..cafc472e 100644 --- a/rendering/precipitation.cpp +++ b/rendering/precipitation.cpp @@ -70,7 +70,9 @@ basic_precipitation::update() { cameramove = glm::dvec3{ 0.0 }; } // ... from camera jump to another location - if( glm::length( cameramove ) > 100.0 ) { + // length2 is better than length for comparing because it does not require sqrt function + if( glm::length2( cameramove ) > 100.0 * 100.0 ) + { cameramove = glm::dvec3{ 0.0 }; } diff --git a/scene/scene.cpp b/scene/scene.cpp index 99617a67..57df3293 100644 --- a/scene/scene.cpp +++ b/scene/scene.cpp @@ -285,7 +285,8 @@ basic_cell::insert( shape_node Shape ) { if( ( shapedata.rangesquared_min == targetshapedata.rangesquared_min ) && ( shapedata.rangesquared_max == targetshapedata.rangesquared_max ) // ...and located close to each other (within arbitrary limit of 25m) - && ( glm::length( shapedata.area.center - targetshapedata.area.center ) < 25.0 ) ) { + // length2 is better than length for comparing because it does not require sqrt function + && ( glm::length2( shapedata.area.center - targetshapedata.area.center ) < 25.0 * 25.0 ) ) { if( true == targetshape.merge( Shape ) ) { // if the shape was merged there's nothing left to do @@ -311,7 +312,8 @@ basic_cell::insert( lines_node Lines ) { if( ( linesdata.rangesquared_min == targetlinesdata.rangesquared_min ) && ( linesdata.rangesquared_max == targetlinesdata.rangesquared_max ) // ...and located close to each other (within arbitrary limit of 10m) - && ( glm::length( linesdata.area.center - targetlinesdata.area.center ) < 10.0 ) ) { + // length2 is better than length for comparing because it does not require sqrt function + && ( glm::length2( linesdata.area.center - targetlinesdata.area.center ) < 10.0 * 10.0) ) { if( true == targetlines.merge( Lines ) ) { // if the shape was merged there's nothing left to do diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index d8b764cb..0d27ebed 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -1412,7 +1412,8 @@ TDynamicObject * TDynamicObject::ABuFindNearestObject(glm::vec3 pos, TTrack *Tra if( CouplNr == -2 ) { // wektor [kamera-obiekt] - poszukiwanie obiektu - if (glm::length(glm::dvec3(pos) - dynamic->vPosition) < 10.0) + // length2 is better than length for comparing because it does not require sqrt function + if (glm::length2(glm::dvec3(pos) - dynamic->vPosition) < 10.0 * 10.0) { // 10 metrów return dynamic; @@ -1420,12 +1421,14 @@ TDynamicObject * TDynamicObject::ABuFindNearestObject(glm::vec3 pos, TTrack *Tra } else { // jeśli (CouplNr) inne niz -2, szukamy sprzęgu - if (glm::length(glm::dvec3(pos) - dynamic->vCoulpler[0]) < 5.0) { + // length2 is better than length for comparing because it does not require sqrt function + if (glm::length2(glm::dvec3(pos) - dynamic->vCoulpler[0]) < 5.0 * 5.0) { // 5 metrów CouplNr = 0; return dynamic; } - if (glm::length(glm::dvec3(pos) - dynamic->vCoulpler[1]) < 5.0) { + // length2 is better than length for comparing because it does not require sqrt function + if (glm::length2(glm::dvec3(pos) - dynamic->vCoulpler[1]) < 5.0 * 5.0) { // 5 metrów CouplNr = 1; return dynamic; diff --git a/world/Track.cpp b/world/Track.cpp index e688c79b..eab3cb74 100644 --- a/world/Track.cpp +++ b/world/Track.cpp @@ -559,8 +559,9 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) // na przechyłce doliczyć jeszcze pół przechyłki } - if( (glm::length(( p1 + p1 + p2 ) / 3.0 - p1 - cp1) < 0.02 ) - || ( glm::length(( p1 + p2 + p2 ) / 3.0 - p2 + cp1) < 0.02 ) ) { + // length2 is better than length for comparing because it does not require sqrt function + if( (glm::length2(( p1 + p1 + p2 ) / 3.0 - p1 - cp1) < 0.02 * 0.02) + || (glm::length2(( p1 + p2 + p2 ) / 3.0 - p2 + cp1) < 0.02 * 0.02) ) { // "prostowanie" prostych z kontrolnymi, dokładność 2cm cp1 = cp2 = glm::dvec3(0, 0, 0); } @@ -655,8 +656,9 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( eType != tt_Cross ) { // dla skrzyżowań muszą być podane kontrolne - if( ( glm::length(( p1 + p1 + p2 ) / 3.0 - p1 - cp1 ) < 0.02 ) - || ( glm::length(( p1 + p2 + p2 ) / 3.0 - p2 + cp1 ) < 0.02 ) ) { + // length2 is better than length for comparing because it does not require sqrt function + if( (glm::length2(( p1 + p1 + p2 ) / 3.0 - p1 - cp1 ) < 0.02 * 0.02) + || (glm::length2(( p1 + p2 + p2 ) / 3.0 - p2 + cp1 ) < 0.02 * 0.02) ) { // "prostowanie" prostych z kontrolnymi, dokładność 2cm cp1 = cp2 = glm::dvec3(0, 0, 0); } @@ -719,8 +721,9 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( eType != tt_Cross ) { // dla skrzyżowań muszą być podane kontrolne - if( ( glm::length(( p3 + p3 + p4 ) / 3.0 - p3 - cp3) < 0.02 ) - || ( glm::length(( p3 + p4 + p4 ) / 3.0 - p4 + cp3) < 0.02 ) ) { + // length2 is better than length for comparing because it does not require sqrt function + if( (glm::length2(( p3 + p3 + p4 ) / 3.0 - p3 - cp3) < 0.02 * 0.02) + || (glm::length2(( p3 + p4 + p4 ) / 3.0 - p4 + cp3) < 0.02 * 0.02) ) { // "prostowanie" prostych z kontrolnymi, dokładność 2cm cp3 = cp4 = glm::dvec3(0, 0, 0); }