diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a96ffb36..51aee460 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,7 +181,6 @@ add_library(colobotbase STATIC math/half.h math/matrix.h math/sphere.h - math/vector.h object/auto/auto.cpp object/auto/auto.h object/auto/autobase.cpp diff --git a/src/app/input.cpp b/src/app/input.cpp index 7bc237bb..e1217f5b 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -27,6 +27,7 @@ #include "level/robotmain.h" +#include "math/func.h" #include #include diff --git a/src/app/input.h b/src/app/input.h index 43a57eda..0ca240ea 100644 --- a/src/app/input.h +++ b/src/app/input.h @@ -27,11 +27,10 @@ #include "common/key.h" #include "common/singleton.h" -#include "math/vector.h" - #include #include +#include struct Event; diff --git a/src/common/event.h b/src/common/event.h index d47c62b1..f887e604 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -27,8 +27,6 @@ #include "common/key.h" #include "common/make_unique.h" -#include "math/vector.h" - #include #include diff --git a/src/graphics/core/light.h b/src/graphics/core/light.h index 7377ac54..8770d231 100644 --- a/src/graphics/core/light.h +++ b/src/graphics/core/light.h @@ -27,7 +27,9 @@ #include "graphics/core/color.h" -#include "math/vector.h" +#include "math/const.h" + +#include // Graphics module namespace diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index c7d07b39..1bb72034 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -28,8 +28,6 @@ #include "graphics/core/color.h" #include "graphics/core/type.h" -#include "math/vector.h" - #include #include diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 7320de74..0678f3e4 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -32,6 +32,7 @@ #include "level/robotmain.h" #include "math/const.h" +#include "math/func.h" #include "math/geometry.h" #include "object/object.h" @@ -552,7 +553,7 @@ void CCamera::EffectFrame(const Event &event) m_effectOffset.z = (Math::Rand() - 0.5f) * 0.2f; } - float dist = Math::Distance(m_eyePt, m_effectPos); + float dist = glm::distance(m_eyePt, m_effectPos); dist = Math::Norm((dist - 100.f) / 100.0f); force *= 1.0f-dist; @@ -604,7 +605,7 @@ void CCamera::StartOver(CameraOverEffect effect, glm::vec3 pos, float force) else decay = 100.0f; - float dist = Math::Distance(m_eyePt, pos); + float dist = glm::distance(m_eyePt, pos); dist = (dist - decay) / decay; if (dist < 0.0f) dist = 0.0f; if (dist > 1.0f) dist = 1.0f; @@ -765,7 +766,7 @@ void CCamera::UpdateCameraAnimation(const glm::vec3 &eyePt, IsCollision(m_finalEye, m_finalLookat); float prog = 0.0f; - float dist = Math::Distance(m_finalEye, m_actualEye); + float dist = glm::distance(m_finalEye, m_actualEye); if (m_smooth == CAM_SMOOTH_NONE) prog = dist; if (m_smooth == CAM_SMOOTH_NORM) prog = powf(dist, 1.5f) * rTime * 0.75f; @@ -781,7 +782,7 @@ void CCamera::UpdateCameraAnimation(const glm::vec3 &eyePt, m_actualEye = (m_finalEye - m_actualEye) / dist * prog + m_actualEye; } - dist = Math::Distance(m_finalLookat, m_actualLookat); + dist = glm::distance(m_finalLookat, m_actualLookat); if ( m_smooth == CAM_SMOOTH_NONE ) prog = dist; if ( m_smooth == CAM_SMOOTH_NORM ) prog = powf(dist, 1.5f) * rTime * 3.0f; if ( m_smooth == CAM_SMOOTH_HARD ) prog = dist * rTime * 4.0f; @@ -881,7 +882,7 @@ void CCamera::IsCollisionBack() oPos.z-oRadius > max.z ) continue; glm::vec3 proj = Math::Projection(m_actualEye, m_actualLookat, oPos); - float dpp = Math::Distance(proj, oPos); + float dpp = glm::distance(proj, oPos); if ( dpp > oRadius ) continue; if ( oType == OBJECT_FACTORY ) @@ -891,11 +892,11 @@ void CCamera::IsCollisionBack() if ( fabs(angle) < 30.0f*Math::PI/180.0f ) continue; // in the gate? } - float del = Math::Distance(m_actualEye, m_actualLookat); + float del = glm::distance(m_actualEye, m_actualLookat); if (oType == OBJECT_FACTORY) del += oRadius; - float len = Math::Distance(m_actualEye, proj); + float len = glm::distance(m_actualEye, proj); if (len > del) continue; SetTransparency(obj, 1.0f); // transparent object @@ -931,10 +932,10 @@ void CCamera::IsCollisionFix(glm::vec3 &eye, glm::vec3 lookat) float objRadius = objSphere.radius; if (objRadius == 0.0f) continue; - float dist = Math::Distance(eye, objPos); + float dist = glm::distance(eye, objPos); if (dist < objRadius) { - dist = Math::Distance(eye, lookat); + dist = glm::distance(eye, lookat); glm::vec3 proj = Math::Projection(eye, lookat, objPos); eye = (lookat - eye) * objRadius / dist + proj; return; @@ -1438,7 +1439,7 @@ glm::vec3 CCamera::ExcludeObject(glm::vec3 eye, glm::vec3 lookat, float oRad; while (obj->GetCrashSphere(j++, oPos, oRad)) { - float dist = Math::Distance(oPos, eye); + float dist = glm::distance(oPos, eye); if (dist < oRad + 2.0f) eye.y = oPos.y + oRad + 2.0f; } diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index 8d19175d..6d13d351 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -26,7 +26,7 @@ #include "graphics/core/color.h" -#include "math/vector.h" +#include #include #include diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 28b722c6..5dbdb789 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3254,7 +3254,7 @@ float CEngine::GetEyeDirV() bool CEngine::IsVisiblePoint(const glm::vec3 &pos) { - return Math::Distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance); + return glm::distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance); } void CEngine::UpdateMatProj() @@ -4767,7 +4767,7 @@ void CEngine::DrawShadowSpots() if ( h > max ) h = max; if ( h > 4.0f ) h = 4.0f; - D = Math::Distance(m_eyePt, pos); + D = glm::distance(m_eyePt, pos); if (D >= endDeepView) continue; @@ -4785,7 +4785,7 @@ void CEngine::DrawShadowSpots() if ( h > max ) h = max; if ( h > 4.0f ) h = 4.0f; - D = Math::Distance(m_eyePt, pos); + D = glm::distance(m_eyePt, pos); if (D >= endDeepView) continue; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 1176a0d3..ef54214c 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -34,7 +34,6 @@ #include "math/matrix.h" #include "math/sphere.h" -#include "math/vector.h" #include diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 2dd7e3e7..bd008535 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -28,7 +28,7 @@ #include "graphics/engine/engine.h" -#include "math/vector.h" +#include // Graphics module namespace diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index ddcc9c68..30e95399 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -357,7 +357,7 @@ void CLightning::StrikeAtPos(glm::vec3 pos) m_pos = pos; glm::vec3 eye = m_engine->GetEyePt(); - float dist = Math::Distance(m_pos, eye); + float dist = glm::distance(m_pos, eye); float deep = m_engine->GetDeepView(); if (dist < deep) diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index e3c078aa..654f6548 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -24,8 +24,6 @@ #pragma once -#include "math/vector.h" - #include #include diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 9be23b20..9a49a841 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -413,9 +413,9 @@ int CParticle::CreateFrag(glm::vec3 pos, glm::vec3 speed, p3.y = m_triangle[i].triangle[2].position.y; p3.z = m_triangle[i].triangle[2].position.z; - float l1 = Math::Distance(p1, p2); - float l2 = Math::Distance(p2, p3); - float l3 = Math::Distance(p3, p1); + float l1 = glm::distance(p1, p2); + float l2 = glm::distance(p2, p3); + float l3 = glm::distance(p3, p1); float dx = fabs(Math::Min(l1, l2, l3))*0.5f; float dy = fabs(Math::Max(l1, l2, l3))*0.5f; p1 = glm::vec3(-dx, dy, 0.0f); @@ -2478,7 +2478,7 @@ bool CParticle::TrackMove(int i, glm::vec3 pos, float progress) last = m_track[i].pos[hh]; } m_track[i].pos[h] = pos; - m_track[i].len[h] = Math::Distance(pos, last); + m_track[i].len[h] = glm::distance(pos, last); m_track[i].head = h; @@ -2978,7 +2978,7 @@ void CParticle::DrawParticleRay(int i) if (left) dim.y = -dim.y; - float len = Math::Distance(pos, goal); + float len = glm::distance(pos, goal); float adv = 0.0f; int step = static_cast((len/(dim.x*2.0f))+1); @@ -3550,7 +3550,7 @@ CObject* CParticle::SearchObjectGun(glm::vec3 old, glm::vec3 pos, float shieldRadius = shielder->GetActiveShieldRadius(); if (shieldRadius > 0.0f) { - float dist = Math::Distance(oPos, pos); + float dist = glm::distance(oPos, pos); if (dist <= shieldRadius) { best = obj; @@ -3563,8 +3563,8 @@ CObject* CParticle::SearchObjectGun(glm::vec3 old, glm::vec3 pos, // Test the center of the object, which is necessary for objects // that have no sphere in the center (station). - float dist = Math::Distance(oPos, pos)-4.0f; - float obj_dist = Math::Distance(old, oPos); + float dist = glm::distance(oPos, pos)-4.0f; + float obj_dist = glm::distance(old, oPos); if (dist < min && obj_dist < best_dist) { best = obj; @@ -3581,8 +3581,8 @@ CObject* CParticle::SearchObjectGun(glm::vec3 old, glm::vec3 pos, oPos.z+oRadius < box1.z || oPos.z-oRadius > box2.z ) continue; glm::vec3 p = Math::Projection(old, pos, oPos); - float ddist = Math::Distance(p, oPos)-oRadius; - float obj_dist = Math::Distance(old, oPos); + float ddist = glm::distance(p, oPos)-oRadius; + float obj_dist = glm::distance(old, oPos); if (ddist < min && obj_dist < best_dist) { best = obj; @@ -3640,7 +3640,7 @@ CObject* CParticle::SearchObjectRay(glm::vec3 pos, glm::vec3 goal, oPos.z < box1.z || oPos.z > box2.z ) continue; glm::vec3 p = Math::Projection(pos, goal, oPos); - float dist = Math::Distance(p, oPos); + float dist = glm::distance(p, oPos); if (dist < min) return obj; } diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 10cf5be0..95e1718f 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -101,7 +101,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) } else { - m_size = Math::Distance(min, max)*2.0f; + m_size = glm::distance(min, max)*2.0f; if ( m_size < 4.0f ) m_size = 4.0f; if ( m_size > 80.0f ) m_size = 80.0f; } @@ -1487,7 +1487,7 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) float h; - h = Math::Distance(p1, p2); + h = glm::distance(p1, p2); if ( h > 5.0f ) { p2.x = p1.x+((p2.x-p1.x)*5.0f/h); @@ -1495,7 +1495,7 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) p2.z = p1.z+((p2.z-p1.z)*5.0f/h); } - h = Math::Distance(p2, p3); + h = glm::distance(p2, p3); if ( h > 5.0f ) { p3.x = p2.x+((p3.x-p2.x)*5.0f/h); @@ -1503,7 +1503,7 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) p3.z = p2.z+((p3.z-p2.z)*5.0f/h); } - h = Math::Distance(p3, p1); + h = glm::distance(p3, p1); if ( h > 5.0f ) { p1.x = p3.x+((p1.x-p3.x)*5.0f/h); @@ -1628,7 +1628,7 @@ void CPyro::ExploStart() { glm::vec3 min, max; m_engine->GetObjectBBox(objRank, min, max); - weight = Math::Distance(min, max); // weight according to size! + weight = glm::distance(min, max); // weight according to size! speed.y = 10.0f+Math::Rand()*20.0f; speed.x = (Math::Rand()-0.5f)*20.0f; @@ -2295,7 +2295,7 @@ CObject* CPyro::FallSearchBeeExplo() float shieldRadius = dynamic_cast(*obj).GetActiveShieldRadius(); if ( shieldRadius > 0.0f ) { - float distance = Math::Distance(oPos, bulletCrashSphere.sphere.pos); + float distance = glm::distance(oPos, bulletCrashSphere.sphere.pos); if (distance <= shieldRadius) return obj; } @@ -2303,14 +2303,14 @@ CObject* CPyro::FallSearchBeeExplo() if ( obj->GetType() == OBJECT_BASE ) { - float distance = Math::Distance(oPos, bulletCrashSphere.sphere.pos); + float distance = glm::distance(oPos, bulletCrashSphere.sphere.pos); if (distance < 25.0f) return obj; } // Test the center of the object, which is necessary for objects // that have no sphere in the center (station). - float distance = Math::Distance(oPos, bulletCrashSphere.sphere.pos)-4.0f; + float distance = glm::distance(oPos, bulletCrashSphere.sphere.pos)-4.0f; if (distance < 5.0f) return obj; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 6212c006..0276de46 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -27,7 +27,8 @@ #include "graphics/core/vertex.h" #include "math/const.h" -#include "math/vector.h" + +#include #include #include diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index f9933482..055a9eeb 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -376,7 +376,7 @@ void CWater::DrawSurf() glm::vec3 p = pos; p.x += size*(m_lines[i].len-1); float radius = sqrtf(powf(size, 2.0f)+powf(size*m_lines[i].len, 2.0f)); - if (Math::Distance(p, eye) > deep + radius) + if (glm::distance(p, eye) > deep + radius) continue; if (device->ComputeSphereVisibility(p, radius) != Gfx::FRUSTUM_PLANE_ALL) diff --git a/src/graphics/opengl/glutil.h b/src/graphics/opengl/glutil.h index 3460bf56..04bbcefc 100644 --- a/src/graphics/opengl/glutil.h +++ b/src/graphics/opengl/glutil.h @@ -26,8 +26,6 @@ #include "graphics/core/device.h" -#include "math/vector.h" - #include #include diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index c2ed7497..bebf8660 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -2432,7 +2432,7 @@ bool CRobotMain::EventFrame(const Event &event) if ( obj->GetProxyActivate() ) // active if it is near? { glm::vec3 eye = m_engine->GetLookatPt(); - float dist = Math::Distance(eye, obj->GetPosition()); + float dist = glm::distance(eye, obj->GetPosition()); if ( dist < obj->GetProxyDistance() ) { obj->SetProxyActivate(false); @@ -4123,7 +4123,7 @@ float SearchNearestObject(CObjectManager* objMan, glm::vec3 center, CObject* exc if (oPos.x != center.x || oPos.z != center.z) { - float dist = Math::Distance(center, oPos) - 80.0f; + float dist = glm::distance(center, oPos) - 80.0f; if (dist < 0.0f) dist = 0.0f; min = Math::Min(min, dist); continue; @@ -4135,7 +4135,7 @@ float SearchNearestObject(CObjectManager* objMan, glm::vec3 center, CObject* exc type == OBJECT_DESTROYER) { glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(center, oPos) - 8.0f; + float dist = glm::distance(center, oPos) - 8.0f; if (dist < 0.0f) dist = 0.0f; min = Math::Min(min, dist); } @@ -4145,7 +4145,7 @@ float SearchNearestObject(CObjectManager* objMan, glm::vec3 center, CObject* exc glm::vec3 oPos = crashSphere.sphere.pos; float oRadius = crashSphere.sphere.radius; - float dist = Math::Distance(center, oPos) - oRadius; + float dist = glm::distance(center, oPos) - oRadius; if (dist < 0.0f) dist = 0.0f; min = Math::Min(min, dist); } @@ -4345,14 +4345,14 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter) if (type == OBJECT_BASE) { oPos = obj->GetPosition(); - float dist = Math::Distance(center, oPos)-80.0f; + float dist = glm::distance(center, oPos)-80.0f; oMax = Math::Min(oMax, dist); } else { for (const auto& crashSphere : obj->GetAllCrashSpheres()) { - float dist = Math::Distance(center, crashSphere.sphere.pos)-crashSphere.sphere.radius; + float dist = glm::distance(center, crashSphere.sphere.pos)-crashSphere.sphere.radius; oMax = Math::Min(oMax, dist); } } @@ -4378,7 +4378,7 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter) { for (const auto& crashSphere : obj->GetAllCrashSpheres()) { - float dist = Math::Distance(center, crashSphere.sphere.pos)-crashSphere.sphere.radius-BUILDMARGIN; + float dist = glm::distance(center, crashSphere.sphere.pos)-crashSphere.sphere.radius-BUILDMARGIN; oMax = Math::Min(oMax, dist); } } @@ -6065,7 +6065,7 @@ void CRobotMain::StartDetectEffect(COldObject* object, CObject* target) { goal = target->GetPosition(); goal.y += 3.0f; - goal = Math::SegmentPoint(pos, goal, Math::Distance(pos, goal)-3.0f); + goal = Math::SegmentPoint(pos, goal, glm::distance(pos, goal)-3.0f); } dim.x = 3.0f; @@ -6076,7 +6076,7 @@ void CRobotMain::StartDetectEffect(COldObject* object, CObject* target) { goal = target->GetPosition(); goal.y += 3.0f; - goal = Math::SegmentPoint(pos, goal, Math::Distance(pos, goal)-1.0f); + goal = Math::SegmentPoint(pos, goal, glm::distance(pos, goal)-1.0f); dim.x = 6.0f; dim.y = dim.x; m_particle->CreateParticle(goal, glm::vec3(0.0f, 0.0f, 0.0f), dim, diff --git a/src/math/all.h b/src/math/all.h index d4883c0b..47621dd5 100644 --- a/src/math/all.h +++ b/src/math/all.h @@ -30,5 +30,4 @@ #include "math/geometry.h" #include "math/half.h" #include "math/matrix.h" -#include "math/vector.h" diff --git a/src/math/const.h b/src/math/const.h index 4e3ace4d..28347576 100644 --- a/src/math/const.h +++ b/src/math/const.h @@ -34,26 +34,26 @@ namespace Math //! Tolerance level -- minimum accepted float value -const float TOLERANCE = 1e-6f; +constexpr float TOLERANCE = 1e-6f; //! Very small number (used in testing/returning some values) -const float VERY_SMALL_NUM = 1e-6f; +constexpr float VERY_SMALL_NUM = 1e-6f; //! Very big number (used in testing/returning some values) -const float VERY_BIG_NUM = 1e6f; +constexpr float VERY_BIG_NUM = 1e6f; //! Huge number -const float HUGE_NUM = 1.0e+38f; +constexpr float HUGE_NUM = 1.0e+38f; //! PI -const float PI = 3.14159265358979323846f; +constexpr float PI = 3.14159265358979323846f; //! Degrees to radians multiplier -const float DEG_TO_RAD = 0.01745329251994329547f; +constexpr float DEG_TO_RAD = 0.01745329251994329547f; //! Radians to degrees multiplier -const float RAD_TO_DEG = 57.29577951308232286465f; +constexpr float RAD_TO_DEG = 57.29577951308232286465f; //! Natural logarithm of 2 -const float LOG_2 = log(2.0f); +const float LOG_2 = std::log(2.0f); } // namespace Math diff --git a/src/math/func.h b/src/math/func.h index b4c2dd41..d584864d 100644 --- a/src/math/func.h +++ b/src/math/func.h @@ -27,9 +27,12 @@ #include "math/const.h" +#include #include #include +#include +#include // Math module namespace @@ -264,6 +267,20 @@ inline float Bounce(float progress, float middle = 0.3f, float bounce = 0.4f) } } +//! Convenience function for calculating angle (in radians) between two vectors +inline float Angle(const glm::vec3& a, const glm::vec3& b) +{ + return std::acosf(glm::dot(a, b) / (glm::length(a) * glm::length(b))); +} + +inline std::string ToString(const glm::vec3& vector) +{ + std::stringstream s; + s.precision(3); + s << "[" << vector.x << ", " << vector.y << ", " << vector.z << "]"; + return s.str(); +} + } // namespace Math diff --git a/src/math/geometry.h b/src/math/geometry.h index 02f2452c..33e5bb5c 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -28,7 +28,6 @@ #include "math/const.h" #include "math/func.h" #include "math/matrix.h" -#include "math/vector.h" #include diff --git a/src/math/matrix.h b/src/math/matrix.h index 401ab628..824b53d3 100644 --- a/src/math/matrix.h +++ b/src/math/matrix.h @@ -27,7 +27,6 @@ #include "math/const.h" #include "math/func.h" -#include "math/vector.h" #include diff --git a/src/math/sphere.h b/src/math/sphere.h index ef770293..4ba9734d 100644 --- a/src/math/sphere.h +++ b/src/math/sphere.h @@ -19,14 +19,14 @@ #pragma once -#include "math/vector.h" +#include namespace Math { struct Sphere { - Sphere(const glm::vec3& pos = glm::vec3(), float radius = 0.0f) + Sphere(const glm::vec3& pos = glm::vec3(0, 0, 0), float radius = 0.0f) : pos(pos), radius(radius) {} glm::vec3 pos; @@ -36,12 +36,12 @@ struct Sphere //! Compute distance between given \a point and \a sphere inline float DistanceToSphere(const glm::vec3& point, const Sphere& sphere) { - return Math::Distance(point, sphere.pos) - sphere.radius; + return glm::distance(point, sphere.pos) - sphere.radius; } inline float DistanceBetweenSpheres(const Sphere& sphere1, const Sphere& sphere2) { - return Math::Distance(sphere1.pos, sphere2.pos) - sphere1.radius - sphere2.radius; + return glm::distance(sphere1.pos, sphere2.pos) - sphere1.radius - sphere2.radius; } inline Sphere BoundingSphereForBox(glm::vec3 mins, glm::vec3 maxs) diff --git a/src/math/vector.h b/src/math/vector.h deleted file mode 100644 index a227d219..00000000 --- a/src/math/vector.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://gnu.org/licenses - */ - -/** - * \file math/vector.h - * \brief Vector struct and related functions - */ - -#pragma once - - -#include "math/const.h" -#include "math/func.h" - - -#include -#include -#include - -// Math module namespace -namespace Math -{ - -//! Checks if two vectors are equal within given \a tolerance -inline bool VectorsEqual(const glm::vec3 &a, const glm::vec3 &b, float tolerance = TOLERANCE) -{ - return IsEqual(a.x, b.x, tolerance) - && IsEqual(a.y, b.y, tolerance) - && IsEqual(a.z, b.z, tolerance); -} - -//! Convenience function for calculating angle (in radians) between two vectors -inline float Angle(const glm::vec3 &a, const glm::vec3 &b) -{ - return std::acosf(glm::dot(a, b) / (glm::length(a) * glm::length(b))); -} - -//! Returns the distance between the ends of two vectors -inline float Distance(const glm::vec3 &a, const glm::vec3 &b) -{ - return glm::distance(a, b); -} - -inline std::string ToString(const glm::vec3& vector) -{ - std::stringstream s; - s.precision(3); - s << "[" << vector.x << ", " << vector.y << ", " << vector.z << "]"; - return s.str(); -} - - -} // namespace Math - diff --git a/src/object/auto/autoconvert.cpp b/src/object/auto/autoconvert.cpp index af5850f6..d1aa1319 100644 --- a/src/object/auto/autoconvert.cpp +++ b/src/object/auto/autoconvert.cpp @@ -406,7 +406,7 @@ CObject* CAutoConvert::SearchStone(ObjectType type) if (IsObjectBeingTransported(obj)) continue; glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, cPos); + float dist = glm::distance(oPos, cPos); if ( dist <= 5.0f ) return obj; } diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index f095ac92..b91a6578 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -493,7 +493,7 @@ bool CAutoDerrick::SearchFree(glm::vec3 pos) glm::vec3 sPos = crashSphere.sphere.pos; float sRadius = crashSphere.sphere.radius; - float distance = Math::Distance(sPos, pos); + float distance = glm::distance(sPos, pos); distance -= sRadius; if ( distance < 2.0f ) return false; // location occupied } diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index fdf4dbca..dffbacc1 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -288,7 +288,7 @@ CObject* CAutoDestroyer::SearchPlastic() if (obj->GetType() == OBJECT_HUMAN || obj->GetType() == OBJECT_TECH) continue; glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, sPos); + float dist = glm::distance(oPos, sPos); if ( dist <= 5.0f ) return obj; } diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index 6f09a04c..a686ef0c 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -570,7 +570,7 @@ CObject* CAutoFactory::SearchCargo() if (IsObjectBeingTransported(obj)) continue; glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, m_cargoPos); + float dist = glm::distance(oPos, m_cargoPos); if ( dist < 8.0f ) return obj; } @@ -701,7 +701,7 @@ CObject* CAutoFactory::SearchVehicle() if (IsObjectBeingTransported(obj)) continue; glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, m_cargoPos); + float dist = glm::distance(oPos, m_cargoPos); if ( dist < 8.0f ) return obj; } diff --git a/src/object/auto/automush.cpp b/src/object/auto/automush.cpp index 1b7c0aa7..b091e8a2 100644 --- a/src/object/auto/automush.cpp +++ b/src/object/auto/automush.cpp @@ -282,7 +282,7 @@ bool CAutoMush::SearchTarget() type != OBJECT_HUMAN ) continue; glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, iPos); + float dist = glm::distance(oPos, iPos); if ( dist < 50.0f ) return true; } diff --git a/src/object/auto/autonest.cpp b/src/object/auto/autonest.cpp index ffb3d8d6..ee725ee0 100644 --- a/src/object/auto/autonest.cpp +++ b/src/object/auto/autonest.cpp @@ -157,7 +157,7 @@ bool CAutoNest::SearchFree(glm::vec3 pos) glm::vec3 sPos = crashSphere.sphere.pos; float sRadius = crashSphere.sphere.radius; - float distance = Math::Distance(sPos, pos); + float distance = glm::distance(sPos, pos); distance -= sRadius; if ( distance < 2.0f ) return false; // location occupied } diff --git a/src/object/auto/autopowercaptor.cpp b/src/object/auto/autopowercaptor.cpp index 1e675558..4d7207ef 100644 --- a/src/object/auto/autopowercaptor.cpp +++ b/src/object/auto/autopowercaptor.cpp @@ -252,7 +252,7 @@ void CAutoPowerCaptor::ChargeObject(float rTime) for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, sPos); + float dist = glm::distance(oPos, sPos); if ( dist > 20.0f ) continue; if (! IsObjectBeingTransported(obj) && obj->Implements(ObjectInterfaceType::PowerContainer) ) diff --git a/src/object/auto/autopowerstation.cpp b/src/object/auto/autopowerstation.cpp index 67e52501..733882e4 100644 --- a/src/object/auto/autopowerstation.cpp +++ b/src/object/auto/autopowerstation.cpp @@ -284,7 +284,7 @@ CObject* CAutoPowerStation::SearchVehicle() type != OBJECT_MOBILEdr ) continue; glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, sPos); + float dist = glm::distance(oPos, sPos); if ( dist <= 5.0f ) return obj; } diff --git a/src/object/auto/autoradar.cpp b/src/object/auto/autoradar.cpp index 22f72a41..15f040e1 100644 --- a/src/object/auto/autoradar.cpp +++ b/src/object/auto/autoradar.cpp @@ -285,7 +285,7 @@ bool CAutoRadar::SearchEnemy(glm::vec3 &pos) m_totalDetect ++; glm::vec3 oPos = obj->GetPosition(); - float distance = Math::Distance(oPos, iPos); + float distance = glm::distance(oPos, iPos); if ( distance < min ) { min = distance; diff --git a/src/object/auto/autorepair.cpp b/src/object/auto/autorepair.cpp index d9ff1f62..0d90124c 100644 --- a/src/object/auto/autorepair.cpp +++ b/src/object/auto/autorepair.cpp @@ -248,7 +248,7 @@ CObject* CAutoRepair::SearchVehicle() if ( obj->Implements(ObjectInterfaceType::Movable) && !dynamic_cast(*obj).GetPhysics()->GetLand() ) continue; // in flight? glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, sPos); + float dist = glm::distance(oPos, sPos); if ( dist <= 5.0f ) return obj; } diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index 7817dfde..d1a903e5 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -298,7 +298,7 @@ CObject* CAutoTower::SearchTarget(glm::vec3 &impact) if (obj->GetCrashSphereCount() == 0) continue; glm::vec3 oPos = obj->GetFirstCrashSphere().sphere.pos; - float distance = Math::Distance(oPos, iPos); + float distance = glm::distance(oPos, iPos); if ( distance > TOWER_SCOPE ) continue; // too far if ( distance < min ) { diff --git a/src/object/implementation/program_storage_impl.h b/src/object/implementation/program_storage_impl.h index eba23c77..626f5bb5 100644 --- a/src/object/implementation/program_storage_impl.h +++ b/src/object/implementation/program_storage_impl.h @@ -21,7 +21,7 @@ #include "object/interface/program_storage_object.h" -#include "math/vector.h" +#include #include diff --git a/src/object/implementation/programmable_impl.h b/src/object/implementation/programmable_impl.h index 6fc375fb..e6eb61ab 100644 --- a/src/object/implementation/programmable_impl.h +++ b/src/object/implementation/programmable_impl.h @@ -20,12 +20,11 @@ #pragma once #include "object/interface/programmable_object.h" - -#include "math/vector.h" - #include "object/interface/interactive_object.h" #include "object/interface/trace_drawing_object.h" +#include + #include class CObject; diff --git a/src/object/motion/motion.h b/src/object/motion/motion.h index 1a4a7aa3..f00b806d 100644 --- a/src/object/motion/motion.h +++ b/src/object/motion/motion.h @@ -21,8 +21,6 @@ #include "common/error.h" -#include "math/vector.h" - #include "object/object_type.h" #include diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp index bcef27a7..beb7e7a4 100644 --- a/src/object/motion/motiontoto.cpp +++ b/src/object/motion/motiontoto.cpp @@ -427,7 +427,7 @@ bool CMotionToto::EventFrame(const Event &event) if ( m_bStartAction ) { m_bStartAction = false; - m_speedAction = Math::Distance(nPos, aPos)/15.0f; + m_speedAction = glm::distance(nPos, aPos)/15.0f; if ( m_speedAction < 20.0f ) m_speedAction = 20.0f; } level = m_speedAction; diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index 896114f4..231c2f69 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -1486,7 +1486,7 @@ bool CMotionVehicle::EventFrame(const Event &event) radius = 1.0f; } - if ( Math::Distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension? + if ( glm::distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension? { character = m_object->GetCharacter(); mat = m_object->GetWorldMatrix(0); @@ -1622,7 +1622,7 @@ bool CMotionVehicle::EventFrame(const Event &event) limit[1] = -10.0f*Math::PI/180.0f; } - if ( Math::Distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension? + if ( glm::distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension? { character = m_object->GetCharacter(); mat = m_object->GetWorldMatrix(0); diff --git a/src/object/object_create_params.h b/src/object/object_create_params.h index fa07d91f..0e6f0393 100644 --- a/src/object/object_create_params.h +++ b/src/object/object_create_params.h @@ -19,10 +19,10 @@ #pragma once -#include "math/vector.h" - #include "object/object_type.h" +#include + struct ObjectCreateParams { glm::vec3 pos; diff --git a/src/object/object_manager.h b/src/object/object_manager.h index 8572a677..ecee8b28 100644 --- a/src/object/object_manager.h +++ b/src/object/object_manager.h @@ -27,7 +27,6 @@ #include "common/singleton.h" #include "math/const.h" -#include "math/vector.h" #include "object/object_create_params.h" #include "object/object_interface_type.h" @@ -35,6 +34,8 @@ #include "object/interface/destroyable_object.h" +#include + #include #include #include diff --git a/src/object/task/taskadvance.h b/src/object/task/taskadvance.h index 9377c6e8..66f0479d 100644 --- a/src/object/task/taskadvance.h +++ b/src/object/task/taskadvance.h @@ -22,7 +22,7 @@ #include "object/task/task.h" -#include "math/vector.h" +#include diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index ac52bb85..4455b994 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -246,7 +246,7 @@ bool CTaskBuild::EventProcess(const Event &event) if ( m_phase == TBP_MOVE ) // preliminary forward/backward? { - dist = Math::Distance(m_object->GetPosition(), m_metal->GetPosition()); + dist = glm::distance(m_object->GetPosition(), m_metal->GetPosition()); linSpeed = 0.0f; if ( m_physics->GetLand() ) { @@ -362,7 +362,7 @@ bool CTaskBuild::EventProcess(const Event &event) { pv = m_object->GetPosition(); pm = m_metal->GetPosition(); - dist = Math::Distance(pv, pm); + dist = glm::distance(pv, pm); diff = pm.y - 8.0f - pv.y; tilt = m_object->GetRotation(); m_object->StartTaskGunGoal(asin(diff/dist)-tilt.z, 0.0f); @@ -453,7 +453,7 @@ Error CTaskBuild::IsEnded() { m_physics->SetMotorSpeedZ(0.0f); - dist = Math::Distance(m_object->GetPosition(), m_metal->GetPosition()); + dist = glm::distance(m_object->GetPosition(), m_metal->GetPosition()); if ( dist > 30.0f ) { time = m_physics->GetLinTimeLength(dist-30.0f, 1.0f); @@ -472,7 +472,7 @@ Error CTaskBuild::IsEnded() if ( m_phase == TBP_MOVE ) // preliminary forward/backward? { - dist = Math::Distance(m_object->GetPosition(), m_metal->GetPosition()); + dist = glm::distance(m_object->GetPosition(), m_metal->GetPosition()); if ( !m_physics->GetLand()) { @@ -526,7 +526,7 @@ Error CTaskBuild::IsEnded() m_object->SetObjectParent(1, 0); pv = m_object->GetPosition(); pm = m_metal->GetPosition(); - dist = Math::Distance(pv, pm); + dist = glm::distance(pv, pm); diff = pm.y - 8.0f - pv.y; tilt = m_object->GetRotation(); if(dist) m_object->StartTaskGunGoal(asin(diff/dist)-tilt.z, 0.0f); @@ -714,7 +714,7 @@ Error CTaskBuild::FlatFloor() if ( type == OBJECT_BASE ) { glm::vec3 oPos = pObj->GetPosition(); - dist = Math::Distance(center, oPos)-80.0f; + dist = glm::distance(center, oPos)-80.0f; if ( dist < max ) { max = dist; @@ -730,7 +730,7 @@ Error CTaskBuild::FlatFloor() glm::vec3 oPos = crashSphere.sphere.pos; float oRadius = crashSphere.sphere.radius; - dist = Math::Distance(center, oPos)-oRadius; + dist = glm::distance(center, oPos)-oRadius; if ( dist < max ) { max = dist; @@ -782,7 +782,7 @@ Error CTaskBuild::FlatFloor() glm::vec3 oPos = crashSphere.sphere.pos; float oRadius = crashSphere.sphere.radius; - dist = Math::Distance(center, oPos)-oRadius; + dist = glm::distance(center, oPos)-oRadius; if ( dist < max ) { max = dist; @@ -831,7 +831,7 @@ CObject* CTaskBuild::SearchMetalObject(float &angle, float dMin, float dMax, bMetal = true; // metal exists oPos = pObj->GetPosition(); - distance = Math::Distance(oPos, iPos); + distance = glm::distance(oPos, iPos); a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW! if ( distance > dMax ) continue; @@ -886,7 +886,7 @@ void CTaskBuild::DeleteMark(glm::vec3 pos, float radius) type != OBJECT_MARKPOWER ) continue; glm::vec3 oPos = obj->GetPosition(); - float distance = Math::Distance(oPos, pos); + float distance = glm::distance(oPos, pos); if ( distance <= radius ) { objectsToDelete.push_back(obj); diff --git a/src/object/task/taskbuild.h b/src/object/task/taskbuild.h index a2866d11..fd6c59a6 100644 --- a/src/object/task/taskbuild.h +++ b/src/object/task/taskbuild.h @@ -22,10 +22,10 @@ #include "object/task/task.h" -#include "math/vector.h" - #include "object/object_type.h" +#include + class CObject; diff --git a/src/object/task/taskfireant.cpp b/src/object/task/taskfireant.cpp index 1685af29..b6244603 100644 --- a/src/object/task/taskfireant.cpp +++ b/src/object/task/taskfireant.cpp @@ -171,7 +171,7 @@ Error CTaskFireAnt::IsEnded() pos = glm::vec3(-2.5f, -0.7f, 0.0f); mat = m_object->GetWorldMatrix(2); pos = Math::Transform(*mat, pos); - dist = Math::Distance(pos, m_impact); + dist = glm::distance(pos, m_impact); speed = m_impact-pos; speed.x += (Math::Rand()-0.5f)*dist*1.2f; speed.y += (Math::Rand()-0.5f)*dist*0.4f+50.0f; diff --git a/src/object/task/taskfireant.h b/src/object/task/taskfireant.h index f9057041..ec1451db 100644 --- a/src/object/task/taskfireant.h +++ b/src/object/task/taskfireant.h @@ -22,7 +22,7 @@ #include "object/task/task.h" -#include "math/vector.h" +#include enum TaskFireAnt diff --git a/src/object/task/taskflag.cpp b/src/object/task/taskflag.cpp index eff8bc12..1c886dc6 100644 --- a/src/object/task/taskflag.cpp +++ b/src/object/task/taskflag.cpp @@ -265,7 +265,7 @@ Error CTaskFlag::CreateFlag(int rank) CObject* pObj = SearchNearest(pos, OBJECT_NULL); if ( pObj != nullptr ) { - float dist = Math::Distance(pos, pObj->GetPosition()); + float dist = glm::distance(pos, pObj->GetPosition()); if ( dist < 10.0f ) { return ERR_FLAG_PROXY; @@ -305,7 +305,7 @@ Error CTaskFlag::DeleteFlag() { return ERR_FLAG_DELETE; } - dist = Math::Distance(iPos, pObj->GetPosition()); + dist = glm::distance(iPos, pObj->GetPosition()); if ( dist > 10.0f ) { return ERR_FLAG_DELETE; diff --git a/src/object/task/taskflag.h b/src/object/task/taskflag.h index eadcd050..1e16424a 100644 --- a/src/object/task/taskflag.h +++ b/src/object/task/taskflag.h @@ -21,10 +21,10 @@ #include "object/task/task.h" -#include "math/vector.h" - #include "object/object_type.h" +#include + class CObject; diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index 95eb1f71..0a708b46 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -638,7 +638,7 @@ void CTaskGoto::WormFrame(float rTime) if ( pObj != nullptr ) { pos = m_object->GetPosition(); - dist = Math::Distance(pos, impact); + dist = glm::distance(pos, impact); if ( dist <= 15.0f ) { pObj->SetVirusMode(true); // bam, infected! @@ -1019,7 +1019,7 @@ Error CTaskGoto::IsEnded() if ( m_phase == TGP_CRADVANCE ) // advance after collision? { - if ( Math::Distance(pos, m_pos) >= 5.0f ) + if ( glm::distance(pos, m_pos) >= 5.0f ) { m_phase = TGP_ADVANCE; } @@ -1052,7 +1052,7 @@ Error CTaskGoto::IsEnded() if ( m_phase == TGP_CLADVANCE ) // advance after collision? { - if ( Math::Distance(pos, m_pos) >= 10.0f ) + if ( glm::distance(pos, m_pos) >= 10.0f ) { m_phase = TGP_ADVANCE; m_try ++; @@ -1068,7 +1068,7 @@ Error CTaskGoto::IsEnded() return ERR_STOP; } - dist = Math::Distance(m_bmFinalPos, m_object->GetPosition()); + dist = glm::distance(m_bmFinalPos, m_object->GetPosition()); if ( dist < m_bmFinalDist ) return ERR_CONTINUE; m_physics->SetMotorSpeedX(0.0f); // stops the advance return ERR_STOP; @@ -1153,7 +1153,7 @@ bool CTaskGoto::AdjustTarget(CObject* pObj, glm::vec3 &pos, float &distance) { pos = m_object->GetPosition(); goal = pObj->GetPosition(); - dist = Math::Distance(goal, pos); + dist = glm::distance(goal, pos); pos = (pos-goal)*(TAKE_DIST+distance)/dist + goal; return true; // approach from all sites } @@ -1162,7 +1162,7 @@ bool CTaskGoto::AdjustTarget(CObject* pObj, glm::vec3 &pos, float &distance) { pos = m_object->GetPosition(); goal = pObj->GetPosition(); - dist = Math::Distance(goal, pos); + dist = glm::distance(goal, pos); pos = (pos-goal)*(TAKE_DIST+distance)/dist + goal; return true; // approach from all sites } @@ -1439,7 +1439,7 @@ void CTaskGoto::ComputeRepulse(glm::vec2&dir) glm::vec3 iPos = firstCrashSphere.sphere.pos; float iRadius = firstCrashSphere.sphere.radius; - gDist = Math::Distance(iPos, m_goal); + gDist = glm::distance(iPos, m_goal); add = m_physics->GetLinStopLength()*1.1f; // braking distance fac = 2.0f; @@ -1551,7 +1551,7 @@ void CTaskGoto::ComputeRepulse(glm::vec2&dir) if ( oPos.y-oRadius > iPos.y+iRadius ) continue; if ( oPos.y+oRadius < iPos.y-iRadius ) continue; - dist = Math::Distance(oPos, m_goal); + dist = glm::distance(oPos, m_goal); if ( dist <= 1.0f ) continue; // on purpose? oRadius += iRadius+addi; diff --git a/src/object/task/taskgoto.h b/src/object/task/taskgoto.h index 46ed6e92..1aba2a05 100644 --- a/src/object/task/taskgoto.h +++ b/src/object/task/taskgoto.h @@ -21,8 +21,6 @@ #include "object/task/task.h" -#include "math/vector.h" - #include #include diff --git a/src/object/task/taskmanip.cpp b/src/object/task/taskmanip.cpp index 61e20bd7..fe68fcbb 100644 --- a/src/object/task/taskmanip.cpp +++ b/src/object/task/taskmanip.cpp @@ -461,7 +461,7 @@ Error CTaskManip::Start(TaskManipOrder order, TaskManipArm arm) } } - dist = Math::Distance(m_object->GetPosition(), m_targetPos); + dist = glm::distance(m_object->GetPosition(), m_targetPos); len = dist-TAKE_DIST; if ( m_arm == TMA_OTHER ) len -= TAKE_DIST_OTHER; if ( len < 0.0f ) len = 0.0f; @@ -548,7 +548,7 @@ Error CTaskManip::IsEnded() if ( m_timeLimit <= 0.0f ) { //OK 1.9 - dist = Math::Distance(m_object->GetPosition(), m_targetPos); + dist = glm::distance(m_object->GetPosition(), m_targetPos); if ( dist <= m_advanceLength + 2.0f ) { m_move = 0.0f; // advance ended @@ -566,7 +566,7 @@ Error CTaskManip::IsEnded() } } - dist = Math::Distance(m_object->GetPosition(), m_targetPos); + dist = glm::distance(m_object->GetPosition(), m_targetPos); if ( dist <= m_advanceLength ) { m_move = 0.0f; // advance ended @@ -714,7 +714,7 @@ CObject* CTaskManip::SearchTakeUnderObject(glm::vec3 &pos, float dLimit) if ( pObj->GetScaleY() != 1.0f ) continue; oPos = pObj->GetPosition(); - distance = Math::Distance(oPos, iPos); + distance = glm::distance(oPos, iPos); if ( distance <= dLimit && distance < min ) { @@ -766,7 +766,7 @@ CObject* CTaskManip::SearchTakeFrontObject(bool bAdvance, glm::vec3 &pos, if ( pObj->GetScaleY() != 1.0f ) continue; oPos = pObj->GetPosition(); - distance = fabs(Math::Distance(oPos, iPos)-TAKE_DIST); + distance = fabs(glm::distance(oPos, iPos)-TAKE_DIST); f = 1.0f-distance/50.0f; if ( f < 0.5f ) f = 0.5f; @@ -833,7 +833,7 @@ CObject* CTaskManip::SearchTakeBackObject(bool bAdvance, glm::vec3 &pos, if ( pObj->GetScaleY() != 1.0f ) continue; oPos = pObj->GetPosition(); - distance = fabs(Math::Distance(oPos, iPos)-TAKE_DIST); + distance = fabs(glm::distance(oPos, iPos)-TAKE_DIST); f = 1.0f-distance/50.0f; if ( f < 0.5f ) f = 0.5f; @@ -940,7 +940,7 @@ CObject* CTaskManip::SearchOtherObject(bool bAdvance, glm::vec3 &pos, angle = Math::RotateAngle(iPos.x-oPos.x, oPos.z-iPos.z); // CW ! if ( !Math::TestAngle(angle, oAngle-oLimit, oAngle+oLimit) ) continue; - distance = fabs(Math::Distance(oPos, iPos)-TAKE_DIST); + distance = fabs(glm::distance(oPos, iPos)-TAKE_DIST); if ( distance <= dLimit ) { angle = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW ! @@ -1232,7 +1232,7 @@ bool CTaskManip::IsFreeDeposeObject(glm::vec3 pos) for (const auto& crashSphere : obj->GetAllCrashSpheres()) { - if ( Math::Distance(iPos, crashSphere.sphere.pos)-(crashSphere.sphere.radius+1.0f) < 2.0f ) + if ( glm::distance(iPos, crashSphere.sphere.pos)-(crashSphere.sphere.radius+1.0f) < 2.0f ) { return false; // location occupied } diff --git a/src/object/task/taskmanip.h b/src/object/task/taskmanip.h index abb74a1d..d2cd38ed 100644 --- a/src/object/task/taskmanip.h +++ b/src/object/task/taskmanip.h @@ -22,10 +22,10 @@ #include "object/task/task.h" -#include "math/vector.h" - #include "object/object_type.h" +#include + class CObject; diff --git a/src/object/task/taskpen.h b/src/object/task/taskpen.h index 24e0a158..fa5ba2be 100644 --- a/src/object/task/taskpen.h +++ b/src/object/task/taskpen.h @@ -21,10 +21,10 @@ #include "object/task/task.h" -#include "math/vector.h" - #include "object/interface/trace_drawing_object.h" +#include + enum TaskPenPhase { diff --git a/src/object/task/taskrecover.cpp b/src/object/task/taskrecover.cpp index 5059fd26..27fc7f48 100644 --- a/src/object/task/taskrecover.cpp +++ b/src/object/task/taskrecover.cpp @@ -98,7 +98,7 @@ bool CTaskRecover::EventProcess(const Event &event) if ( m_phase == TRP_MOVE ) // preliminary forward/backward? { - dist = Math::Distance(m_object->GetPosition(), m_ruin->GetPosition()); + dist = glm::distance(m_object->GetPosition(), m_ruin->GetPosition()); linSpeed = 0.0f; if ( dist > RECOVER_DIST ) linSpeed = 1.0f; if ( dist < RECOVER_DIST ) linSpeed = -1.0f; @@ -246,7 +246,7 @@ Error CTaskRecover::IsEnded() { m_physics->SetMotorSpeedZ(0.0f); - dist = Math::Distance(m_object->GetPosition(), m_ruin->GetPosition()); + dist = glm::distance(m_object->GetPosition(), m_ruin->GetPosition()); if ( dist > RECOVER_DIST ) { time = m_physics->GetLinTimeLength(dist-RECOVER_DIST, 1.0f); @@ -265,7 +265,7 @@ Error CTaskRecover::IsEnded() if ( m_phase == TRP_MOVE ) // preliminary advance? { - dist = Math::Distance(m_object->GetPosition(), m_ruin->GetPosition()); + dist = glm::distance(m_object->GetPosition(), m_ruin->GetPosition()); if ( dist >= RECOVER_DIST-1.0f && dist <= RECOVER_DIST+1.0f ) diff --git a/src/object/task/taskrecover.h b/src/object/task/taskrecover.h index 0d64e6cf..5fd0c6d0 100644 --- a/src/object/task/taskrecover.h +++ b/src/object/task/taskrecover.h @@ -22,7 +22,7 @@ #include "object/task/task.h" -#include "math/vector.h" +#include class CObject; diff --git a/src/object/task/taskshield.cpp b/src/object/task/taskshield.cpp index 7347cde8..7436d4cb 100644 --- a/src/object/task/taskshield.cpp +++ b/src/object/task/taskshield.cpp @@ -553,7 +553,7 @@ void CTaskShield::IncreaseShield() if (!shielded->IsRepairable()) continue; // NOTE: Looks like the original code forgot to check that glm::vec3 oPos = obj->GetPosition(); - float dist = Math::Distance(oPos, m_shieldPos); + float dist = glm::distance(oPos, m_shieldPos); if ( dist <= GetRadius()+10.0f ) { shielded->SetShield(shielded->GetShield() + 0.1f); diff --git a/src/object/task/taskshield.h b/src/object/task/taskshield.h index b4ca9859..cb6553b1 100644 --- a/src/object/task/taskshield.h +++ b/src/object/task/taskshield.h @@ -22,7 +22,7 @@ #include "object/task/task.h" -#include "math/vector.h" +#include const float RADIUS_SHIELD_MIN = 40.0f; // minimum radius of the protected zone diff --git a/src/object/task/tasktake.cpp b/src/object/task/tasktake.cpp index 38431cf5..2411de02 100644 --- a/src/object/task/tasktake.cpp +++ b/src/object/task/tasktake.cpp @@ -309,7 +309,7 @@ CObject* CTaskTake::SearchTakeObject(float &angle, if ( pObj->GetScaleY() != 1.0f ) continue; oPos = pObj->GetPosition(); - distance = Math::Distance(oPos, iPos); + distance = glm::distance(oPos, iPos); if ( distance >= 4.0f-dLimit && distance <= 4.0f+dLimit ) { @@ -400,7 +400,7 @@ CObject* CTaskTake::SearchFriendObject(float &angle, Math::Matrix* mat = pObj->GetWorldMatrix(0); glm::vec3 oPos = Math::Transform(*mat, dynamic_cast(*pObj).GetPowerPosition()); - float distance = fabs(Math::Distance(oPos, iPos) - (iRad+1.0f)); + float distance = fabs(glm::distance(oPos, iPos) - (iRad+1.0f)); if ( distance <= dLimit ) { angle = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW ! @@ -541,7 +541,7 @@ bool CTaskTake::IsFreeDeposeObject(glm::vec3 pos) for (const auto& crashSphere : pObj->GetAllCrashSpheres()) { - if ( Math::Distance(iPos, crashSphere.sphere.pos)-(crashSphere.sphere.radius+1.0f) < 1.0f ) + if ( glm::distance(iPos, crashSphere.sphere.pos)-(crashSphere.sphere.radius+1.0f) < 1.0f ) { return false; // location occupied } diff --git a/src/object/task/tasktake.h b/src/object/task/tasktake.h index 31b2ef3b..9eb60338 100644 --- a/src/object/task/tasktake.h +++ b/src/object/task/tasktake.h @@ -21,10 +21,10 @@ #include "object/task/task.h" -#include "math/vector.h" - #include "object/object_type.h" +#include + class CObject; diff --git a/src/object/task/taskterraform.cpp b/src/object/task/taskterraform.cpp index f0a856e1..039910bb 100644 --- a/src/object/task/taskterraform.cpp +++ b/src/object/task/taskterraform.cpp @@ -282,7 +282,7 @@ Error CTaskTerraform::IsEnded() pos.z = m_terraPos.z+(Math::Rand()-0.5f)*80.0f; pos.y = m_terraPos.y; m_terrain->AdjustToFloor(pos); - dist = Math::Distance(pos, m_terraPos); + dist = glm::distance(pos, m_terraPos); speed = glm::vec3(0.0f, 0.0f, 0.0f); dim.x = 2.0f+(40.0f-dist)/(1.0f+Math::Rand()*4.0f); dim.y = dim.x; @@ -412,7 +412,7 @@ bool CTaskTerraform::Terraform() type == OBJECT_BARRIER3 || type == OBJECT_APOLLO4 ) // everything what fits? { - dist = Math::Distance(m_terraPos, pObj->GetPosition()); + dist = glm::distance(m_terraPos, pObj->GetPosition()); if ( type == OBJECT_BULLET || type == OBJECT_NEST || @@ -457,7 +457,7 @@ bool CTaskTerraform::Terraform() if ( !pObj->Implements(ObjectInterfaceType::Movable) ) continue; motion = dynamic_cast(*pObj).GetMotion(); - dist = Math::Distance(m_terraPos, pObj->GetPosition()); + dist = glm::distance(m_terraPos, pObj->GetPosition()); if ( dist > ACTION_RADIUS ) continue; if ( type == OBJECT_ANT || type == OBJECT_SPIDER ) diff --git a/src/object/task/taskterraform.h b/src/object/task/taskterraform.h index fb20c4bd..acc5db1d 100644 --- a/src/object/task/taskterraform.h +++ b/src/object/task/taskterraform.h @@ -22,7 +22,7 @@ #include "object/task/task.h" -#include "math/vector.h" +#include enum TaskTerraPhase diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 9c9f2683..63b57caf 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -2552,7 +2552,7 @@ int CPhysics::ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle) if ( oType == OBJECT_TARGET2 && !pObj->GetLock() ) { glm::vec3 oPos = pObj->GetPosition(); - distance = Math::Distance(oPos, iPos); + distance = glm::distance(oPos, iPos); if ( distance < 10.0f*1.5f ) { m_sound->Play(SOUND_WAYPOINT, m_object->GetPosition()); @@ -2573,10 +2573,10 @@ int CPhysics::ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle) if ( iType == OBJECT_BEE && oRad <= 1.2f ) continue; if ( iType == OBJECT_WORM && oRad <= 1.2f ) continue; - distance = Math::Distance(oPos, iPos); + distance = glm::distance(oPos, iPos); if ( distance < iRad+oRad ) // collision? { - distance = Math::Distance(oPos, iiPos); + distance = glm::distance(oPos, iiPos); if ( distance >= iRad+oRad ) // view (*) { m_bCollision = true; @@ -2664,7 +2664,7 @@ bool CPhysics::JostleObject(CJostleableObject* pObj, glm::vec3 iPos, float iRad) { Math::Sphere jostlingSphere = pObj->GetJostlingSphere(); - float distance = Math::Distance(jostlingSphere.pos, iPos); + float distance = glm::distance(jostlingSphere.pos, iPos); if ( distance >= iRad+jostlingSphere.radius) return false; float d = (iRad+jostlingSphere.radius)/2.0f; @@ -3041,7 +3041,7 @@ void CPhysics::CrashParticle(float crash) ppos.x = pos.x + (Math::Rand()-0.5f)*15.0f*crash; ppos.z = pos.z + (Math::Rand()-0.5f)*15.0f*crash; ppos.y = pos.y + Math::Rand()*4.0f; - len = 1.0f-(Math::Distance(ppos, pos)/(15.0f+5.0f)); + len = 1.0f-(glm::distance(ppos, pos)/(15.0f+5.0f)); if ( len <= 0.0f ) continue; speed.x = (ppos.x-pos.x)*0.1f; speed.z = (ppos.z-pos.z)*0.1f; @@ -3731,10 +3731,10 @@ void CPhysics::WheelParticle(TraceColor color, float width) while ( true ) { - dist1 = Math::Distance(m_wheelParticlePos[0], goal1); + dist1 = glm::distance(m_wheelParticlePos[0], goal1); if ( dist1 < step ) break; - dist2 = Math::Distance(m_wheelParticlePos[1], goal2); + dist2 = glm::distance(m_wheelParticlePos[1], goal2); wheel1 = Math::SegmentPoint(m_wheelParticlePos[0], goal1, step); wheel2 = Math::SegmentPoint(m_wheelParticlePos[1], goal2, step * dist2 / dist1); diff --git a/src/physics/physics.h b/src/physics/physics.h index 078cccc6..ed957a2b 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -27,12 +27,12 @@ #include "common/error.h" -#include "math/vector.h" - #include "object/object_type.h" #include "object/interface/trace_drawing_object.h" +#include + class CObject; class COldObject; diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 6a68ffd0..ef0a5b87 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -1732,7 +1732,7 @@ bool CScriptFunctions::rDistance(CBotVar* var, CBotVar* result, int& exception, if ( !GetPoint(var, exception, p1) ) return true; if ( !GetPoint(var, exception, p2) ) return true; - value = Math::Distance(p1, p2); + value = glm::distance(p1, p2); result->SetValFloat(value/g_unit); return true; } diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 77f125f1..6f840f65 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -24,12 +24,12 @@ #pragma once -#include "math/vector.h" - #include "sound/sound.h" #include "sound/oalsound/check.h" +#include + #include #include #include diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index 8a3595fe..e6439d3f 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -21,7 +21,7 @@ #include "common/logger.h" -#include "math/vector.h" +#include "math/func.h" #include #include diff --git a/src/sound/sound.h b/src/sound/sound.h index 5c7fb1d1..c5877c41 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -26,7 +26,7 @@ #include "sound/sound_type.h" -#include "math/vector.h" +#include #include diff --git a/src/tools/convert_model.cpp b/src/tools/convert_model.cpp index 563e0095..dd1fddd0 100644 --- a/src/tools/convert_model.cpp +++ b/src/tools/convert_model.cpp @@ -23,6 +23,8 @@ #include "graphics/model/model_io_exception.h" #include "graphics/model/model_output.h" +#include "math/func.h" + #include #include #include diff --git a/test/unit/math/matrix_test.cpp b/test/unit/math/matrix_test.cpp index 1f031e26..2e634900 100644 --- a/test/unit/math/matrix_test.cpp +++ b/test/unit/math/matrix_test.cpp @@ -275,7 +275,7 @@ TEST(MatrixTest, MultiplyVectorTest) const glm::vec3 expectedMultiply1(0.608932463260470f, -1.356893266403749f, 3.457156276255142f); glm::vec3 multiply1 = Math::MatrixVectorMultiply(mat1, vec1, false); - EXPECT_TRUE(Math::VectorsEqual(multiply1, expectedMultiply1, TEST_TOLERANCE)); + EXPECT_TRUE(glm::all(glm::epsilonEqual(multiply1, expectedMultiply1, TEST_TOLERANCE))); const Math::Matrix mat2( { @@ -291,5 +291,5 @@ TEST(MatrixTest, MultiplyVectorTest) const glm::vec3 expectedMultiply2(0.2816820577317669f, 0.0334468811767428f, 0.1996974284970455f); glm::vec3 multiply2 = Math::MatrixVectorMultiply(mat2, vec2, true); - EXPECT_TRUE(Math::VectorsEqual(multiply2, expectedMultiply2, TEST_TOLERANCE)); + EXPECT_TRUE(glm::all(glm::epsilonEqual(multiply2, expectedMultiply2, TEST_TOLERANCE))); } diff --git a/test/unit/math/vector_test.cpp b/test/unit/math/vector_test.cpp index 0df31162..b2508ee3 100644 --- a/test/unit/math/vector_test.cpp +++ b/test/unit/math/vector_test.cpp @@ -25,7 +25,9 @@ */ #include "math/func.h" -#include "math/vector.h" + +#include +#include #include @@ -48,7 +50,7 @@ TEST(VectorTest, NormalizeTest) vec = glm::normalize(vec); - EXPECT_TRUE(Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE)); + EXPECT_TRUE(glm::all(glm::epsilonEqual(vec, expectedNormalized, TEST_TOLERANCE))); } TEST(VectorTest, DotTest) @@ -69,7 +71,7 @@ TEST(VectorTest, CrossTest) glm::vec3 expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581); glm::vec3 expectedReverseCross = -expectedCross; - EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecA, vecB), expectedCross, TEST_TOLERANCE)); + EXPECT_TRUE(glm::all(glm::epsilonEqual(glm::cross(vecA, vecB), expectedCross, TEST_TOLERANCE))); - EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecB, vecA), expectedReverseCross, TEST_TOLERANCE)); + EXPECT_TRUE(glm::all(glm::epsilonEqual(glm::cross(vecB, vecA), expectedReverseCross, TEST_TOLERANCE))); }