diff --git a/src/app/input.cpp b/src/app/input.cpp index 6f02488b..1177a0f1 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -197,8 +197,8 @@ void CInput::EventProcess(Event& event) } } - event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); - event.cameraInput = Math::Clamp(m_joyMotionCam + m_cameraKeyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); + event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(1.0f, 1.0f, 1.0f)); + event.cameraInput = Math::Clamp(m_joyMotionCam + m_cameraKeyMotion, glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(1.0f, 1.0f, 1.0f)); } void CInput::MouseMove(const glm::ivec2& pos) @@ -219,10 +219,10 @@ bool CInput::GetMouseButtonState(int index) const void CInput::ResetKeyStates() { GetLogger()->Trace("Reset key states\n"); - m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f); - m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f); - m_cameraKeyMotion = Math::Vector(0.0f, 0.0f, 0.0f); - m_joyMotionCam = Math::Vector(0.0f, 0.0f, 0.0f); + m_keyMotion = glm::vec3(0.0f, 0.0f, 0.0f); + m_joyMotion = glm::vec3(0.0f, 0.0f, 0.0f); + m_cameraKeyMotion = glm::vec3(0.0f, 0.0f, 0.0f); + m_joyMotionCam = glm::vec3(0.0f, 0.0f, 0.0f); for(int i=0; iGetType(); - Math::Vector min; + Math::Vector min{}; min.x = Math::Min(m_actualEye.x, m_actualLookat.x); min.y = Math::Min(m_actualEye.y, m_actualLookat.y); min.z = Math::Min(m_actualEye.z, m_actualLookat.z); - Math::Vector max; + Math::Vector max{}; max.x = Math::Max(m_actualEye.x, m_actualLookat.x); max.y = Math::Max(m_actualEye.y, m_actualLookat.y); max.z = Math::Max(m_actualEye.z, m_actualLookat.z); @@ -880,7 +880,7 @@ void CCamera::IsCollisionBack() oPos.y-oRadius > max.y || oPos.z-oRadius > max.z ) continue; - Math::Vector proj = Projection(m_actualEye, m_actualLookat, oPos); + Math::Vector proj = Math::Projection(m_actualEye, m_actualLookat, oPos); float dpp = Math::Distance(proj, oPos); if ( dpp > oRadius ) continue; @@ -935,7 +935,7 @@ void CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) if (dist < objRadius) { dist = Math::Distance(eye, lookat); - Math::Vector proj = Projection(eye, lookat, objPos); + Math::Vector proj = Math::Projection(eye, lookat, objPos); eye = (lookat - eye) * objRadius / dist + proj; return; } @@ -1230,7 +1230,7 @@ bool CCamera::EventFrameBack(const Event &event) m_centeringCurrentH = m_centeringAngleH * centeringH; m_centeringCurrentV = m_centeringAngleV * centeringV; - m_eyePt = RotateView(lookatPt, h, v, d); + m_eyePt = Math::RotateView(lookatPt, h, v, d); bool ground = true; if (m_cameraObj->Implements(ObjectInterfaceType::Movable)) @@ -1275,7 +1275,7 @@ bool CCamera::EventFrameFix(const Event &event) float v = m_fixDirectionV; float d = m_fixDist; - m_eyePt = RotateView(lookatPt, h, v, d); + m_eyePt = Math::RotateView(lookatPt, h, v, d); if (m_type == CAM_TYPE_PLANE) m_eyePt.y += m_fixDist / 2.0f; m_eyePt = ExcludeTerrain(m_eyePt, lookatPt, h, v); m_eyePt = ExcludeObject(m_eyePt, lookatPt, h, v); @@ -1354,7 +1354,7 @@ bool CCamera::EventFrameVisit(const Event &event) float angleH = (m_visitTime / 10.0f) * (Math::PI * 2.0f); float angleV = m_visitDirectionV; - Math::Vector eye = RotateView(m_visitGoal, angleH, angleV, m_visitDist); + Math::Vector eye = Math::RotateView(m_visitGoal, angleH, angleV, m_visitDist); eye = ExcludeTerrain(eye, m_visitGoal, angleH, angleV); eye = ExcludeObject(eye, m_visitGoal, angleH, angleV); UpdateCameraAnimation(eye, m_visitGoal, event.rTime); @@ -1414,7 +1414,7 @@ Math::Vector CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat, if ( pos.y > eye.y ) { angleV = -Math::RotateAngle(dist, pos.y-lookat.y); - eye = RotateView(lookat, angleH, angleV, dist); + eye = Math::RotateView(lookat, angleH, angleV, dist); } } return eye; @@ -1454,7 +1454,7 @@ void CCamera::SetCameraSpeed(float speed) Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllowed) { - Math::Vector delta; + Math::Vector delta{}; delta.x += m_mouseDelta.x * 2*Math::PI; delta.y -= m_mouseDelta.y * Math::PI; @@ -1478,7 +1478,7 @@ Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllow } } - if (delta.Length() > 0) + if (glm::length(delta) > 0) AbortCentering(); // special stops framing return delta; diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 70a803e4..00e4a46e 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -140,7 +140,7 @@ public: * \param lookat Initial lookat position * \param delay Time of the initial entry animation */ - void Init(Math::Vector eye, Math::Vector lookat, float delay); + void Init(glm::vec3 eye, glm::vec3 lookat, float delay); //! Sets the object controlling the camera void SetControllingObject(CObject* object); @@ -159,12 +159,12 @@ public: //! Returns the current point of view of the camera - void GetCamera(Math::Vector &eye, Math::Vector &lookat); + void GetCamera(glm::vec3 &eye, glm::vec3 &lookat); //! \name Visit camera management (CAM_TYPE_VISIT) - camera in this mode shows a position, constantly rotating around it //@{ //! Start visit camera - void StartVisit(Math::Vector goal, float dist); + void StartVisit(glm::vec3 goal, float dist); //! Stop visit camera void StopVisit(); //@} @@ -182,7 +182,7 @@ public: //! \name Camera shake effects //@{ //! Starts a camera shake effect - void StartEffect(CameraEffect effect, Math::Vector pos, float force); + void StartEffect(CameraEffect effect, glm::vec3 pos, float force); //! Removes the camera shake effect void FlushEffect(); //@} @@ -190,7 +190,7 @@ public: //! \name Camera overlay effects //@{ //! Starts camera overlay effect - void StartOver(CameraOverEffect effect, Math::Vector pos, float force); + void StartOver(CameraOverEffect effect, glm::vec3 pos, float force); //! Removes camera overlay effect void FlushOver(); //! Specifies camera overlay effect base color @@ -200,13 +200,13 @@ public: //! \name Script camera - cutscenes controlled by external code //@{ //! Script camera: Set camera position - void SetScriptCamera(Math::Vector eye, Math::Vector lookat); + void SetScriptCamera(glm::vec3 eye, glm::vec3 lookat); //! Script camera: Animate to given camera position - void SetScriptCameraAnimate(Math::Vector eye, Math::Vector lookat); + void SetScriptCameraAnimate(glm::vec3 eye, glm::vec3 lookat); //! Script camera: Animate to given eye position - void SetScriptCameraAnimateEye(Math::Vector eye); + void SetScriptCameraAnimateEye(glm::vec3 eye); //! Script camera: Animate to given lookat position - void SetScriptCameraAnimateLookat(Math::Vector lookat); + void SetScriptCameraAnimateLookat(glm::vec3 lookat); //@} //! \name Configuration settings @@ -250,7 +250,7 @@ protected: * \param rTime Time since last time this function was called (used to calculate animation) * \see SetViewParams */ - void UpdateCameraAnimation(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime); + void UpdateCameraAnimation(const glm::vec3 &eyePt, const glm::vec3 &lookatPt, float rTime); /** * \brief Avoid the obstacles @@ -261,16 +261,16 @@ protected: * \param eye Eye position, may be adjusted * \param lookat Lookat point */ - void IsCollision(Math::Vector &eye, Math::Vector lookat); + void IsCollision(glm::vec3 &eye, glm::vec3 lookat); //! Avoid the obstacles (CAM_TYPE_BACK) void IsCollisionBack(); //! Avoid the obstacles (CAM_TYPE_FIX or CAM_TYPE_PLANE) - void IsCollisionFix(Math::Vector &eye, Math::Vector lookat); + void IsCollisionFix(glm::vec3 &eye, glm::vec3 lookat); //! Adjusts the camera not to enter the ground - Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); + glm::vec3 ExcludeTerrain(glm::vec3 eye, glm::vec3 lookat, float &angleH, float &angleV); //! Adjusts the camera not to enter an object - Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); + glm::vec3 ExcludeObject(glm::vec3 eye, glm::vec3 lookat, float &angleH, float &angleV); /** * \brief Updates the location and direction of the camera in the 3D engine @@ -279,14 +279,14 @@ protected: * \param up Up vector * \see CEngine::SetViewParams */ - void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up = Math::Vector(0.0f, 1.0f, 0.0f)); + void SetViewParams(const glm::vec3 &eye, const glm::vec3 &lookat, const glm::vec3 &up = glm::vec3(0.0f, 1.0f, 0.0f)); /** * \brief Calculate camera movement (from user inputs) to apply - * \return Math::Vector where x, y represent respectively horizontal and vertical angle change in radians and z represents zoom (distance change) + * \return glm::vec3 where x, y represent respectively horizontal and vertical angle change in radians and z represents zoom (distance change) * \remarks Should not be called more often than once every EVENT_FRAME **/ - Math::Vector CalculateCameraMovement(const Event &event, bool keysAllowed = true); + glm::vec3 CalculateCameraMovement(const Event &event, bool keysAllowed = true); protected: CEngine* m_engine; @@ -306,22 +306,22 @@ protected: float m_initDelay; //! Current eye - Math::Vector m_actualEye; + glm::vec3 m_actualEye{ 0, 0, 0 }; //! Current aim - Math::Vector m_actualLookat; + glm::vec3 m_actualLookat{ 0, 0, 0 }; //! Final eye - Math::Vector m_finalEye; + glm::vec3 m_finalEye{ 0, 0, 0 }; //! Final lookat - Math::Vector m_finalLookat; + glm::vec3 m_finalLookat{ 0, 0, 0 }; //! Eye position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT - Math::Vector m_prevEye; + glm::vec3 m_prevEye{ 0, 0, 0 }; //! Lookat position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT - Math::Vector m_prevLookat; + glm::vec3 m_prevLookat{ 0, 0, 0 }; float m_focus; //! CAM_TYPE_FREE: eye - Math::Vector m_eyePt; + glm::vec3 m_eyePt{ 0, 0, 0 }; //! CAM_TYPE_FREE: horizontal direction float m_directionH; //! CAM_TYPE_FREE: vertical direction @@ -350,7 +350,7 @@ protected: float m_fixDirectionV; //! CAM_TYPE_VISIT: target position - Math::Vector m_visitGoal; + glm::vec3 m_visitGoal{ 0, 0, 0 }; //! CAM_TYPE_VISIT: distance float m_visitDist; //! CAM_TYPE_VISIT: relative time @@ -379,10 +379,10 @@ protected: float m_centeringProgress; CameraEffect m_effectType; - Math::Vector m_effectPos; + glm::vec3 m_effectPos{ 0, 0, 0 }; float m_effectForce; float m_effectProgress; - Math::Vector m_effectOffset; + glm::vec3 m_effectOffset{ 0, 0, 0 }; CameraOverEffect m_overType; float m_overForce; @@ -393,8 +393,8 @@ protected: float m_overFadeIn; float m_overFadeOut; - Math::Vector m_scriptEye; - Math::Vector m_scriptLookat; + glm::vec3 m_scriptEye{ 0, 0, 0 }; + glm::vec3 m_scriptLookat{ 0, 0, 0 }; //! Is camera frozen? bool m_freeze = false; diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp index 08c71848..182c6476 100644 --- a/src/graphics/engine/cloud.cpp +++ b/src/graphics/engine/cloud.cpp @@ -76,7 +76,7 @@ bool CCloud::EventFrame(const Event &event) return true; } -void CCloud::AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, +void CCloud::AdjustLevel(glm::vec3& pos, glm::vec3& eye, float deep, glm::vec2& uv1, glm::vec2& uv2) { uv1.x = (pos.x+20000.0f)/1280.0f; @@ -132,20 +132,20 @@ void CCloud::Draw() device->SetTransform(TRANSFORM_WORLD, matrix); float size = m_brickSize/2.0f; - Math::Vector eye = m_engine->GetEyePt(); - Math::Vector n = Math::Vector(0.0f, -1.0f, 0.0f); + glm::vec3 eye = m_engine->GetEyePt(); + glm::vec3 n = glm::vec3(0.0f, -1.0f, 0.0f); // Draws all the lines for (int i = 0; i < static_cast( m_lines.size() ); i++) { - Math::Vector pos; + glm::vec3 pos{}; pos.y = m_level; pos.z = m_lines[i].pz; pos.x = m_lines[i].px1; int vertexIndex = 0; - Math::Vector p; + glm::vec3 p{}; glm::vec2 uv1, uv2; p.x = pos.x-size; diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index f3b56d1a..8d19175d 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -81,7 +81,7 @@ protected: //! Makes the clouds evolve bool EventFrame(const Event &event); //! Adjusts the position to normal, to imitate the clouds at movement - void AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, + void AdjustLevel(glm::vec3& pos, glm::vec3& eye, float deep, glm::vec2& uv1, glm::vec2& uv2); //! Updates the positions, relative to the ground void CreateLine(int x, int y, int len); @@ -106,7 +106,7 @@ protected: int m_subdiv = 8; //! Wind speed - Math::Vector m_wind; + glm::vec3 m_wind{ 0, 0, 0 }; //! Brick mosaic int m_brickCount = 0; //! Size of a brick element diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index f405b9d4..9dc98e7d 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -185,8 +185,8 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_highlight = false; std::fill_n(m_highlightRank, 100, -1); m_highlightTime = 0.0f; - m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); - m_lookatPt = Math::Vector(0.0f, 0.0f, 1.0f); + m_eyePt = glm::vec3(0.0f, 0.0f, 0.0f); + m_lookatPt = glm::vec3(0.0f, 0.0f, 1.0f); m_drawWorld = true; m_drawFront = false; m_particleDensity = 1.0f; @@ -233,8 +233,8 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) // Compute bias matrix for shadow mapping Math::Matrix temp1, temp2; - Math::LoadScaleMatrix(temp1, Math::Vector(0.5f, 0.5f, 0.5f)); - Math::LoadTranslationMatrix(temp2, Math::Vector(1.0f, 1.0f, 1.0f)); + Math::LoadScaleMatrix(temp1, glm::vec3(0.5f, 0.5f, 0.5f)); + Math::LoadTranslationMatrix(temp2, glm::vec3(1.0f, 1.0f, 1.0f)); m_shadowBias = Math::MultiplyMatrices(temp1, temp2); m_lastState = -1; @@ -604,7 +604,7 @@ int CEngine::GetStatisticTriangle() return m_statisticTriangle; } -void CEngine::SetStatisticPos(Math::Vector pos) +void CEngine::SetStatisticPos(glm::vec3 pos) { m_statisticPos = pos; } @@ -853,9 +853,9 @@ void CEngine::DebugObject(int objRank) std::string vecStr; - vecStr = p1.bboxMin.ToString(); + vecStr = Math::ToString(p1.bboxMin); l->Debug(" bboxMin: %s\n", vecStr.c_str()); - vecStr = p1.bboxMax.ToString(); + vecStr = Math::ToString(p1.bboxMax); l->Debug(" bboxMax: %s\n", vecStr.c_str()); l->Debug(" totalTriangles: %d\n", p1.totalTriangles); l->Debug(" radius: %f\n", p1.boundingSphere.radius); @@ -994,7 +994,7 @@ void CEngine::SetObjectTransparency(int objRank, float value) m_objects[objRank].transparency = value; } -void CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max) +void CEngine::GetObjectBBox(int objRank, glm::vec3& min, glm::vec3& max) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); @@ -1251,7 +1251,7 @@ void CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, while (pos < 0.0f) pos += 1.0f; // never negative! - Math::Vector current; + glm::vec3 current{ 0, 0, 0 }; for (int i = 0; i < 6; i++) { @@ -1401,7 +1401,7 @@ void CEngine::SetObjectShadowSpotType(int objRank, EngineShadowType type) m_shadowSpots[shadowRank].type = type; } -void CEngine::SetObjectShadowSpotPos(int objRank, const Math::Vector& pos) +void CEngine::SetObjectShadowSpotPos(int objRank, const glm::vec3& pos) { assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); @@ -1502,7 +1502,7 @@ bool CEngine::GetBBox2D(int objRank, glm::vec2& min, glm::vec2& max) for (int i = 0; i < 8; i++) { - Math::Vector p; + glm::vec3 p{ 0, 0, 0 }; if ( i & (1<<0) ) p.x = p1.bboxMin.x; else p.x = p1.bboxMax.x; @@ -1511,7 +1511,7 @@ bool CEngine::GetBBox2D(int objRank, glm::vec2& min, glm::vec2& max) if ( i & (1<<2) ) p.z = p1.bboxMin.z; else p.z = p1.bboxMax.z; - Math::Vector pp; + glm::vec3 pp{ 0, 0, 0 }; if (TransformPoint(pp, objRank, p)) { if (pp.x < min.x) min.x = pp.x; @@ -1573,10 +1573,10 @@ void CEngine::DeleteGroundSpot(int rank) assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); m_groundSpots[rank].used = false; - m_groundSpots[rank].pos = Math::Vector(0.0f, 0.0f, 0.0f); + m_groundSpots[rank].pos = glm::vec3(0.0f, 0.0f, 0.0f); } -void CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos) +void CEngine::SetObjectGroundSpotPos(int rank, const glm::vec3& pos) { assert(rank >= 0 && rank < static_cast( m_groundSpots.size() )); @@ -1612,7 +1612,7 @@ void CEngine::SetObjectGroundSpotSmooth(int rank, float smooth) m_groundSpots[rank].smooth = smooth; } -void CEngine::CreateGroundMark(Math::Vector pos, float radius, +void CEngine::CreateGroundMark(glm::vec3 pos, float radius, float delay1, float delay2, float delay3, int dx, int dy, char* table) { @@ -1643,11 +1643,11 @@ void CEngine::ComputeDistance() if (! m_objects[i].used) continue; - Math::Vector v; + glm::vec3 v{}; v.x = m_eyePt.x - m_objects[i].transform.Get(1, 4); v.y = m_eyePt.y - m_objects[i].transform.Get(2, 4); v.z = m_eyePt.z - m_objects[i].transform.Get(3, 4); - m_objects[i].distance = v.Length(); + m_objects[i].distance = glm::length(v); } } @@ -1662,8 +1662,8 @@ void CEngine::UpdateGeometry() if (! p1.used) continue; - p1.bboxMin.LoadZero(); - p1.bboxMax.LoadZero(); + p1.bboxMin = { 0, 0, 0 }; + p1.bboxMax = { 0, 0, 0 }; for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { @@ -1770,7 +1770,7 @@ bool CEngine::DetectBBox(int objRank, const glm::vec2& mouse) for (int i = 0; i < 8; i++) { - Math::Vector p; + glm::vec3 p{ 0, 0, 0 }; if ( i & (1<<0) ) p.x = p1.bboxMin.x; else p.x = p1.bboxMax.x; @@ -1779,7 +1779,7 @@ bool CEngine::DetectBBox(int objRank, const glm::vec2& mouse) if ( i & (1<<2) ) p.z = p1.bboxMin.z; else p.z = p1.bboxMax.z; - Math::Vector pp; + glm::vec3 pp{ 0, 0, 0 }; if ( TransformPoint(pp, objRank, p) ) { if (pp.x < min.x) min.x = pp.x; @@ -1795,11 +1795,11 @@ bool CEngine::DetectBBox(int objRank, const glm::vec2& mouse) mouse.y <= max.y ); } -int CEngine::DetectObject(const glm::vec2& mouse, Math::Vector& targetPos, bool terrain) +int CEngine::DetectObject(const glm::vec2& mouse, glm::vec3& targetPos, bool terrain) { float min = 1000000.0f; int nearest = -1; - Math::Vector pos; + glm::vec3 pos{ 0, 0, 0 }; for (int objRank = 0; objRank < static_cast( m_objects.size() ); objRank++) { @@ -1863,11 +1863,11 @@ int CEngine::DetectObject(const glm::vec2& mouse, Math::Vector& targetPos, bool return nearest; } -bool CEngine::DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, Math::Vector& pos) +bool CEngine::DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, glm::vec3& pos) { assert(objRank >= 0 && objRank < static_cast(m_objects.size())); - Math::Vector p2D[3], p3D; + glm::vec3 p2D[3], p3D{ 0, 0, 0 }; for (int i = 0; i < 3; i++) { @@ -1910,11 +1910,11 @@ bool CEngine::DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int obj if (! Math::IsInsideTriangle(a, b, c, mouse)) return false; - Math::Vector a2 = Math::Transform(m_objects[objRank].transform, triangle[0].position); - Math::Vector b2 = Math::Transform(m_objects[objRank].transform, triangle[1].position); - Math::Vector c2 = Math::Transform(m_objects[objRank].transform, triangle[2].position); - Math::Vector e = Math::Transform(m_matView.Inverse(), Math::Vector(0.0f, 0.0f, -1.0f)); - Math::Vector f = Math::Transform(m_matView.Inverse(), Math::Vector( + glm::vec3 a2 = Math::Transform(m_objects[objRank].transform, triangle[0].position); + glm::vec3 b2 = Math::Transform(m_objects[objRank].transform, triangle[1].position); + glm::vec3 c2 = Math::Transform(m_objects[objRank].transform, triangle[2].position); + glm::vec3 e = Math::Transform(m_matView.Inverse(), glm::vec3(0.0f, 0.0f, -1.0f)); + glm::vec3 f = Math::Transform(m_matView.Inverse(), glm::vec3( (mouse.x*2.0f-1.0f)*m_matProj.Inverse().Get(1,1), (mouse.y*2.0f-1.0f)*m_matProj.Inverse().Get(2,2), 0.0f)); @@ -1946,57 +1946,57 @@ bool CEngine::IsVisible(const Math::Matrix& matrix, int objRank) return false; } -int CEngine::ComputeSphereVisibility(const Math::Matrix& m, const Math::Vector& center, float radius) +int CEngine::ComputeSphereVisibility(const Math::Matrix& m, const glm::vec3& center, float radius) { - Math::Vector vec[6]; + glm::vec3 vec[6]; float originPlane[6]; // Left plane vec[0].x = m.Get(4, 1) + m.Get(1, 1); vec[0].y = m.Get(4, 2) + m.Get(1, 2); vec[0].z = m.Get(4, 3) + m.Get(1, 3); - float l1 = vec[0].Length(); - vec[0].Normalize(); + float l1 = glm::length(vec[0]); + vec[0] = glm::normalize(vec[0]); originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1; // Right plane vec[1].x = m.Get(4, 1) - m.Get(1, 1); vec[1].y = m.Get(4, 2) - m.Get(1, 2); vec[1].z = m.Get(4, 3) - m.Get(1, 3); - float l2 = vec[1].Length(); - vec[1].Normalize(); + float l2 = glm::length(vec[1]); + vec[1] = glm::normalize(vec[1]); originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2; // Bottom plane vec[2].x = m.Get(4, 1) + m.Get(2, 1); vec[2].y = m.Get(4, 2) + m.Get(2, 2); vec[2].z = m.Get(4, 3) + m.Get(2, 3); - float l3 = vec[2].Length(); - vec[2].Normalize(); + float l3 = glm::length(vec[2]); + vec[2] = glm::normalize(vec[2]); originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3; // Top plane vec[3].x = m.Get(4, 1) - m.Get(2, 1); vec[3].y = m.Get(4, 2) - m.Get(2, 2); vec[3].z = m.Get(4, 3) - m.Get(2, 3); - float l4 = vec[3].Length(); - vec[3].Normalize(); + float l4 = glm::length(vec[3]); + vec[3] = glm::normalize(vec[3]); originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4; // Front plane vec[4].x = m.Get(4, 1) + m.Get(3, 1); vec[4].y = m.Get(4, 2) + m.Get(3, 2); vec[4].z = m.Get(4, 3) + m.Get(3, 3); - float l5 = vec[4].Length(); - vec[4].Normalize(); + float l5 = glm::length(vec[4]); + vec[4] = glm::normalize(vec[4]); originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5; // Back plane vec[5].x = m.Get(4, 1) - m.Get(3, 1); vec[5].y = m.Get(4, 2) - m.Get(3, 2); vec[5].z = m.Get(4, 3) - m.Get(3, 3); - float l6 = vec[5].Length(); - vec[5].Normalize(); + float l6 = glm::length(vec[5]); + vec[5] = glm::normalize(vec[5]); originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6; int result = 0; @@ -2017,7 +2017,7 @@ int CEngine::ComputeSphereVisibility(const Math::Matrix& m, const Math::Vector& return result; } -bool CEngine::InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius) +bool CEngine::InPlane(glm::vec3 normal, float originPlane, glm::vec3 center, float radius) { float distance = originPlane + Math::DotProduct(normal, center); @@ -2027,7 +2027,7 @@ bool CEngine::InPlane(Math::Vector normal, float originPlane, Math::Vector cente return true; } -bool CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D) +bool CEngine::TransformPoint(glm::vec3& p2D, int objRank, glm::vec3 p3D) { assert(objRank >= 0 && objRank < static_cast(m_objects.size())); @@ -2319,7 +2319,7 @@ void CEngine::SetMaterial(const Material& mat) m_device->SetMaterial(mat); } -void CEngine::SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec) +void CEngine::SetViewParams(const glm::vec3 &eyePt, const glm::vec3 &lookatPt, const glm::vec3 &upVec) { m_eyePt = eyePt; m_lookatPt = lookatPt; @@ -3232,12 +3232,12 @@ const Math::Matrix& CEngine::GetMatProj() return m_matProj; } -Math::Vector CEngine::GetEyePt() +glm::vec3 CEngine::GetEyePt() { return m_eyePt; } -Math::Vector CEngine::GetLookatPt() +glm::vec3 CEngine::GetLookatPt() { return m_lookatPt; } @@ -3252,7 +3252,7 @@ float CEngine::GetEyeDirV() return m_eyeDirV; } -bool CEngine::IsVisiblePoint(const Math::Vector &pos) +bool CEngine::IsVisiblePoint(const glm::vec3 &pos) { return Math::Distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance); } @@ -3836,15 +3836,15 @@ void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix& static constexpr int NUM_LINE_STRIPS = 2 + LONGITUDE_DIVISIONS + LATITUDE_DIVISIONS; static constexpr int VERTS_IN_LINE_STRIP = 32; - static std::array verticesTemplate = [] + static std::array verticesTemplate = [] { - std::array vertices; + std::array vertices; auto SpherePoint = [&](float latitude, float longitude) { float latitudeAngle = (latitude - 0.5f) * 2.0f * Math::PI; float longitudeAngle = longitude * 2.0f * Math::PI; - return Math::Vector(sinf(latitudeAngle) * cosf(longitudeAngle), + return glm::vec3(sinf(latitudeAngle) * cosf(longitudeAngle), cosf(latitudeAngle), sinf(latitudeAngle) * sinf(longitudeAngle)); }; @@ -3898,7 +3898,7 @@ void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix& } } -void CEngine::RenderDebugBox(const Math::Vector& mins, const Math::Vector& maxs, const Math::Matrix& transform, const Gfx::Color& color) +void CEngine::RenderDebugBox(const glm::vec3& mins, const glm::vec3& maxs, const Math::Matrix& transform, const Gfx::Color& color) { static constexpr int NUM_LINE_STRIPS = 4; static constexpr int VERTS_IN_LINE_STRIP = 4; @@ -3922,25 +3922,25 @@ void CEngine::RenderDebugBox(const Math::Vector& mins, const Math::Vector& maxs, auto vert = m_pendingDebugDraws.vertices.begin() + firstVert; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, maxs.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, maxs.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, maxs.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, maxs.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, maxs.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, mins.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, maxs.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, maxs.z}), color}; - *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, mins.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, maxs.z}), color}; + *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, maxs.z}), color}; } void CEngine::RenderPendingDebugDraws() @@ -4045,11 +4045,11 @@ void CEngine::RenderShadowMap() m_shadowParams[region].scale); // recompute matrices - Math::Vector worldUp(0.0f, 1.0f, 0.0f); - Math::Vector lightDir = Math::Vector(1.0f, 2.0f, -1.0f); - Math::Vector dir = m_lookatPt - m_eyePt; + glm::vec3 worldUp(0.0f, 1.0f, 0.0f); + glm::vec3 lightDir = glm::vec3(1.0f, 2.0f, -1.0f); + glm::vec3 dir = m_lookatPt - m_eyePt; dir.y = 0.0f; - dir.Normalize(); + dir = glm::normalize(dir); float range = m_shadowParams[region].range; @@ -4062,14 +4062,14 @@ void CEngine::RenderShadowMap() dist = 75.0f * scale; } - Math::Vector pos = m_lookatPt + 0.25f * dist * dir; + glm::vec3 pos = m_lookatPt + 0.25f * dist * dir; { // To prevent 'shadow shimmering', we ensure that the position only moves in texel-sized // increments. To do this we transform the position to a space where the light's forward/right/up // axes are aligned with the x/y/z axes (not necessarily in that order, and +/- signs don't matter). Math::Matrix lightRotation; - Math::LoadViewMatrix(lightRotation, Math::Vector{}, lightDir, worldUp); + Math::LoadViewMatrix(lightRotation, glm::vec3{0, 0, 0}, lightDir, worldUp); pos = Math::MatrixVectorMultiply(lightRotation, pos); // ...then we round to the nearest worldUnitsPerTexel: const float worldUnitsPerTexel = (dist * 2.0f) / m_shadowMap.size.x; @@ -4082,13 +4082,13 @@ void CEngine::RenderShadowMap() pos = Math::MatrixVectorMultiply(lightRotation.Inverse(), pos); } - Math::Vector lookAt = pos - lightDir; + glm::vec3 lookAt = pos - lightDir; Math::LoadOrthoProjectionMatrix(m_shadowProjMat, -dist, dist, -dist, dist, -depth, depth); Math::LoadViewMatrix(m_shadowViewMat, pos, lookAt, worldUp); Math::Matrix scaleMat; - Math::LoadScaleMatrix(scaleMat, Math::Vector(1.0f, 1.0f, -1.0f)); + Math::LoadScaleMatrix(scaleMat, glm::vec3(1.0f, 1.0f, -1.0f)); m_shadowViewMat = Math::MultiplyMatrices(scaleMat, m_shadowViewMat); Math::Matrix temporary = Math::MultiplyMatrices(m_shadowProjMat, m_shadowViewMat); @@ -4550,7 +4550,7 @@ void CEngine::UpdateGroundSpotTextures() { for (int ix = 0; ix < 256; ix++) { - Math::Vector pos; + glm::vec3 pos{}; pos.x = (256.0f * (s%4) + ix) * 3200.0f/1024.0f - 1600.0f; pos.z = (256.0f * (s/4) + iy) * 3200.0f/1024.0f - 1600.0f; pos.y = 0.0f; @@ -4648,7 +4648,7 @@ void CEngine::UpdateGroundSpotTextures() { for (float y = min.y; y < max.y; y += 1.0f) { - Math::Vector pos( + glm::vec3 pos( x / 4.0f / 254.0f * 3200.0f - 1600.0f, 0.0f, y / 4.0f / 254.0f * 3200.0f - 1600.0f @@ -4738,7 +4738,7 @@ void CEngine::DrawShadowSpots() ts.y += dp; ti.y -= dp; - Math::Vector n(0.0f, 1.0f, 0.0f); + glm::vec3 n(0.0f, 1.0f, 0.0f); float startDeepView = m_deepView[m_rankView] * m_fogStart[m_rankView] * m_clippingDistance; float endDeepView = m_deepView[m_rankView] * m_clippingDistance; @@ -4749,7 +4749,7 @@ void CEngine::DrawShadowSpots() if (m_shadowSpots[i].hide || !m_shadowSpots[i].used) continue; - Math::Vector pos = m_shadowSpots[i].pos; // pos = center of the shadow on the ground + glm::vec3 pos = m_shadowSpots[i].pos; // pos = center of the shadow on the ground if (m_eyePt.y == pos.y) continue; // camera at the same level? @@ -4809,7 +4809,7 @@ void CEngine::DrawShadowSpots() radius *= 1.0f-d/D; // smaller if close - Math::Vector corner[4]; + glm::vec3 corner[4]; if (m_shadowSpots[i].type == ENG_SHADOW_NORM) { @@ -4956,10 +4956,10 @@ void CEngine::DrawBackgroundGradient(const Color& up, const Color& down) VertexCol vertex[4] = { - { Math::Vector(p1.x, p1.y, 0.0f), color[1] }, - { Math::Vector(p1.x, p2.y, 0.0f), color[0] }, - { Math::Vector(p2.x, p1.y, 0.0f), color[1] }, - { Math::Vector(p2.x, p2.y, 0.0f), color[0] } + { glm::vec3(p1.x, p1.y, 0.0f), color[1] }, + { glm::vec3(p1.x, p2.y, 0.0f), color[0] }, + { glm::vec3(p2.x, p1.y, 0.0f), color[1] }, + { glm::vec3(p2.x, p2.y, 0.0f), color[0] } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); @@ -4974,7 +4974,7 @@ void CEngine::DrawBackgroundImage() p2.x = 1.0f; p2.y = 1.0f; - Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal + glm::vec3 n = glm::vec3(0.0f, 0.0f, -1.0f); // normal float u1, u2, v1, v2; if (m_backgroundFull) @@ -5068,7 +5068,7 @@ void CEngine::DrawForegroundImage() if (m_foregroundName.empty()) return; - Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal + glm::vec3 n = glm::vec3(0.0f, 0.0f, -1.0f); // normal glm::vec2 p1(0.0f, 0.0f); glm::vec2 p2(1.0f, 1.0f); @@ -5082,10 +5082,10 @@ void CEngine::DrawForegroundImage() Vertex vertex[4] = { - { Math::Vector(p1.x, p1.y, 0.0f), n, { u1, v2 } }, - { Math::Vector(p1.x, p2.y, 0.0f), n, { u1, v1 } }, - { Math::Vector(p2.x, p1.y, 0.0f), n, { u2, v2 } }, - { Math::Vector(p2.x, p2.y, 0.0f), n, { u2, v1 } } + { glm::vec3(p1.x, p1.y, 0.0f), n, { u1, v2 } }, + { glm::vec3(p1.x, p2.y, 0.0f), n, { u1, v1 } }, + { glm::vec3(p2.x, p1.y, 0.0f), n, { u2, v2 } }, + { glm::vec3(p2.x, p2.y, 0.0f), n, { u2, v1 } } }; SetTexture(m_foregroundTex); @@ -5128,10 +5128,10 @@ void CEngine::DrawOverColor() VertexCol vertex[4] = { - { Math::Vector(p1.x, p1.y, 0.0f), color[1] }, - { Math::Vector(p1.x, p2.y, 0.0f), color[0] }, - { Math::Vector(p2.x, p1.y, 0.0f), color[1] }, - { Math::Vector(p2.x, p2.y, 0.0f), color[0] } + { glm::vec3(p1.x, p1.y, 0.0f), color[1] }, + { glm::vec3(p1.x, p2.y, 0.0f), color[0] }, + { glm::vec3(p2.x, p1.y, 0.0f), color[1] }, + { glm::vec3(p2.x, p2.y, 0.0f), color[0] } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); @@ -5202,32 +5202,32 @@ void CEngine::DrawHighlight() VertexCol line[3] = { - { Math::Vector(), color }, - { Math::Vector(), color }, - { Math::Vector(), color } + { { 0, 0, 0 }, color }, + { { 0, 0, 0 }, color}, + { { 0, 0, 0 }, color} }; float dx = (p2.x - p1.x) / 5.0f; float dy = (p2.y - p1.y) / 5.0f; - line[0].coord = Math::Vector(p1.x, p1.y + dy, 0.0f); - line[1].coord = Math::Vector(p1.x, p1.y, 0.0f); - line[2].coord = Math::Vector(p1.x + dx, p1.y, 0.0f); + line[0].coord = glm::vec3(p1.x, p1.y + dy, 0.0f); + line[1].coord = glm::vec3(p1.x, p1.y, 0.0f); + line[2].coord = glm::vec3(p1.x + dx, p1.y, 0.0f); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); - line[0].coord = Math::Vector(p2.x - dx, p1.y, 0.0f); - line[1].coord = Math::Vector(p2.x, p1.y, 0.0f); - line[2].coord = Math::Vector(p2.x, p1.y + dy, 0.0f); + line[0].coord = glm::vec3(p2.x - dx, p1.y, 0.0f); + line[1].coord = glm::vec3(p2.x, p1.y, 0.0f); + line[2].coord = glm::vec3(p2.x, p1.y + dy, 0.0f); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); - line[0].coord = Math::Vector(p2.x, p2.y - dy, 0.0f); - line[1].coord = Math::Vector(p2.x, p2.y, 0.0f); - line[2].coord = Math::Vector(p2.x - dx, p2.y, 0.0f); + line[0].coord = glm::vec3(p2.x, p2.y - dy, 0.0f); + line[1].coord = glm::vec3(p2.x, p2.y, 0.0f); + line[2].coord = glm::vec3(p2.x - dx, p2.y, 0.0f); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); - line[0].coord = Math::Vector(p1.x + dx, p2.y, 0.0f); - line[1].coord = Math::Vector(p1.x, p2.y, 0.0f); - line[2].coord = Math::Vector(p1.x, p2.y - dy, 0.0f); + line[0].coord = glm::vec3(p1.x + dx, p2.y, 0.0f); + line[1].coord = glm::vec3(p1.x, p2.y, 0.0f); + line[2].coord = glm::vec3(p1.x, p2.y - dy, 0.0f); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); } @@ -5504,11 +5504,11 @@ void CEngine::UpdateObjectShadowSpotNormal(int objRank) // Calculating the normal to the ground in nine strategic locations, // then perform a weighted average (the dots in the center are more important). - Math::Vector pos = m_shadowSpots[shadowRank].pos; + glm::vec3 pos = m_shadowSpots[shadowRank].pos; float radius = m_shadowSpots[shadowRank].radius; - Math::Vector n[20]; - Math::Vector norm; + glm::vec3 n[20]; + glm::vec3 norm = { 0, 0, 0 }; int i = 0; m_terrain->GetNormal(norm, pos); @@ -5516,7 +5516,7 @@ void CEngine::UpdateObjectShadowSpotNormal(int objRank) n[i++] = norm; n[i++] = norm; - Math::Vector shPos = pos; + glm::vec3 shPos = pos; shPos.x += radius*0.6f; shPos.z += radius*0.6f; m_terrain->GetNormal(norm, shPos); @@ -5568,7 +5568,7 @@ void CEngine::UpdateObjectShadowSpotNormal(int objRank) m_terrain->GetNormal(norm, shPos); n[i++] = norm; - norm.LoadZero(); + norm = { 0, 0, 0 }; for (int j = 0; j < i; j++) { norm += n[j]; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 7b70e7d8..1176a0d3 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -243,9 +243,9 @@ struct EngineBaseObject //! Number of triangles int totalTriangles = 0; //! Bounding box min (origin 0,0,0 always included) - Math::Vector bboxMin; + glm::vec3 bboxMin{ 0, 0, 0 }; //! bounding box max (origin 0,0,0 always included) - Math::Vector bboxMax; + glm::vec3 bboxMax{ 0, 0, 0 }; //! A bounding sphere that contains all the vertices in this EngineBaseObject Math::Sphere boundingSphere; //! Next tier (Tex) @@ -318,9 +318,9 @@ struct EngineShadow //! Type of shadow EngineShadowType type = ENG_SHADOW_NORM; //! Position of the shadow - Math::Vector pos; + glm::vec3 pos{ 0, 0, 0 }; //! Normal to the terrain - Math::Vector normal; + glm::vec3 normal{ 0, 0, 0 }; //! Angle of the shadow float angle = 0.0f; //! Radius of the shadow @@ -353,11 +353,11 @@ struct EngineGroundSpot //! Transition area float smooth = 0.0f; //! Position for the shadow - Math::Vector pos; + glm::vec3 pos{ 0, 0, 0 }; //! Radius of the shadow float radius = 0.0f; //! Position of the shadow drawn - Math::Vector drawPos; + glm::vec3 drawPos{ 0, 0, 0 }; //! Radius of the shadow drawn float drawRadius = 0.0f; @@ -398,13 +398,13 @@ struct EngineGroundMark //! Fixed time float fix = 0.0f; //! Position for marks - Math::Vector pos; + glm::vec3 pos{ 0, 0, 0 }; //! Radius of marks float radius = 0.0f; //! Color intensity float intensity = 0.0f; //! Draw position for marks - Math::Vector drawPos; + glm::vec3 drawPos{ 0, 0, 0 }; //! Radius for marks float drawRadius = 0.0f; //! Draw intensity for marks @@ -685,7 +685,7 @@ public: int GetStatisticTriangle(); //! Sets the coordinates to display in stats window - void SetStatisticPos(Math::Vector pos); + void SetStatisticPos(glm::vec3 pos); //! Sets text to display as mission timer void SetTimerDisplay(const std::string& text); @@ -777,7 +777,7 @@ public: void SetObjectTransparency(int objRank, float value); //! Returns the bounding box for an object - void GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max); + void GetObjectBBox(int objRank, glm::vec3& min, glm::vec3& max); //! Returns the total number of triangles of given object int GetObjectTotalTriangles(int objRank); @@ -807,7 +807,7 @@ public: //! Detects the target object that is selected with the mouse /** Returns the rank of the object or -1. */ - int DetectObject(const glm::vec2& mouse, Math::Vector& targetPos, bool terrain = false); + int DetectObject(const glm::vec2& mouse, glm::vec3& targetPos, bool terrain = false); //! Creates a shadow for the given object void CreateShadowSpot(int objRank); @@ -818,7 +818,7 @@ public: //! Management of different shadow params void SetObjectShadowSpotHide(int objRank, bool hide); void SetObjectShadowSpotType(int objRank, EngineShadowType type); - void SetObjectShadowSpotPos(int objRank, const Math::Vector& pos); + void SetObjectShadowSpotPos(int objRank, const glm::vec3& pos); void SetObjectShadowSpotAngle(int objRank, float angle); void SetObjectShadowSpotRadius(int objRank, float radius); void SetObjectShadowSpotIntensity(int objRank, float intensity); @@ -840,7 +840,7 @@ public: //@{ //! Management of different ground spot params - void SetObjectGroundSpotPos(int rank, const Math::Vector& pos); + void SetObjectGroundSpotPos(int rank, const glm::vec3& pos); void SetObjectGroundSpotRadius(int rank, float radius); void SetObjectGroundSpotColor(int rank, const Color& color); void SetObjectGroundSpotMinMax(int rank, float min, float max); @@ -848,7 +848,7 @@ public: //@} //! Creates the ground mark with the given params - void CreateGroundMark(Math::Vector pos, float radius, + void CreateGroundMark(glm::vec3 pos, float radius, float delay1, float delay2, float delay3, int dx, int dy, char* table); //! Deletes the ground mark @@ -867,7 +867,7 @@ public: void SetMaterial(const Material& mat); //! Specifies the location and direction of view - void SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec); + void SetViewParams(const glm::vec3 &eyePt, const glm::vec3 &lookatPt, const glm::vec3 &upVec); //! Updates the textures used for drawing ground spot void UpdateGroundSpotTextures(); @@ -1158,15 +1158,15 @@ public: //! Returns the projection matrix const Math::Matrix& GetMatProj(); //! Returns the camera center point - TEST_VIRTUAL Math::Vector GetEyePt(); + TEST_VIRTUAL glm::vec3 GetEyePt(); //! Returns the camera target point - TEST_VIRTUAL Math::Vector GetLookatPt(); + TEST_VIRTUAL glm::vec3 GetLookatPt(); //! Returns the horizontal direction angle of view float GetEyeDirH(); //! Returns the vertical direction angle of view float GetEyeDirV(); //! Indicates whether a point is visible - bool IsVisiblePoint(const Math::Vector& pos); + bool IsVisiblePoint(const glm::vec3& pos); //! Resets the projection matrix after changes void UpdateMatProj(); @@ -1175,7 +1175,7 @@ public: void ApplyChange(); void RenderDebugSphere(const Math::Sphere&, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f}); - void RenderDebugBox(const Math::Vector& mins, const Math::Vector& maxs, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f}); + void RenderDebugBox(const glm::vec3& mins, const glm::vec3& maxs, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f}); void SetDebugLights(bool debugLights); bool GetDebugLights(); @@ -1263,9 +1263,9 @@ protected: //! Tests whether the given object is visible bool IsVisible(const Math::Matrix& matrix, int objRank); - int ComputeSphereVisibility(const Math::Matrix& m, const Math::Vector& center, float radius); + int ComputeSphereVisibility(const Math::Matrix& m, const glm::vec3& center, float radius); - bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius); + bool InPlane(glm::vec3 normal, float originPlane, glm::vec3 center, float radius); //! Detects whether an object is affected by the mouse bool DetectBBox(int objRank, const glm::vec2& mouse); @@ -1274,11 +1274,11 @@ protected: bool GetBBox2D(int objRank, glm::vec2& min, glm::vec2& max); //! Detects whether the mouse is in a triangle. - bool DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, Math::Vector& pos); + bool DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, glm::vec3& pos); //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window /** The coordinated p2D.z gives the distance. */ - bool TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D); + bool TransformPoint(glm::vec3& p2D, int objRank, glm::vec3 p3D); //! Calculates the distances between the viewpoint and the origin of different objects void ComputeDistance(); @@ -1382,9 +1382,9 @@ protected: EngineGroundMark m_groundMark; //! Location of camera - Math::Vector m_eyePt; + glm::vec3 m_eyePt{ 0, 0, 0 }; //! Camera target - Math::Vector m_lookatPt; + glm::vec3 m_lookatPt{ 0, 0, 0 }; float m_eyeDirH; float m_eyeDirV; int m_rankView; @@ -1395,7 +1395,7 @@ protected: float m_fogStart[2]; Color m_waterAddColor; int m_statisticTriangle; - Math::Vector m_statisticPos; + glm::vec3 m_statisticPos{ 0, 0, 0 }; bool m_updateGeometry; bool m_updateStaticBuffers; bool m_firstGroundSpot; diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index ff71a2f0..2021f274 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -130,9 +130,9 @@ void CLightManager::DebugDumpLights() l->Debug(" diffuse = %s\n", str.c_str()); str = light.specular.ToString(); l->Debug(" specular = %s\n", str.c_str()); - str = light.position.ToString(); + str = Math::ToString(light.position); l->Debug(" position = %s\n", str.c_str()); - str = light.direction.ToString(); + str = Math::ToString(light.direction); l->Debug(" direction = %s\n", str.c_str()); l->Debug(" attenuation0 = %f\n", light.attenuation0); l->Debug(" attenuation1 = %f\n", light.attenuation1); @@ -515,7 +515,7 @@ float CLightManager::CLightsComparator::GetLightWeight(const DynamicLight& dynLi else if (dynLight.excludeType != ENG_OBJTYPE_NULL) enabled = dynLight.excludeType != m_objectType; - return enabled ? ( (dynLight.light.position - m_eyePos).Length() * dynLight.priority ) : 10000.0f; + return enabled ? ( glm::length(dynLight.light.position - m_eyePos) * dynLight.priority ) : 10000.0f; } bool CLightManager::CLightsComparator::operator()(const DynamicLight& left, const DynamicLight& right) diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 3bb77da0..6cd1de85 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -2621,7 +2621,7 @@ void CParticle::TrackDraw(int i, ParticleType type) Math::Vector p2 = m_track[i].pos[h]; - Math::Vector n = Normalize(p1-eye); + Math::Vector n = glm::normalize(p1-eye); Math::Vector p; glm::vec2 rot; diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 7827f15a..66e3144a 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -547,7 +547,7 @@ VertexTex2 CTerrain::GetVertex(int x, int y, int step) if (x-step >= 0 && y-step >= 0) s += Math::NormalToPlane(a,f,o); - s = Normalize(s); + s = glm::normalize(s); v.normal = s; int brick = m_brickCount/m_textureSubdivCount; @@ -1453,11 +1453,11 @@ float CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water) Math::Vector ps = pos; if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) ) { - if ( !IntersectY(p1, p2, p3, ps) ) return 0.0f; + if ( !Math::IntersectY(p1, p2, p3, ps) ) return 0.0f; } else { - if ( !IntersectY(p2, p4, p3, ps) ) return 0.0f; + if ( !Math::IntersectY(p2, p4, p3, ps) ) return 0.0f; } if (! brut) AdjustBuildingLevel(ps); @@ -1489,11 +1489,11 @@ float CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water) Math::Vector ps = pos; if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) ) { - if ( !IntersectY(p1, p2, p3, ps) ) return 0.0f; + if ( !Math::IntersectY(p1, p2, p3, ps) ) return 0.0f; } else { - if ( !IntersectY(p2, p4, p3, ps) ) return 0.0f; + if ( !Math::IntersectY(p2, p4, p3, ps) ) return 0.0f; } if (! brut) AdjustBuildingLevel(ps); @@ -1720,7 +1720,7 @@ void CTerrain::AdjustBuildingLevel(Math::Vector &p) return; } - Math::Vector border; + Math::Vector border{ 0, 0, 0 }; border.x = ((p.x - m_buildingLevels[i].center.x) * m_buildingLevels[i].max) / dist + m_buildingLevels[i].center.x; border.z = ((p.z - m_buildingLevels[i].center.z) * m_buildingLevels[i].max) / @@ -1780,7 +1780,7 @@ void CTerrain::ShowFlatGround(Math::Vector pos) int i = x + y*41; table[i] = 0; - Math::Vector p; + Math::Vector p{}; p.x = (x-20)*radius; p.z = (y-20)*radius; p.y = 0.0f; @@ -1820,7 +1820,7 @@ float CTerrain::GetFlatZoneRadius(Math::Vector center, float max) for (int i = 0; i < nb; i++) { glm::vec2 result = Math::RotatePoint(c, angle, p); - Math::Vector pos; + Math::Vector pos{ 0, 0, 0 }; pos.x = result.x; pos.z = result.y; float h = GetFloorLevel(pos, true); diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 4fa6ebe5..aebb712b 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -371,7 +371,7 @@ protected: */ struct BuildingLevel { - Math::Vector center; + Math::Vector center{ 0, 0, 0 }; float factor = 0.0f; float min = 0.0f; float max = 0.0f; @@ -385,7 +385,7 @@ protected: std::vector m_buildingLevels; //! Wind speed - Math::Vector m_wind; + Math::Vector m_wind{ 0, 0, 0 }; //! Global flying height limit float m_flyingMaxHeight; @@ -396,7 +396,7 @@ protected: */ struct FlyingLimit { - Math::Vector center; + Math::Vector center{ 0, 0, 0 }; float extRadius = 0.0f; float intRadius = 0.0f; float maxHeight = 0.0f; diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index 22abb688..4b57cca8 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -98,7 +98,7 @@ void CWater::LavaFrame(float rTime) float distance = Math::Rand()*200.0f; float shift = (Math::Rand()-0.5f)*200.0f; - Math::Vector dir = Normalize(lookat-eye); + Math::Vector dir = glm::normalize(lookat-eye); Math::Vector pos = eye + dir*distance; Math::Vector perp; diff --git a/src/graphics/model/model_crash_sphere.h b/src/graphics/model/model_crash_sphere.h index 08ba9b3a..4e15757d 100644 --- a/src/graphics/model/model_crash_sphere.h +++ b/src/graphics/model/model_crash_sphere.h @@ -30,7 +30,7 @@ namespace Gfx */ struct ModelCrashSphere { - Math::Vector position; + Math::Vector position{ 0, 0, 0 }; float radius = 0.0f; std::string sound; float hardness = 0.0f; diff --git a/src/graphics/model/model_mesh.cpp b/src/graphics/model/model_mesh.cpp index 39ba2036..ee6c5302 100644 --- a/src/graphics/model/model_mesh.cpp +++ b/src/graphics/model/model_mesh.cpp @@ -42,32 +42,32 @@ int CModelMesh::GetTriangleCount() const return m_triangles.size(); } -const Math::Vector& CModelMesh::GetPosition() const +const glm::vec3& CModelMesh::GetPosition() const { return m_position; } -void CModelMesh::SetPosition(const Math::Vector& position) +void CModelMesh::SetPosition(const glm::vec3& position) { m_position = position; } -const Math::Vector& CModelMesh::GetRotation() const +const glm::vec3& CModelMesh::GetRotation() const { return m_rotation; } -void CModelMesh::SetRotation(const Math::Vector& rotation) +void CModelMesh::SetRotation(const glm::vec3& rotation) { m_rotation = rotation; } -const Math::Vector& CModelMesh::GetScale() const +const glm::vec3& CModelMesh::GetScale() const { return m_scale; } -void CModelMesh::SetScale(const Math::Vector& scale) +void CModelMesh::SetScale(const glm::vec3& scale) { m_scale = scale; } diff --git a/src/graphics/model/model_mesh.h b/src/graphics/model/model_mesh.h index c5f607a2..b3664587 100644 --- a/src/graphics/model/model_mesh.h +++ b/src/graphics/model/model_mesh.h @@ -21,8 +21,6 @@ #include "graphics/model/model_triangle.h" -#include "math/vector.h" - #include namespace Gfx @@ -45,19 +43,19 @@ public: int GetTriangleCount() const; //! Returns the mesh position - const Math::Vector& GetPosition() const; + const glm::vec3& GetPosition() const; //! Sets the mesh rotation - void SetPosition(const Math::Vector& position); + void SetPosition(const glm::vec3& position); //! Returns the mesh rotation - const Math::Vector& GetRotation() const; + const glm::vec3& GetRotation() const; //! Sets the mesh rotation - void SetRotation(const Math::Vector& rotation); + void SetRotation(const glm::vec3& rotation); //! Returns the mesh scale - const Math::Vector& GetScale() const; + const glm::vec3& GetScale() const; //! Sets the mesh scale - void SetScale(const Math::Vector& scale); + void SetScale(const glm::vec3& scale); //! Returns the name of parent mesh const std::string& GetParent() const; @@ -66,9 +64,9 @@ public: private: std::vector m_triangles; - Math::Vector m_position; - Math::Vector m_rotation; - Math::Vector m_scale; + glm::vec3 m_position; + glm::vec3 m_rotation; + glm::vec3 m_scale; std::string m_parent; }; diff --git a/src/graphics/model/model_output.cpp b/src/graphics/model/model_output.cpp index b7412987..c889b320 100644 --- a/src/graphics/model/model_output.cpp +++ b/src/graphics/model/model_output.cpp @@ -39,7 +39,7 @@ namespace ModelOutput void WriteShadowSpot(const ModelShadowSpot& shadowSpot, std::ostream &stream); void WriteCameraCollisionSphere(const Math::Sphere& sphere, std::ostream &stream); void WriteTextMesh(const CModelMesh* mesh, const std::string& meshName, std::ostream &stream); - std::string VectorToString(const Math::Vector& vector); + std::string VectorToString(const glm::vec3& vector); std::string TransparentModeToString(ModelTransparentMode mode); std::string SpecialMarkToString(ModelSpecialMark specialMark); @@ -203,7 +203,7 @@ void ModelOutput::WriteTextMesh(const CModelMesh* mesh, const std::string& meshN } } -std::string ModelOutput::VectorToString(const Math::Vector& vector) +std::string ModelOutput::VectorToString(const glm::vec3& vector) { std::ostringstream str; str << vector.x << " " << vector.y << " " << vector.z; diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 285bd84d..336a129d 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -131,9 +131,9 @@ void CGL33Device::DebugLights() if (l.type == LIGHT_DIRECTIONAL) { Gfx::VertexCol v[2]; - v[0].coord = -Math::Normalize(l.direction) * 100.0f + Math::Vector(0.0f, 0.0f, 1.0f) * i; + v[0].coord = -Math::Normalize(l.direction) * 100.0f + glm::vec3(0.0f, 0.0f, 1.0f) * float(i); v[0].color = HSV2RGB(color); - v[1].coord = Math::Normalize(l.direction) * 100.0f + Math::Vector(0.0f, 0.0f, 1.0f) * i; + v[1].coord = Math::Normalize(l.direction) * 100.0f + glm::vec3(0.0f, 0.0f, 1.0f) * float(i); v[1].color = HSV2RGB(color); while (v[0].coord.y < 60.0f && v[0].coord.y < 60.0f) { @@ -154,28 +154,28 @@ void CGL33Device::DebugLights() for (int i = 0; i < 8; ++i) v[i].color = HSV2RGB(color); - v[0].coord = l.position + Math::Vector(-1.0f, -1.0f, -1.0f) * 4.0f; - v[1].coord = l.position + Math::Vector( 1.0f, -1.0f, -1.0f) * 4.0f; - v[2].coord = l.position + Math::Vector( 1.0f, 1.0f, -1.0f) * 4.0f; - v[3].coord = l.position + Math::Vector(-1.0f, 1.0f, -1.0f) * 4.0f; - v[4].coord = l.position + Math::Vector(-1.0f, -1.0f, -1.0f) * 4.0f; + v[0].coord = l.position + glm::vec3(-1.0f, -1.0f, -1.0f) * 4.0f; + v[1].coord = l.position + glm::vec3( 1.0f, -1.0f, -1.0f) * 4.0f; + v[2].coord = l.position + glm::vec3( 1.0f, 1.0f, -1.0f) * 4.0f; + v[3].coord = l.position + glm::vec3(-1.0f, 1.0f, -1.0f) * 4.0f; + v[4].coord = l.position + glm::vec3(-1.0f, -1.0f, -1.0f) * 4.0f; DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5); - v[0].coord = l.position + Math::Vector(-1.0f, -1.0f, 1.0f) * 4.0f; - v[1].coord = l.position + Math::Vector( 1.0f, -1.0f, 1.0f) * 4.0f; - v[2].coord = l.position + Math::Vector( 1.0f, 1.0f, 1.0f) * 4.0f; - v[3].coord = l.position + Math::Vector(-1.0f, 1.0f, 1.0f) * 4.0f; - v[4].coord = l.position + Math::Vector(-1.0f, -1.0f, 1.0f) * 4.0f; + v[0].coord = l.position + glm::vec3(-1.0f, -1.0f, 1.0f) * 4.0f; + v[1].coord = l.position + glm::vec3( 1.0f, -1.0f, 1.0f) * 4.0f; + v[2].coord = l.position + glm::vec3( 1.0f, 1.0f, 1.0f) * 4.0f; + v[3].coord = l.position + glm::vec3(-1.0f, 1.0f, 1.0f) * 4.0f; + v[4].coord = l.position + glm::vec3(-1.0f, -1.0f, 1.0f) * 4.0f; DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5); - v[0].coord = l.position + Math::Vector(-1.0f, -1.0f, -1.0f) * 4.0f; - v[1].coord = l.position + Math::Vector(-1.0f, -1.0f, 1.0f) * 4.0f; - v[2].coord = l.position + Math::Vector( 1.0f, -1.0f, -1.0f) * 4.0f; - v[3].coord = l.position + Math::Vector( 1.0f, -1.0f, 1.0f) * 4.0f; - v[4].coord = l.position + Math::Vector( 1.0f, 1.0f, -1.0f) * 4.0f; - v[5].coord = l.position + Math::Vector( 1.0f, 1.0f, 1.0f) * 4.0f; - v[6].coord = l.position + Math::Vector(-1.0f, 1.0f, -1.0f) * 4.0f; - v[7].coord = l.position + Math::Vector(-1.0f, 1.0f, 1.0f) * 4.0f; + v[0].coord = l.position + glm::vec3(-1.0f, -1.0f, -1.0f) * 4.0f; + v[1].coord = l.position + glm::vec3(-1.0f, -1.0f, 1.0f) * 4.0f; + v[2].coord = l.position + glm::vec3( 1.0f, -1.0f, -1.0f) * 4.0f; + v[3].coord = l.position + glm::vec3( 1.0f, -1.0f, 1.0f) * 4.0f; + v[4].coord = l.position + glm::vec3( 1.0f, 1.0f, -1.0f) * 4.0f; + v[5].coord = l.position + glm::vec3( 1.0f, 1.0f, 1.0f) * 4.0f; + v[6].coord = l.position + glm::vec3(-1.0f, 1.0f, -1.0f) * 4.0f; + v[7].coord = l.position + glm::vec3(-1.0f, 1.0f, 1.0f) * 4.0f; DrawPrimitive(PrimitiveType::LINES, v, 8); } else if (l.type == LIGHT_SPOT) @@ -184,11 +184,11 @@ void CGL33Device::DebugLights() for (int i = 0; i < 5; ++i) v[i].color = HSV2RGB(color); - v[0].coord = l.position + Math::Vector(-1.0f, 0.0f, -1.0f) * 4.0f; - v[1].coord = l.position + Math::Vector( 1.0f, 0.0f, -1.0f) * 4.0f; - v[2].coord = l.position + Math::Vector( 1.0f, 0.0f, 1.0f) * 4.0f; - v[3].coord = l.position + Math::Vector(-1.0f, 0.0f, 1.0f) * 4.0f; - v[4].coord = l.position + Math::Vector(-1.0f, 0.0f, -1.0f) * 4.0f; + v[0].coord = l.position + glm::vec3(-1.0f, 0.0f, -1.0f) * 4.0f; + v[1].coord = l.position + glm::vec3( 1.0f, 0.0f, -1.0f) * 4.0f; + v[2].coord = l.position + glm::vec3( 1.0f, 0.0f, 1.0f) * 4.0f; + v[3].coord = l.position + glm::vec3(-1.0f, 0.0f, 1.0f) * 4.0f; + v[4].coord = l.position + glm::vec3(-1.0f, 0.0f, -1.0f) * 4.0f; DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5); v[0].coord = l.position; @@ -600,7 +600,7 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix) else if (type == TRANSFORM_VIEW) { Math::Matrix scale; - Math::Vector cameraPosition; + glm::vec3 cameraPosition; scale.Set(3, 3, -1.0f); m_viewMat = Math::MultiplyMatrices(scale, matrix); @@ -611,9 +611,9 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix) if (m_uniforms.cameraPosition >= 0) { - cameraPosition.LoadZero(); + cameraPosition = { 0, 0, 0 }; cameraPosition = MatrixVectorMultiply(m_viewMat.Inverse(), cameraPosition); - glUniform3fv(m_uniforms.cameraPosition, 1, cameraPosition.Array()); + glUniform3fv(m_uniforms.cameraPosition, 1, glm::value_ptr(cameraPosition)); } } else if (type == TRANSFORM_PROJECTION) @@ -1329,7 +1329,7 @@ void CGL33Device::DestroyVertexBuffer(CVertexBuffer* buffer) /* Based on libwine's implementation */ -int CGL33Device::ComputeSphereVisibility(const Math::Vector ¢er, float radius) +int CGL33Device::ComputeSphereVisibility(const glm::vec3 ¢er, float radius) { if (m_combinedMatrixOutdated) { @@ -1339,55 +1339,55 @@ int CGL33Device::ComputeSphereVisibility(const Math::Vector ¢er, float radiu Math::Matrix &m = m_combinedMatrix; - Math::Vector vec[6]; + glm::vec3 vec[6]; float originPlane[6]; // Left plane vec[0].x = m.Get(4, 1) + m.Get(1, 1); vec[0].y = m.Get(4, 2) + m.Get(1, 2); vec[0].z = m.Get(4, 3) + m.Get(1, 3); - float l1 = vec[0].Length(); - vec[0].Normalize(); + float l1 = glm::length(vec[0]); + vec[0] = glm::normalize(vec[0]); originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1; // Right plane vec[1].x = m.Get(4, 1) - m.Get(1, 1); vec[1].y = m.Get(4, 2) - m.Get(1, 2); vec[1].z = m.Get(4, 3) - m.Get(1, 3); - float l2 = vec[1].Length(); - vec[1].Normalize(); + float l2 = glm::length(vec[1]); + vec[1] = glm::normalize(vec[1]); originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2; // Bottom plane vec[2].x = m.Get(4, 1) + m.Get(2, 1); vec[2].y = m.Get(4, 2) + m.Get(2, 2); vec[2].z = m.Get(4, 3) + m.Get(2, 3); - float l3 = vec[2].Length(); - vec[2].Normalize(); + float l3 = glm::length(vec[2]); + vec[2] = glm::normalize(vec[2]); originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3; // Top plane vec[3].x = m.Get(4, 1) - m.Get(2, 1); vec[3].y = m.Get(4, 2) - m.Get(2, 2); vec[3].z = m.Get(4, 3) - m.Get(2, 3); - float l4 = vec[3].Length(); - vec[3].Normalize(); + float l4 = glm::length(vec[3]); + vec[3] = glm::normalize(vec[3]); originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4; // Front plane vec[4].x = m.Get(4, 1) + m.Get(3, 1); vec[4].y = m.Get(4, 2) + m.Get(3, 2); vec[4].z = m.Get(4, 3) + m.Get(3, 3); - float l5 = vec[4].Length(); - vec[4].Normalize(); + float l5 = glm::length(vec[4]); + vec[4] = glm::normalize(vec[4]); originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5; // Back plane vec[5].x = m.Get(4, 1) - m.Get(3, 1); vec[5].y = m.Get(4, 2) - m.Get(3, 2); vec[5].z = m.Get(4, 3) - m.Get(3, 3); - float l6 = vec[5].Length(); - vec[5].Normalize(); + float l6 = glm::length(vec[5]); + vec[5] = glm::normalize(vec[5]); originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6; int result = 0; diff --git a/src/graphics/opengl/gl33device.h b/src/graphics/opengl/gl33device.h index 70ea424a..3b5aecfc 100644 --- a/src/graphics/opengl/gl33device.h +++ b/src/graphics/opengl/gl33device.h @@ -169,7 +169,7 @@ public: void DrawVertexBuffer(CVertexBuffer*) override; void DestroyVertexBuffer(CVertexBuffer*) override; - int ComputeSphereVisibility(const Math::Vector ¢er, float radius) override; + int ComputeSphereVisibility(const glm::vec3 ¢er, float radius) override; void SetViewport(int x, int y, int width, int height) override; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index a6e03194..9c938c5f 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -447,7 +447,7 @@ void CRobotMain::ChangePhase(Phase phase) m_engine->SetOverColor(); m_engine->DeleteGroundMark(0); SetSpeed(1.0f); - m_terrain->SetWind(Math::Vector(0.0f, 0.0f, 0.0f)); + m_terrain->SetWind(glm::vec3(0.0f, 0.0f, 0.0f)); m_terrain->FlushBuildingLevel(); m_terrain->FlushFlyingLimit(); m_lightMan->FlushLights(); @@ -458,7 +458,7 @@ void CRobotMain::ChangePhase(Phase phase) m_planet->Flush(); m_interface->Flush(); m_newScriptName.clear(); - m_sound->SetListener(Math::Vector(0.0f, 0.0f, 0.0f), Math::Vector(0.0f, 0.0f, 1.0f)); + m_sound->SetListener(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)); m_sound->StopAll(); m_camera->SetType(Gfx::CAM_TYPE_NULL); m_movie->Flush(); @@ -602,7 +602,7 @@ void CRobotMain::ChangePhase(Phase phase) } else { - m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); + m_displayText->DisplayError(INFO_WIN, glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); } StartMusic(); } @@ -632,7 +632,7 @@ void CRobotMain::ChangePhase(Phase phase) glm::vec2 ddim; ddim.x = dim.x*2; ddim.y = dim.y*2; m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK); - m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); + m_displayText->DisplayError(INFO_LOST, glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); StartMusic(); } @@ -1043,7 +1043,7 @@ bool CRobotMain::ProcessEvent(Event &event) CLevelParserLine line("CreateObject"); line.AddParam("type", MakeUnique(obj->GetType())); - Math::Vector pos = obj->GetPosition()/g_unit; + glm::vec3 pos = obj->GetPosition()/g_unit; pos.y = 0.0f; line.AddParam("pos", MakeUnique(pos)); @@ -1538,7 +1538,7 @@ void CRobotMain::ExecuteCmd(const std::string& cmd) } if (m_phase == PHASE_SIMUL) - m_displayText->DisplayError(ERR_CMD, Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayError(ERR_CMD, glm::vec3(0.0f,0.0f,0.0f)); } @@ -1805,7 +1805,7 @@ void CRobotMain::FrameVisit(float rTime) // Moves the arrow. m_visitTime += rTime; - Math::Vector pos = m_visitPosArrow; + glm::vec3 pos = m_visitPosArrow; pos.y += 1.5f+sinf(m_visitTime*4.0f)*4.0f; m_visitArrow->SetPosition(pos); m_visitArrow->SetRotationY(m_visitTime*2.0f); @@ -1819,7 +1819,7 @@ void CRobotMain::FrameVisit(float rTime) pos = m_visitPos; float level = m_terrain->GetFloorLevel(pos)+2.0f; if (pos.y < level) pos.y = level; // not below the ground - Math::Vector speed(0.0f, 0.0f, 0.0f); + glm::vec3 speed(0.0f, 0.0f, 0.0f); glm::vec2 dim; dim.x = 30.0f; dim.y = dim.x; @@ -2026,7 +2026,7 @@ CObject* CRobotMain::GetSelect() //! Detects the object aimed by the mouse CObject* CRobotMain::DetectObject(const glm::vec2& pos) { - Math::Vector p; + glm::vec3 p; int objRank = m_engine->DetectObject(pos, p); for (CObject* obj : m_objMan->GetAllObjects()) @@ -2372,7 +2372,7 @@ void CRobotMain::UpdateInfoText() CObject* obj = GetSelect(); if (obj != nullptr) { - Math::Vector pos = obj->GetPosition(); + glm::vec3 pos = obj->GetPosition(); m_engine->SetStatisticPos(pos / g_unit); } } @@ -2384,8 +2384,8 @@ void CRobotMain::UpdateInfoText() void CRobotMain::InitEye() { if (m_phase == PHASE_SIMUL) - m_camera->Init(Math::Vector( 0.0f, 10.0f, 0.0f), - Math::Vector(10.0f, 5.0f, 0.0f), 0.0f); + m_camera->Init(glm::vec3( 0.0f, 10.0f, 0.0f), + glm::vec3(10.0f, 5.0f, 0.0f), 0.0f); } //! Advances the entire scene @@ -2431,7 +2431,7 @@ bool CRobotMain::EventFrame(const Event &event) if ( obj->GetProxyActivate() ) // active if it is near? { - Math::Vector eye = m_engine->GetLookatPt(); + glm::vec3 eye = m_engine->GetLookatPt(); float dist = Math::Distance(eye, obj->GetPosition()); if ( dist < obj->GetProxyDistance() ) { @@ -2482,7 +2482,7 @@ bool CRobotMain::EventFrame(const Event &event) { if (!m_immediatSatCom && !m_beginSatCom && !m_movieLock) { - m_displayText->DisplayError(INFO_BEGINSATCOM, Math::Vector(0.0f, 0.0f, 0.0f)); + m_displayText->DisplayError(INFO_BEGINSATCOM, glm::vec3(0.0f, 0.0f, 0.0f)); m_beginSatCom = true; // message appears } @@ -3155,7 +3155,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "Planet" && !resetObject) { - Math::Vector ppos, uv1, uv2; + glm::vec3 ppos, uv1, uv2; ppos = line->GetParam("pos")->AsPoint(); uv1 = line->GetParam("uv1")->AsPoint(); @@ -3237,7 +3237,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "TerrainWater" && !resetObject) { - Math::Vector pos; + glm::vec3 pos; pos.x = line->GetParam("moveX")->AsFloat(0.0f); pos.y = line->GetParam("moveY")->AsFloat(0.0f); pos.z = pos.x; @@ -3374,7 +3374,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("max")->AsFloat(100.0f)*g_unit, line->GetParam("slope")->AsFloat(5.0f), line->GetParam("freq")->AsFloat(100.0f), - line->GetParam("center")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, + line->GetParam("center")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit, line->GetParam("radius")->AsFloat(0.0f)*g_unit); continue; } @@ -3414,7 +3414,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) throw CLevelParserException("There can be only one LevelController in the level"); } - m_controller = m_objMan->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER); + m_controller = m_objMan->CreateObject(glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER); assert(m_controller->Implements(ObjectInterfaceType::Programmable)); assert(m_controller->Implements(ObjectInterfaceType::ProgramStorage)); @@ -3493,7 +3493,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "CreateFog" && !resetObject) { Gfx::ParticleType type = static_cast(Gfx::PARTIFOG0+(line->GetParam("type")->AsInt())); - Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit; + glm::vec3 pos = line->GetParam("pos")->AsPoint()*g_unit; float height = line->GetParam("height")->AsFloat(1.0f)*g_unit; float ddim = line->GetParam("dim")->AsFloat(50.0f)*g_unit; float delay = line->GetParam("delay")->AsFloat(2.0f); @@ -3502,7 +3502,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) glm::vec2 dim; dim.x = ddim; dim.y = dim.x; - m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, type, delay, 0.0f, 0.0f); + m_particle->CreateParticle(pos, glm::vec3(0.0f, 0.0f, 0.0f), dim, type, delay, 0.0f, 0.0f); continue; } @@ -3560,7 +3560,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rank = m_engine->CreateGroundSpot(); if (rank != -1) { - m_engine->SetObjectGroundSpotPos(rank, line->GetParam("pos")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit); + m_engine->SetObjectGroundSpotPos(rank, line->GetParam("pos")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit); m_engine->SetObjectGroundSpotRadius(rank, line->GetParam("radius")->AsFloat(10.0f)*g_unit); m_engine->SetObjectGroundSpotColor(rank, line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f))); m_engine->SetObjectGroundSpotSmooth(rank, line->GetParam("smooth")->AsFloat(1.0f)); @@ -3585,9 +3585,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_mapImage = line->GetParam("image")->AsBool(false); if (m_mapImage) { - Math::Vector offset; + glm::vec3 offset; strcpy(m_mapFilename, line->GetParam("filename")->AsPath("textures").c_str()); - offset = line->GetParam("offset")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f)); + offset = line->GetParam("offset")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f)); m_map->SetFixParam(line->GetParam("zoom")->AsFloat(1.0f), offset.x, offset.z, line->GetParam("angle")->AsFloat(0.0f)*Math::PI/180.0f, @@ -3621,12 +3621,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "Camera") { - m_camera->Init(line->GetParam("eye")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, - line->GetParam("lookat")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, + m_camera->Init(line->GetParam("eye")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit, + line->GetParam("lookat")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit, resetObject ? 0.0f : line->GetParam("delay")->AsFloat(0.0f)); if (line->GetParam("fadeIn")->AsBool(false)) - m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); + m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, glm::vec3(0.0f, 0.0f, 0.0f), 1.0f); continue; } @@ -3865,7 +3865,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (!m_sceneReadPath.empty() && sel != nullptr) // loading file? { - Math::Vector pos = sel->GetPosition(); + glm::vec3 pos = sel->GetPosition(); m_camera->Init(pos, pos, 0.0f); SelectObject(sel); @@ -3903,7 +3903,7 @@ void CRobotMain::LevelLoadingError(const std::string& error, const std::runtime_ } //! Creates a directional light -int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) +int CRobotMain::CreateLight(glm::vec3 direction, Gfx::Color color) { if (direction.x == 0.0f && direction.y == 0.0f && @@ -3924,7 +3924,7 @@ int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) } //! Creates a light spot -int CRobotMain::CreateSpot(Math::Vector pos, Gfx::Color color) +int CRobotMain::CreateSpot(glm::vec3 pos, Gfx::Color color) { if (!m_engine->GetLightMode()) return -1; @@ -3935,7 +3935,7 @@ int CRobotMain::CreateSpot(Math::Vector pos, Gfx::Color color) light.diffuse = color; light.ambient = color * 0.1f; light.position = pos; - light.direction = Math::Vector(0.0f, -1.0f, 0.0f); + light.direction = glm::vec3(0.0f, -1.0f, 0.0f); light.spotIntensity = 1.0f; light.spotAngle = 90.0f*Math::PI/180.0f; light.attenuation0 = 2.0f; @@ -4105,7 +4105,7 @@ void CRobotMain::ChangeColor() //! Calculates the distance to the nearest object namespace { -float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* exclu) +float SearchNearestObject(CObjectManager* objMan, glm::vec3 center, CObject* exclu) { float min = 100000.0f; for (CObject* obj : objMan->GetAllObjects()) @@ -4119,7 +4119,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* if (type == OBJECT_BASE) { - Math::Vector oPos = obj->GetPosition(); + glm::vec3 oPos = obj->GetPosition(); if (oPos.x != center.x || oPos.z != center.z) { @@ -4134,7 +4134,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* type == OBJECT_REPAIR || type == OBJECT_DESTROYER) { - Math::Vector oPos = obj->GetPosition(); + glm::vec3 oPos = obj->GetPosition(); float dist = Math::Distance(center, oPos) - 8.0f; if (dist < 0.0f) dist = 0.0f; min = Math::Min(min, dist); @@ -4142,7 +4142,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* for (const auto &crashSphere : obj->GetAllCrashSpheres()) { - Math::Vector oPos = crashSphere.sphere.pos; + glm::vec3 oPos = crashSphere.sphere.pos; float oRadius = crashSphere.sphere.radius; float dist = Math::Distance(center, oPos) - oRadius; @@ -4155,7 +4155,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* } //! Calculates a free space -bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadius, +bool CRobotMain::FreeSpace(glm::vec3 ¢er, float minRadius, float maxRadius, float space, CObject *exclu) { if (minRadius < maxRadius) // from internal to external? @@ -4169,7 +4169,7 @@ bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadiu p.x = center.x+radius; p.y = center.z; p = Math::RotatePoint({ center.x, center.z }, angle, p); - Math::Vector pos; + glm::vec3 pos; pos.x = p.x; pos.z = p.y; pos.y = 0.0f; @@ -4198,7 +4198,7 @@ bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadiu p.x = center.x+radius; p.y = center.z; p = Math::RotatePoint({ center.x, center.z }, angle, p); - Math::Vector pos; + glm::vec3 pos; pos.x = p.x; pos.z = p.y; pos.y = 0.0f; @@ -4220,7 +4220,7 @@ bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadiu } //! Calculates a flat free space -bool CRobotMain::FlatFreeSpace(Math::Vector ¢er, float minFlat, float minRadius, float maxRadius, +bool CRobotMain::FlatFreeSpace(glm::vec3 ¢er, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu) { if (minRadius < maxRadius) // from internal to external? @@ -4234,7 +4234,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector ¢er, float minFlat, float minRad p.x = center.x+radius; p.y = center.z; p = Math::RotatePoint({ center.x, center.z }, angle, p); - Math::Vector pos; + glm::vec3 pos; pos.x = p.x; pos.z = p.y; pos.y = 0.0f; @@ -4267,7 +4267,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector ¢er, float minFlat, float minRad p.x = center.x+radius; p.y = center.z; p = Math::RotatePoint({ center.x, center.z }, angle, p); - Math::Vector pos; + glm::vec3 pos; pos.x = p.x; pos.z = p.y; pos.y = 0.0f; @@ -4293,7 +4293,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector ¢er, float minFlat, float minRad } //! Calculates the maximum radius of a free space -float CRobotMain::GetFlatZoneRadius(Math::Vector center, float maxRadius, +float CRobotMain::GetFlatZoneRadius(glm::vec3 center, float maxRadius, CObject *exclu) { float dist = SearchNearestObject(m_objMan.get(), center, exclu); @@ -4326,7 +4326,7 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter) { if (metal == nullptr) return; - Math::Vector center = metal->GetPosition(); + glm::vec3 center = metal->GetPosition(); // Calculates the maximum radius possible depending on other items. float oMax = 30.0f; // radius to build the biggest building @@ -4339,7 +4339,7 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter) if (obj == metal) continue; if (obj == transporter) continue; - Math::Vector oPos; + glm::vec3 oPos; ObjectType type = obj->GetType(); if (type == OBJECT_BASE) @@ -4413,7 +4413,7 @@ void CRobotMain::FlushShowLimit(int i) //! Specifies the boundaries to show void CRobotMain::SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, - Math::Vector pos, float radius, float duration) + glm::vec3 pos, float radius, float duration) { FlushShowLimit(i); // erases the current boundaries @@ -4443,7 +4443,7 @@ void CRobotMain::SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, for (int j = 0; j < m_showLimit[i].total; j++) { - m_showLimit[i].parti[j] = m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, parti, duration); + m_showLimit[i].parti[j] = m_particle->CreateParticle(pos, glm::vec3(0.0f, 0.0f, 0.0f), dim, parti, duration); } } @@ -4504,7 +4504,7 @@ void CRobotMain::FrameShowLimit(float rTime) rotate.y = center.y; rotate = Math::RotatePoint(center, angle, rotate); - Math::Vector pos; + glm::vec3 pos; pos.x = rotate.x; pos.z = rotate.y; pos.y = 0.0f; @@ -4845,7 +4845,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s //! Notifies the user that scene write is finished void CRobotMain::IOWriteSceneFinished() { - m_displayText->DisplayError(INFO_WRITEOK, Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayError(INFO_WRITEOK, glm::vec3(0.0f,0.0f,0.0f)); m_shotSaving--; } @@ -5246,7 +5246,7 @@ Error CRobotMain::ProcessEndMissionTake() std::string text; GetResource(RES_ERR, INFO_TEAM_DEAD, text); text = StrUtils::Format(text.c_str(), GetTeamName(team).c_str()); - m_displayText->DisplayText(text.c_str(), Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_ERROR); + m_displayText->DisplayText(text.c_str(), glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_ERROR); m_displayText->SetEnable(false); // To prevent "bot destroyed" messages m_objMan->DestroyTeam(team); @@ -5260,11 +5260,11 @@ Error CRobotMain::ProcessEndMissionTake() { GetLogger()->Info("Team %d won\n", team); - m_displayText->DisplayText(("<<< Team "+boost::lexical_cast(team)+" won the game >>>").c_str(), Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayText(("<<< Team "+boost::lexical_cast(team)+" won the game >>>").c_str(), glm::vec3(0.0f,0.0f,0.0f)); if (m_missionTimerEnabled && m_missionTimerStarted) { GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); - m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), glm::vec3(0.0f,0.0f,0.0f)); } m_missionTimerEnabled = m_missionTimerStarted = false; m_winDelay = m_endTakeWinDelay; // wins in two seconds @@ -5277,7 +5277,7 @@ Error CRobotMain::ProcessEndMissionTake() std::string text; GetResource(RES_ERR, INFO_TEAM_FINISH, text); text = StrUtils::Format(text.c_str(), GetTeamName(team).c_str()); - m_displayText->DisplayText(text.c_str(), Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayText(text.c_str(), glm::vec3(0.0f,0.0f,0.0f)); if (m_scoreboard) m_scoreboard->ProcessEndTake(team); m_objMan->DestroyTeam(team, DestructionType::Win); @@ -5329,7 +5329,7 @@ Error CRobotMain::CheckEndMission(bool frame) { if (m_lostDelay == 0.0f) { - m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayError(INFO_LOST, glm::vec3(0.0f,0.0f,0.0f)); m_lostDelay = m_endTakeLostDelay; // lost in 6 seconds m_winDelay = 0.0f; } @@ -5361,11 +5361,11 @@ Error CRobotMain::CheckEndMission(bool frame) if (m_winDelay == 0.0f) { - m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayError(INFO_WIN, glm::vec3(0.0f,0.0f,0.0f)); if (m_missionTimerEnabled && m_missionTimerStarted) { GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); - m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); + m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), glm::vec3(0.0f,0.0f,0.0f)); } m_missionTimerEnabled = m_missionTimerStarted = false; m_winDelay = m_endTakeWinDelay; // wins in two seconds @@ -5712,7 +5712,7 @@ void CRobotMain::DisplayError(Error err, CObject* pObj, float time) m_displayText->DisplayError(err, pObj, time); } -void CRobotMain::DisplayError(Error err, Math::Vector goal, float height, float dist, float time) +void CRobotMain::DisplayError(Error err, glm::vec3 goal, float height, float dist, float time) { m_displayText->DisplayError(err, goal, height, dist, time); } @@ -5840,7 +5840,7 @@ void CRobotMain::QuickLoad() std::string dir = m_playerProfile->GetSaveFile(std::string("quicksave")); if(!CResourceManager::Exists(dir)) { - m_displayText->DisplayError(ERR_NO_QUICK_SLOT, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); + m_displayText->DisplayError(ERR_NO_QUICK_SLOT, glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); GetLogger()->Debug("Quicksave slot not found\n"); return; } @@ -6051,15 +6051,15 @@ float CRobotMain::GetGlobalCellCapacity() void CRobotMain::StartDetectEffect(COldObject* object, CObject* target) { Math::Matrix* mat; - Math::Vector pos, goal; + glm::vec3 pos, goal; glm::vec2 dim; mat = object->GetWorldMatrix(0); - pos = Math::Transform(*mat, Math::Vector(2.0f, 3.0f, 0.0f)); + pos = Math::Transform(*mat, glm::vec3(2.0f, 3.0f, 0.0f)); if ( target == nullptr ) { - goal = Math::Transform(*mat, Math::Vector(50.0f, 3.0f, 0.0f)); + goal = Math::Transform(*mat, glm::vec3(50.0f, 3.0f, 0.0f)); } else { @@ -6079,7 +6079,7 @@ void CRobotMain::StartDetectEffect(COldObject* object, CObject* target) goal = Math::SegmentPoint(pos, goal, Math::Distance(pos, goal)-1.0f); dim.x = 6.0f; dim.y = dim.x; - m_particle->CreateParticle(goal, Math::Vector(0.0f, 0.0f, 0.0f), dim, + m_particle->CreateParticle(goal, glm::vec3(0.0f, 0.0f, 0.0f), dim, target != nullptr ? Gfx::PARTIGLINT : Gfx::PARTIGLINTr, 0.5f); } diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 358bd35c..aebfc9b5 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -46,6 +46,8 @@ #include #include +#include + enum Phase { PHASE_WELCOME1, @@ -136,7 +138,7 @@ const int MAXSCENE = 999; struct ShowLimit { bool used = false; - Math::Vector pos; + glm::vec3 pos; float radius = 0.0f; int total = 0; int parti[MAXSHOWPARTI] = {}; @@ -153,8 +155,8 @@ struct MinMax struct Viewpoint { - Math::Vector eye{}; - Math::Vector look{}; + glm::vec3 eye{}; + glm::vec3 look{}; int button = 13; // 13 is the camera button }; @@ -295,15 +297,15 @@ public: void ClearInterface(); void ChangeColor(); - bool FreeSpace(Math::Vector ¢er, float minRadius, float maxRadius, float space, CObject *exclu); - bool FlatFreeSpace(Math::Vector ¢er, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu); + bool FreeSpace(glm::vec3 ¢er, float minRadius, float maxRadius, float space, CObject *exclu); + bool FlatFreeSpace(glm::vec3 ¢er, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu); //! \name In-world indicators //@{ - float GetFlatZoneRadius(Math::Vector center, float maxRadius, CObject *exclu); + float GetFlatZoneRadius(glm::vec3 center, float maxRadius, CObject *exclu); void HideDropZone(CObject* metal); void ShowDropZone(CObject* metal, CObject* transporter); void FlushShowLimit(int i); - void SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, Math::Vector pos, + void SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, glm::vec3 pos, float radius, float duration=SHOWLIMITTIME); void StartShowLimit(); void FrameShowLimit(float rTime); @@ -336,13 +338,13 @@ public: CObject* IOReadObject(CLevelParserLine *line, const std::string& programDir, const std::string& objCounterText, float objectProgress, int objRank = -1); //@} - int CreateSpot(Math::Vector pos, Gfx::Color color); + int CreateSpot(glm::vec3 pos, Gfx::Color color); //! Find the currently selected object CObject* GetSelect(); void DisplayError(Error err, CObject* pObj, float time=10.0f); - void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f); + void DisplayError(Error err, glm::vec3 goal, float height=15.0f, float dist=60.0f, float time=10.0f); void UpdateCustomLevelList(); std::string GetCustomLevelName(int id); @@ -499,7 +501,7 @@ protected: void LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase = PHASE_LEVEL_LIST); - int CreateLight(Math::Vector direction, Gfx::Color color); + int CreateLight(glm::vec3 direction, Gfx::Color color); void HiliteClear(); void HiliteObject(const glm::vec2& pos); void HiliteFrame(float rTime); @@ -676,8 +678,8 @@ protected: CObject* m_visitArrow = nullptr; float m_visitTime = 0.0f; float m_visitParticle = 0.0f; - Math::Vector m_visitPos; - Math::Vector m_visitPosArrow; + glm::vec3 m_visitPos; + glm::vec3 m_visitPosArrow; ActivePause* m_visitPause = nullptr; std::vector> m_endTake; diff --git a/src/math/geometry.h b/src/math/geometry.h index 987cba61..183298c4 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -271,7 +271,7 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from, // difference from the eyepoint to the lookat point. Math::Vector view = at - from; - float length = view.Length(); + float length = glm::length(view); assert(! IsZero(length) ); // Normalize the z basis vector @@ -285,16 +285,16 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from, // If this vector has near-zero length because the input specified a // bogus up vector, let's try a default up vector - if ( IsZero(length = up.Length()) ) + if ( IsZero(length = glm::length(up)) ) { up = Math::Vector(0.0f, 1.0f, 0.0f) - view.y * view; // If we still have near-zero length, resort to a different axis. - if ( IsZero(length = up.Length()) ) + if ( IsZero(length = glm::length(up)) ) { up = Math::Vector(0.0f, 0.0f, 1.0f) - view.z * view; - assert(! IsZero(up.Length()) ); + assert(! IsZero(glm::length(up)) ); } } @@ -518,9 +518,7 @@ inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2 */ inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist) { - Math::Vector direction = p2 - p1; - - direction.Normalize(); + Math::Vector direction = glm::normalize(p2 - p1); return p1 + direction * dist; } diff --git a/src/math/sphere.h b/src/math/sphere.h index e5fec294..fd489e9d 100644 --- a/src/math/sphere.h +++ b/src/math/sphere.h @@ -48,7 +48,7 @@ inline Sphere BoundingSphereForBox(Vector mins, Vector maxs) { auto centroid = (maxs + mins) / 2.0f; auto halfExtent = (maxs - centroid); - return Sphere{centroid, halfExtent.Length()}; + return Sphere{centroid, glm::length(halfExtent)}; } } // namespace Math diff --git a/src/math/vector.h b/src/math/vector.h index a19cda9c..bfd2d857 100644 --- a/src/math/vector.h +++ b/src/math/vector.h @@ -38,212 +38,10 @@ namespace Math { -/** - * \struct Vector - * \brief 3D (3x1) vector - * - * Represents a universal 3x1 vector that can be used in OpenGL and DirectX engines. - * Contains the required methods for operating on vectors. - * - * All methods are made inline to maximize optimization. - * - * Unit tests for the structure and related functions are in module: math/test/vector_test.cpp. - * - */ -struct Vector -{ - //! X - 1st coord - float x; - //! Y - 2nd coord - float y; - //! Z - 3rd coord - float z; - - //! Creates a zero vector (0, 0, 0) - inline Vector() - : x(0.0f) - , y(0.0f) - , z(0.0f) - {} - - //! Creates a vector from given values - inline explicit Vector(float _x, float _y, float _z) - : x(_x) - , y(_y) - , z(_z) - {} - - inline Vector(const glm::vec3& vector) - : x(vector.x) - , y(vector.y) - , z(vector.z) - {} - - //! Loads the zero vector (0, 0, 0) - inline void LoadZero() - { - x = y = z = 0.0f; - } - - //! Returns the struct cast to \c float* array; use with care! - inline float* Array() - { - return reinterpret_cast(this); - } - - //! Returns the struct cast to const float* array; use with care! - inline const float* Array() const - { - return reinterpret_cast(this); - } - - operator glm::vec3() const - { - return { x, y, z }; - } - - //! Returns the vector length - inline float Length() const - { - return sqrtf(x*x + y*y + z*z); - } - - //! Normalizes the vector - inline void Normalize() - { - float l = Length(); - if (IsZero(l)) - return; - - x /= l; - y /= l; - z /= l; - } - - //! Calculates the cross product with another vector - /** - * \param right right-hand side vector - * \returns the cross product - */ - inline Vector CrossMultiply(const Vector &right) const - { - float px = y * right.z - z * right.y; - float py = z * right.x - x * right.z; - float pz = x * right.y - y * right.x; - return Vector(px, py, pz); - } - - //! Calculates the dot product with another vector - /** - * \param right right-hand side vector - * \returns the dot product - */ - inline float DotMultiply(const Vector &right) const - { - return x * right.x + y * right.y + z * right.z; - } - - //! Returns the cosine of angle between this and another vector - inline float CosAngle(const Vector &right) const - { - return DotMultiply(right) / (Length() * right.Length()); - } - - //! Returns angle (in radians) between this and another vector - inline float Angle(const Vector &right) const - { - return acos(CosAngle(right)); - } - - - /* Operators */ - - //! Returns the inverted vector - inline Vector operator-() const - { - return Vector(-x, -y, -z); - } - - //! Adds the given vector - inline const Vector& operator+=(const Vector &right) - { - x += right.x; - y += right.y; - z += right.z; - return *this; - } - - //! Adds two vectors - inline friend const Vector operator+(const Vector &left, const Vector &right) - { - return Vector(left.x + right.x, left.y + right.y, left.z + right.z); - } - - //! Subtracts the given vector - inline const Vector& operator-=(const Vector &right) - { - x -= right.x; - y -= right.y; - z -= right.z; - return *this; - } - - //! Subtracts two vectors - inline friend const Vector operator-(const Vector &left, const Vector &right) - { - return Vector(left.x - right.x, left.y - right.y, left.z - right.z); - } - - //! Multiplies by given scalar - inline const Vector& operator*=(const float &right) - { - x *= right; - y *= right; - z *= right; - return *this; - } - - //! Multiplies vector by scalar - inline friend const Vector operator*(const float &left, const Vector &right) - { - return Vector(left * right.x, left * right.y, left * right.z); - } - - //! Multiplies vector by scalar - inline friend const Vector operator*(const Vector &left, const float &right) - { - return Vector(left.x * right, left.y * right, left.z * right); - } - - //! Divides by given scalar - inline const Vector& operator/=(const float &right) - { - x /= right; - y /= right; - z /= right; - return *this; - } - - //! Divides vector by scalar - inline friend const Vector operator/(const Vector &left, const float &right) - { - return Vector(left.x / right, left.y / right, left.z / right); - } - - - //! Returns a string "[x, y, z]" - inline std::string ToString() const - { - std::stringstream s; - s.precision(3); - s << "[" << x << ", " << y << ", " << z << "]"; - return s.str(); - } - -}; // struct Vector +using Vector = glm::vec3; //! Checks if two vectors are equal within given \a tolerance -inline bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tolerance = 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) @@ -251,47 +49,47 @@ inline bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tol } //! Convenience function for getting normalized vector -inline Vector Normalize(const Math::Vector &v) +inline Vector Normalize(const glm::vec3 &v) { - Vector result = v; - result.Normalize(); - return result; + return glm::normalize(v); } //! Convenience function for calculating dot product -inline float DotProduct(const Math::Vector &left, const Math::Vector &right) +inline float DotProduct(const glm::vec3 &left, const glm::vec3 &right) { - return left.DotMultiply(right); + return glm::dot(left, right); } //! Convenience function for calculating cross product -inline Vector CrossProduct(const Math::Vector &left, const Math::Vector &right) +inline Vector CrossProduct(const glm::vec3 &left, const glm::vec3 &right) { - return left.CrossMultiply(right); + return glm::cross(left, right); } //! Convenience function for calculating angle (in radians) between two vectors -inline float Angle(const Math::Vector &a, const Math::Vector &b) +inline float Angle(const glm::vec3 &a, const glm::vec3 &b) { - return a.Angle(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 Math::Vector &a, const Math::Vector &b) +inline float Distance(const glm::vec3 &a, const glm::vec3 &b) { - return sqrtf( (a.x-b.x)*(a.x-b.x) + - (a.y-b.y)*(a.y-b.y) + - (a.z-b.z)*(a.z-b.z) ); + return glm::distance(a, b); } //! Clamps the vector \a vec to range between \a min and \a max inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max) { - Vector clamped; - clamped.x = Min(Max(min.x, vec.x), max.x); - clamped.y = Min(Max(min.y, vec.y), max.y); - clamped.z = Min(Max(min.z, vec.z), max.z); - return clamped; + return glm::clamp(vec, min, max); +} + +inline std::string ToString(const Vector& vector) +{ + std::stringstream s; + s.precision(3); + s << "[" << vector.x << ", " << vector.y << ", " << vector.z << "]"; + return s.str(); } diff --git a/src/object/auto/autoflag.cpp b/src/object/auto/autoflag.cpp index 05308ecc..c10d4deb 100644 --- a/src/object/auto/autoflag.cpp +++ b/src/object/auto/autoflag.cpp @@ -64,7 +64,7 @@ void CAutoFlag::Init() angle = Math::RotateAngle(wind.x, -wind.z); m_object->SetRotationY(angle); // directs the flag in the wind - m_strong = wind.Length(); + m_strong = glm::length(wind); } diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp index e0a1afb1..6573194a 100644 --- a/src/object/motion/motiontoto.cpp +++ b/src/object/motion/motiontoto.cpp @@ -400,7 +400,7 @@ bool CMotionToto::EventFrame(const Event &event) //? shift *= focus; verti /= focus; - dir = Normalize(lookat-eye); + dir = glm::normalize(lookat-eye); nPos = eye + dir*distance; perp.x = -dir.z; diff --git a/src/object/object.cpp b/src/object/object.cpp index c2d04160..9e7fefe6 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -141,23 +141,23 @@ bool CObject::CanCollideWith(CObject* other) return true; } -Math::Vector CObject::GetPosition() const +glm::vec3 CObject::GetPosition() const { return m_position; } -void CObject::SetPosition(const Math::Vector& pos) +void CObject::SetPosition(const glm::vec3& pos) { // TODO: provide default implementation... throw std::logic_error("CObject::SetPosition() - not implemented!"); } -Math::Vector CObject::GetRotation() const +glm::vec3 CObject::GetRotation() const { return m_rotation; } -void CObject::SetRotation(const Math::Vector& rotation) +void CObject::SetRotation(const glm::vec3& rotation) { // TODO: provide default implementation... throw std::logic_error("CObject::SetRotation() - not implemented!"); @@ -165,21 +165,21 @@ void CObject::SetRotation(const Math::Vector& rotation) void CObject::SetRotationX(float angle) { - Math::Vector rotation = GetRotation(); + glm::vec3 rotation = GetRotation(); rotation.x = angle; return SetRotation(rotation); } void CObject::SetRotationY(float angle) { - Math::Vector rotation = GetRotation(); + glm::vec3 rotation = GetRotation(); rotation.y = angle; return SetRotation(rotation); } void CObject::SetRotationZ(float angle) { - Math::Vector rotation = GetRotation(); + glm::vec3 rotation = GetRotation(); rotation.z = angle; return SetRotation(rotation); } @@ -199,12 +199,12 @@ float CObject::GetRotationZ() return GetRotation().z; } -Math::Vector CObject::GetScale() const +glm::vec3 CObject::GetScale() const { return m_scale; } -void CObject::SetScale(const Math::Vector& scale) +void CObject::SetScale(const glm::vec3& scale) { // TODO: provide default implementation... throw std::logic_error("CObject::SetScale() - not implemented!"); @@ -212,26 +212,26 @@ void CObject::SetScale(const Math::Vector& scale) void CObject::SetScale(float scale) { - SetScale(Math::Vector(scale, scale, scale)); + SetScale(glm::vec3(scale, scale, scale)); } void CObject::SetScaleX(float angle) { - Math::Vector scale = GetScale(); + glm::vec3 scale = GetScale(); scale.x = angle; return SetScale(scale); } void CObject::SetScaleY(float angle) { - Math::Vector scale = GetScale(); + glm::vec3 scale = GetScale(); scale.y = angle; return SetScale(scale); } void CObject::SetScaleZ(float angle) { - Math::Vector scale = GetScale(); + glm::vec3 scale = GetScale(); scale.z = angle; return SetScale(scale); } diff --git a/src/object/object.h b/src/object/object.h index a2c9f4f7..e7bfc127 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -100,16 +100,16 @@ public: } //! Returns object's position - virtual Math::Vector GetPosition() const; + virtual glm::vec3 GetPosition() const; //! Sets object's position - virtual void SetPosition(const Math::Vector& pos); + virtual void SetPosition(const glm::vec3& pos); //! Returns object's rotation (Euler angles) /** Angles are given in radians */ - virtual Math::Vector GetRotation() const; + virtual glm::vec3 GetRotation() const; //! Sets object's rotation (Euler angles) /** Angles are given in radians */ - virtual void SetRotation(const Math::Vector& rotation); + virtual void SetRotation(const glm::vec3& rotation); //!@{ //! Shortcuts for rotation components @@ -122,9 +122,9 @@ public: //!@} //! Returns object's scale - virtual Math::Vector GetScale() const; + virtual glm::vec3 GetScale() const; //! Sets objects's scale - virtual void SetScale(const Math::Vector& scale); + virtual void SetScale(const glm::vec3& scale); //! Sets objects's scale (uniform value) void SetScale(float scale); @@ -221,9 +221,9 @@ protected: const int m_id; //!< unique identifier ObjectType m_type; //!< object type ObjectInterfaceTypes m_implementedInterfaces; //!< interfaces that the object implements - Math::Vector m_position; - Math::Vector m_rotation; - Math::Vector m_scale; + glm::vec3 m_position{ 0, 0, 0 }; + glm::vec3 m_rotation{ 0, 0, 0 }; + glm::vec3 m_scale{ 0, 0, 0 }; std::vector m_crashSpheres; //!< crash spheres Math::Sphere m_cameraCollisionSphere; bool m_animateOnReset; diff --git a/src/object/object_create_params.h b/src/object/object_create_params.h index 15e1d0a4..fa07d91f 100644 --- a/src/object/object_create_params.h +++ b/src/object/object_create_params.h @@ -25,7 +25,7 @@ struct ObjectCreateParams { - Math::Vector pos; + glm::vec3 pos; float angle; ObjectType type; float power; @@ -38,7 +38,7 @@ struct ObjectCreateParams ObjectCreateParams() { - pos = Math::Vector(0.0f, 0.0f, 0.0f); + pos = glm::vec3(0.0f, 0.0f, 0.0f); angle = 0.0f; type = OBJECT_NULL; power = -1.0f; diff --git a/src/object/object_manager.cpp b/src/object/object_manager.cpp index c0eb90dd..8ecc23e2 100644 --- a/src/object/object_manager.cpp +++ b/src/object/object_manager.cpp @@ -158,7 +158,7 @@ CObject* CObjectManager::CreateObject(ObjectCreateParams params) return objectPtr; } -CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type, float power) +CObject* CObjectManager::CreateObject(glm::vec3 pos, float angle, ObjectType type, float power) { ObjectCreateParams params; params.pos = pos; @@ -248,7 +248,7 @@ std::vector CObjectManager::RadarAll(CObject* pThis, ObjectType type, std::vector CObjectManager::RadarAll(CObject* pThis, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { - Math::Vector iPos; + glm::vec3 iPos{}; float iAngle; if (pThis != nullptr) { @@ -258,13 +258,13 @@ std::vector CObjectManager::RadarAll(CObject* pThis, std::vector CObjectManager::RadarAll(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +std::vector CObjectManager::RadarAll(CObject* pThis, glm::vec3 thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { std::vector types; if (type != OBJECT_NULL) @@ -272,10 +272,10 @@ std::vector CObjectManager::RadarAll(CObject* pThis, Math::Vector this return RadarAll(pThis, thisPosition, thisAngle, types, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); } -std::vector CObjectManager::RadarAll(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +std::vector CObjectManager::RadarAll(CObject* pThis, glm::vec3 thisPosition, float thisAngle, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { CObject *pObj; - Math::Vector iPos, oPos; + glm::vec3 iPos{ 0, 0, 0 }, oPos{ 0, 0, 0 }; float iAngle, d, a; ObjectType oType; @@ -432,13 +432,13 @@ CObject* CObjectManager::Radar(CObject* pThis, std::vector type, flo return best.size() > 0 ? best[0] : nullptr; } -CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +CObject* CObjectManager::Radar(CObject* pThis, glm::vec3 thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { std::vector best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); return best.size() > 0 ? best[0] : nullptr; } -CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +CObject* CObjectManager::Radar(CObject* pThis, glm::vec3 thisPosition, float thisAngle, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { std::vector best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); return best.size() > 0 ? best[0] : nullptr; @@ -454,12 +454,12 @@ CObject* CObjectManager::FindNearest(CObject* pThis, std::vector ty return Radar(pThis, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes); } -CObject* CObjectManager::FindNearest(CObject* pThis, Math::Vector thisPosition, ObjectType type, float maxDist, bool cbotTypes) +CObject* CObjectManager::FindNearest(CObject* pThis, glm::vec3 thisPosition, ObjectType type, float maxDist, bool cbotTypes) { return Radar(pThis, thisPosition, 0.0f, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes); } -CObject* CObjectManager::FindNearest(CObject* pThis, Math::Vector thisPosition, std::vector type, float maxDist, bool cbotTypes) +CObject* CObjectManager::FindNearest(CObject* pThis, glm::vec3 thisPosition, std::vector type, float maxDist, bool cbotTypes) { return Radar(pThis, thisPosition, 0.0f, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes); } diff --git a/src/object/object_manager.h b/src/object/object_manager.h index cc2a4c0b..8572a677 100644 --- a/src/object/object_manager.h +++ b/src/object/object_manager.h @@ -160,7 +160,7 @@ public: //! Creates an object //@{ CObject* CreateObject(ObjectCreateParams params); - CObject* CreateObject(Math::Vector pos, float angle, ObjectType type, float power = -1.0f); + CObject* CreateObject(glm::vec3 pos, float angle, ObjectType type, float power = -1.0f); //@} //! Deletes the object @@ -215,7 +215,7 @@ public: RadarFilter filter = FILTER_NONE, bool cbotTypes = false); std::vector RadarAll(CObject* pThis, - Math::Vector thisPosition, + glm::vec3 thisPosition, float thisAngle, ObjectType type = OBJECT_NULL, float angle = 0.0f, @@ -226,7 +226,7 @@ public: RadarFilter filter = FILTER_NONE, bool cbotTypes = false); std::vector RadarAll(CObject* pThis, - Math::Vector thisPosition, + glm::vec3 thisPosition, float thisAngle, std::vector type = std::vector(), float angle = 0.0f, @@ -258,7 +258,7 @@ public: RadarFilter filter = FILTER_NONE, bool cbotTypes = false); CObject* Radar(CObject* pThis, - Math::Vector thisPosition, + glm::vec3 thisPosition, float thisAngle, ObjectType type = OBJECT_NULL, float angle = 0.0f, @@ -269,7 +269,7 @@ public: RadarFilter filter = FILTER_NONE, bool cbotTypes = false); CObject* Radar(CObject* pThis, - Math::Vector thisPosition, + glm::vec3 thisPosition, float thisAngle, std::vector type = std::vector(), float angle = 0.0f, @@ -291,12 +291,12 @@ public: float maxDist = 1000.0f, bool cbotTypes = false); CObject* FindNearest(CObject* pThis, - Math::Vector thisPosition, + glm::vec3 thisPosition, ObjectType type = OBJECT_NULL, float maxDist = 1000.0f, bool cbotTypes = false); CObject* FindNearest(CObject* pThis, - Math::Vector thisPosition, + glm::vec3 thisPosition, std::vector type = std::vector(), float maxDist = 1000.0f, bool cbotTypes = false); diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index d7c0abdb..9c9f2683 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -84,7 +84,7 @@ CPhysics::CPhysics(COldObject* object) m_gravity = 9.81f; // default gravity m_time = 0.0f; m_timeUnderWater = 0.0f; - m_motorSpeed = Math::Vector(0.0f, 0.0f, 0.0f); + m_motorSpeed = glm::vec3(0.0f, 0.0f, 0.0f); m_bMotor = false; m_bLand = true; // ground m_bSwim = false; // in air @@ -181,7 +181,7 @@ bool CPhysics::Write(CLevelParserLine* line) bool CPhysics::Read(CLevelParserLine* line) { - m_motorSpeed = line->GetParam("motor")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f)); + m_motorSpeed = line->GetParam("motor")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f)); if ( m_object->Implements(ObjectInterfaceType::Flying) ) { @@ -302,7 +302,7 @@ bool CPhysics::GetFreeze() // y = up/down // z = turn -void CPhysics::SetMotorSpeed(Math::Vector speed) +void CPhysics::SetMotorSpeed(glm::vec3 speed) { m_motorSpeed = speed; } @@ -334,7 +334,7 @@ void CPhysics::SetMotorSpeedZ(float speed) m_motorSpeed.z = speed; } -Math::Vector CPhysics::GetMotorSpeed() +glm::vec3 CPhysics::GetMotorSpeed() { return m_motorSpeed; } @@ -358,7 +358,7 @@ float CPhysics::GetMotorSpeedZ() // Management of linear and angular velocities. // Specifies the speed parallel to the direction of travel. -void CPhysics::SetLinMotion(PhysicsMode mode, Math::Vector value) +void CPhysics::SetLinMotion(PhysicsMode mode, glm::vec3 value) { if ( mode == MO_ADVACCEL ) m_linMotion.advanceAccel = value; if ( mode == MO_RECACCEL ) m_linMotion.recedeAccel = value; @@ -374,7 +374,7 @@ void CPhysics::SetLinMotion(PhysicsMode mode, Math::Vector value) if ( mode == MO_REASPEED ) m_linMotion.realSpeed = value; } -Math::Vector CPhysics::GetLinMotion(PhysicsMode mode) +glm::vec3 CPhysics::GetLinMotion(PhysicsMode mode) { if ( mode == MO_ADVACCEL ) return m_linMotion.advanceAccel; if ( mode == MO_RECACCEL ) return m_linMotion.recedeAccel; @@ -388,7 +388,7 @@ Math::Vector CPhysics::GetLinMotion(PhysicsMode mode) if ( mode == MO_MOTSPEED ) return m_linMotion.motorSpeed; if ( mode == MO_CURSPEED ) return m_linMotion.currentSpeed; if ( mode == MO_REASPEED ) return m_linMotion.realSpeed; - return Math::Vector(0.0f, 0.0f, 0.0f); + return glm::vec3(0.0f, 0.0f, 0.0f); } void CPhysics::SetLinMotionX(PhysicsMode mode, float value) @@ -496,7 +496,7 @@ float CPhysics::GetLinMotionZ(PhysicsMode mode) // Specifies the rotation around the axis of walk. -void CPhysics::SetCirMotion(PhysicsMode mode, Math::Vector value) +void CPhysics::SetCirMotion(PhysicsMode mode, glm::vec3 value) { if ( mode == MO_ADVACCEL ) m_cirMotion.advanceAccel = value; if ( mode == MO_RECACCEL ) m_cirMotion.recedeAccel = value; @@ -512,7 +512,7 @@ void CPhysics::SetCirMotion(PhysicsMode mode, Math::Vector value) if ( mode == MO_REASPEED ) m_cirMotion.realSpeed = value; } -Math::Vector CPhysics::GetCirMotion(PhysicsMode mode) +glm::vec3 CPhysics::GetCirMotion(PhysicsMode mode) { if ( mode == MO_ADVACCEL ) return m_cirMotion.advanceAccel; if ( mode == MO_RECACCEL ) return m_cirMotion.recedeAccel; @@ -526,7 +526,7 @@ Math::Vector CPhysics::GetCirMotion(PhysicsMode mode) if ( mode == MO_MOTSPEED ) return m_cirMotion.motorSpeed; if ( mode == MO_CURSPEED ) return m_cirMotion.currentSpeed; if ( mode == MO_REASPEED ) return m_cirMotion.realSpeed; - return Math::Vector(0.0f, 0.0f, 0.0f); + return glm::vec3(0.0f, 0.0f, 0.0f); } void CPhysics::SetCirMotionX(PhysicsMode mode, float value) @@ -757,7 +757,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime) { ObjectType type; CPowerContainerObject* power = nullptr; - Math::Vector pos, motorSpeed; + glm::vec3 pos{ 0, 0, 0 }, motorSpeed{ 0, 0, 0 }; float energy, speed, factor, h; type = m_object->GetType(); @@ -1013,7 +1013,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime) void CPhysics::EffectUpdate(float aTime, float rTime) { Character* character; - Math::Vector vibLin, vibCir, incl; + glm::vec3 vibLin{ 0, 0, 0 }, vibCir{ 0, 0, 0 }, incl{ 0, 0, 0 }; float speedLin, speedCir, accel; ObjectType type; bool bOnBoard; @@ -1142,10 +1142,10 @@ void CPhysics::EffectUpdate(float aTime, float rTime) } else { - m_motion->SetLinVibration(Math::Vector(0.0f, 0.0f, 0.0f)); + m_motion->SetLinVibration(glm::vec3(0.0f, 0.0f, 0.0f)); -//? m_motion->SetCirVibration(Math::Vector(0.0f, 0.0f, 0.0f)); -//? m_motion->SetTilt(Math::Vector(0.0f, 0.0f, 0.0f)); +//? m_motion->SetCirVibration(glm::vec3(0.0f, 0.0f, 0.0f)); +//? m_motion->SetTilt(glm::vec3(0.0f, 0.0f, 0.0f)); } } @@ -1204,9 +1204,9 @@ void CPhysics::EffectUpdate(float aTime, float rTime) { if ( m_bLand ) // on the ground? { - m_motion->SetLinVibration(Math::Vector(0.0f, 0.0f, 0.0f)); - m_motion->SetCirVibration(Math::Vector(0.0f, 0.0f, 0.0f)); - m_motion->SetTilt(Math::Vector(0.0f, 0.0f, 0.0f)); + m_motion->SetLinVibration(glm::vec3(0.0f, 0.0f, 0.0f)); + m_motion->SetCirVibration(glm::vec3(0.0f, 0.0f, 0.0f)); + m_motion->SetTilt(glm::vec3(0.0f, 0.0f, 0.0f)); } else // in flight? { @@ -1442,7 +1442,7 @@ bool CPhysics::EventFrame(const Event &event) { ObjectType type; Math::Matrix objRotate, matRotate; - Math::Vector iPos, iAngle, tAngle, pos, newpos, angle, newangle, n; + glm::vec3 iPos{ 0, 0, 0 }, iAngle{ 0, 0, 0 }, tAngle{ 0, 0, 0 }, pos{ 0, 0, 0 }, newpos{ 0, 0, 0 }, angle{ 0, 0, 0 }, newangle{ 0, 0, 0 }, n{ 0, 0, 0 }; float h, w; int i; @@ -1745,7 +1745,7 @@ void CPhysics::SoundMotor(float rTime) void CPhysics::WaterFrame(float aTime, float rTime) { ObjectType type; - Math::Vector pos, speed; + glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 }; glm::vec2 dim; float level; @@ -1961,7 +1961,7 @@ void CPhysics::SoundMotorFull(float rTime, ObjectType type) void CPhysics::SoundMotorSlow(float rTime, ObjectType type) { Math::Matrix* mat; - Math::Vector pos, speed; + glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 }; glm::vec2 dim; SoundType sound; float amplitude; @@ -2069,7 +2069,7 @@ void CPhysics::SoundMotorSlow(float rTime, ObjectType type) max = static_cast(10.0f*m_engine->GetParticleDensity()); for ( i=0 ; iGetType() == OBJECT_HUMAN || m_object->GetType() == OBJECT_TECH ) { - pos = Math::Vector(-1.6f, -0.5f, 0.0f); + pos = glm::vec3(-1.6f, -0.5f, 0.0f); } else { - pos = Math::Vector(0.0f, -1.0f, 0.0f); + pos = glm::vec3(0.0f, -1.0f, 0.0f); } pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f; @@ -2211,11 +2211,11 @@ void CPhysics::SoundReactorFull(float rTime, ObjectType type) if ( m_object->GetType() == OBJECT_HUMAN || m_object->GetType() == OBJECT_TECH ) { - pos = Math::Vector(-1.6f, -0.5f, 0.0f); + pos = glm::vec3(-1.6f, -0.5f, 0.0f); } else { - pos = Math::Vector(0.0f, -1.0f, 0.0f); + pos = glm::vec3(0.0f, -1.0f, 0.0f); } pos.x += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f; @@ -2285,11 +2285,11 @@ void CPhysics::SoundReactorStop(float rTime, ObjectType type) // Adapts the physics of the object based on the ground. void CPhysics::FloorAdapt(float aTime, float rTime, - Math::Vector &pos, Math::Vector &angle) + glm::vec3 &pos, glm::vec3 &angle) { Character* character; ObjectType type; - Math::Vector norm; + glm::vec3 norm{ 0, 0, 0 }; Math::Matrix matRotate; float level, h, f, a1, volume, freq, force; bool bSlopingTerrain; @@ -2459,10 +2459,10 @@ void CPhysics::FloorAdapt(float aTime, float rTime, // Calculates the angle of an object with the field. -void CPhysics::FloorAngle(const Math::Vector &pos, Math::Vector &angle) +void CPhysics::FloorAngle(const glm::vec3 &pos, glm::vec3 &angle) { Character* character; - Math::Vector pw, norm; + glm::vec3 pw{ 0, 0, 0 }, norm{ 0, 0, 0 }; float a1, a2; character = m_object->GetCharacter(); @@ -2498,10 +2498,10 @@ void CPhysics::FloorAngle(const Math::Vector &pos, Math::Vector &angle) // Returns 1 -> immobile object (because collision) // Returns 2 -> destroyed object -int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) +int CPhysics::ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle) { Math::Matrix matRotate; - Math::Vector iPos, oAngle, oSpeed; + glm::vec3 iPos{ 0, 0, 0 }, oAngle{ 0, 0, 0 }, oSpeed{ 0, 0, 0 }; float distance, force, volume; int colType; ObjectType iType, oType; @@ -2515,7 +2515,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) return 0; auto firstCrashSphere = m_object->GetFirstCrashSphere(); - Math::Vector iiPos = firstCrashSphere.sphere.pos; + glm::vec3 iiPos = firstCrashSphere.sphere.pos; float iRad = firstCrashSphere.sphere.radius; iPos = iiPos + (pos - m_object->GetPosition()); @@ -2540,7 +2540,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) !pObj->GetLock() && m_object->GetTrainer() ) // driving vehicle? { - Math::Vector oPos = pObj->GetPosition(); + glm::vec3 oPos = pObj->GetPosition(); distance = Math::DistanceProjected(oPos, iPos); if ( distance < 4.0f ) { @@ -2551,7 +2551,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) if ( oType == OBJECT_TARGET2 && !pObj->GetLock() ) { - Math::Vector oPos = pObj->GetPosition(); + glm::vec3 oPos = pObj->GetPosition(); distance = Math::Distance(oPos, iPos); if ( distance < 10.0f*1.5f ) { @@ -2562,7 +2562,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) for (const auto& crashSphere : pObj->GetAllCrashSpheres()) { - Math::Vector oPos = crashSphere.sphere.pos; + glm::vec3 oPos = crashSphere.sphere.pos; float oRad = crashSphere.sphere.radius; // Aliens ignore small objects @@ -2592,7 +2592,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) if ( colType == 0 ) continue; // ignores? } - force = m_linMotion.realSpeed.Length(); + force = glm::length(m_linMotion.realSpeed); force *= crashSphere.hardness; volume = fabs(force*0.05f); if ( volume > 1.0f ) volume = 1.0f; @@ -2616,7 +2616,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) m_repeatCollision = 10; } - m_linMotion.currentSpeed = Normalize(iPos-oPos)*force; + m_linMotion.currentSpeed = glm::normalize(iPos-oPos)*force; Math::LoadRotationXZYMatrix(matRotate, -angle); m_linMotion.currentSpeed = Transform(matRotate, m_linMotion.currentSpeed); if ( !m_object->Implements(ObjectInterfaceType::Flying) ) @@ -2631,7 +2631,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) if ( ph != nullptr ) { oAngle = pObj->GetRotation(); - oSpeed = Normalize(oPos-iPos)*force; + oSpeed = glm::normalize(oPos-iPos)*force; Math::LoadRotationXZYMatrix(matRotate, -oAngle); oSpeed = Transform(matRotate, oSpeed); if ( !pObj->Implements(ObjectInterfaceType::Flying) ) @@ -2660,7 +2660,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) // Shakes an object. -bool CPhysics::JostleObject(CJostleableObject* pObj, Math::Vector iPos, float iRad) +bool CPhysics::JostleObject(CJostleableObject* pObj, glm::vec3 iPos, float iRad) { Math::Sphere jostlingSphere = pObj->GetJostlingSphere(); @@ -2672,9 +2672,9 @@ bool CPhysics::JostleObject(CJostleableObject* pObj, Math::Vector iPos, float iR if ( f < 0.0f ) f = 0.0f; if ( f > 1.0f ) f = 1.0f; - Math::Vector speed = m_linMotion.realSpeed; + glm::vec3 speed = m_linMotion.realSpeed; speed.y = 0.0f; - float force = speed.Length()*f*0.05f; + float force = glm::length(speed)*f*0.05f; if ( force > 1.0f ) force = 1.0f; if ( m_soundTimeJostle >= 0.20f ) @@ -2962,7 +2962,7 @@ void CPhysics::FrameParticle(float aTime, float rTime) void CPhysics::PowerParticle(float factor, bool bBreak) { Math::Matrix* mat; - Math::Vector pos, ppos, eye, speed; + glm::vec3 pos{ 0, 0, 0 }, ppos{ 0, 0, 0 }, eye{ 0, 0, 0 }, speed{ 0, 0, 0 }; glm::vec2 dim; bool bCarryPower; @@ -3000,7 +3000,7 @@ void CPhysics::PowerParticle(float factor, bool bBreak) if ( bCarryPower ) // carry a battery? { - pos = Math::Vector(3.0f, 5.6f, 0.0f); // position of battery holder // TODO: Move to CTransportableObject + pos = glm::vec3(3.0f, 5.6f, 0.0f); // position of battery holder // TODO: Move to CTransportableObject pos = Transform(*mat, pos); speed.x = (Math::Rand()-0.5f)*12.0f; @@ -3023,7 +3023,7 @@ void CPhysics::PowerParticle(float factor, bool bBreak) void CPhysics::CrashParticle(float crash) { - Math::Vector pos, ppos, speed; + glm::vec3 pos{ 0, 0, 0 }, ppos{ 0, 0, 0 }, speed{ 0, 0, 0 }; glm::vec2 dim; float len; int i, max; @@ -3057,7 +3057,7 @@ void CPhysics::CrashParticle(float crash) void CPhysics::MotorParticle(float aTime, float rTime) { Math::Matrix* mat; - Math::Vector pos, speed; + glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 }; glm::vec2 dim; ObjectType type; glm::vec2 c, p; @@ -3166,7 +3166,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) pos.z = Math::Rand()*0.4f+1.0f; if ( rand()%2 == 0 ) pos.z = -pos.z; pos = Transform(*mat, pos); - speed = Math::Vector(0.0f, 1.0f, 0.0f); + speed = glm::vec3(0.0f, 1.0f, 0.0f); dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f; if ( dim.x > 2.5f ) dim.x = 2.5f; dim.y = dim.x; @@ -3195,7 +3195,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) pos.z = Math::Rand()*2.0f+3.0f; if ( rand()%2 == 0 ) pos.z = -pos.z; pos = Transform(*mat, pos); - speed = Math::Vector(0.0f, 0.0f, 0.0f); + speed = glm::vec3(0.0f, 0.0f, 0.0f); dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f; if ( dim.x > 3.0f ) dim.x = 3.0f; dim.y = dim.x; @@ -3223,7 +3223,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) pos.z = Math::Rand()*3.0f+3.0f; if ( rand()%2 == 0 ) pos.z = -pos.z; pos = Transform(*mat, pos); - speed = Math::Vector(0.0f, 0.0f, 0.0f); + speed = glm::vec3(0.0f, 0.0f, 0.0f); dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f; if ( dim.x > 3.0f ) dim.x = 3.0f; dim.y = dim.x; @@ -3249,7 +3249,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.05f) ) return; m_lastMotorParticle = aTime; - pos = Math::Vector(-1.6f, -0.5f, 0.0f); + pos = glm::vec3(-1.6f, -0.5f, 0.0f); mat = m_object->GetWorldMatrix(0); pos = Transform(*mat, pos); @@ -3278,7 +3278,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.02f) ) return; m_lastMotorParticle = aTime; - pos = Math::Vector(-1.6f, -1.0f, 0.0f); + pos = glm::vec3(-1.6f, -1.0f, 0.0f); pos.x += (Math::Rand()-0.5f)*3.0f; pos.y += (Math::Rand()-0.5f)*1.5f; pos.z += (Math::Rand()-0.5f)*3.0f; @@ -3288,7 +3288,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) h = m_floorHeight; if ( h > 10.0f ) // high enough? { - speed = Math::Vector(0.0f, -10.0f, 0.0f); // against the bottom + speed = glm::vec3(0.0f, -10.0f, 0.0f); // against the bottom } else { @@ -3302,7 +3302,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f); - pos = Math::Vector(-1.6f, -0.5f, 0.0f); + pos = glm::vec3(-1.6f, -0.5f, 0.0f); pos = Transform(*mat, pos); speed.x = (Math::Rand()-0.5f)*1.0f; @@ -3356,15 +3356,15 @@ void CPhysics::MotorParticle(float aTime, float rTime) m_lastMotorParticle = aTime; r = rand()%3; - if ( r == 0 ) pos = Math::Vector(-3.0f, 0.0f, -4.0f); - if ( r == 1 ) pos = Math::Vector(-3.0f, 0.0f, 4.0f); - if ( r == 2 ) pos = Math::Vector( 4.0f, 0.0f, 0.0f); + if ( r == 0 ) pos = glm::vec3(-3.0f, 0.0f, -4.0f); + if ( r == 1 ) pos = glm::vec3(-3.0f, 0.0f, 4.0f); + if ( r == 2 ) pos = glm::vec3( 4.0f, 0.0f, 0.0f); pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f; mat = m_object->GetWorldMatrix(0); pos = Transform(*mat, pos); - speed = Math::Vector(0.0f, 0.0f, 0.0f); + speed = glm::vec3(0.0f, 0.0f, 0.0f); dim.x = Math::Rand()*h/5.0f+2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f); @@ -3378,15 +3378,15 @@ void CPhysics::MotorParticle(float aTime, float rTime) m_lastMotorParticle = aTime; r = rand()%3; - if ( r == 0 ) pos = Math::Vector(-3.0f, 0.0f, -4.0f); - if ( r == 1 ) pos = Math::Vector(-3.0f, 0.0f, 4.0f); - if ( r == 2 ) pos = Math::Vector( 4.0f, 0.0f, 0.0f); + if ( r == 0 ) pos = glm::vec3(-3.0f, 0.0f, -4.0f); + if ( r == 1 ) pos = glm::vec3(-3.0f, 0.0f, 4.0f); + if ( r == 2 ) pos = glm::vec3( 4.0f, 0.0f, 0.0f); pos.x += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f; mat = m_object->GetWorldMatrix(0); pos = Transform(*mat, pos); - speed = Math::Vector(0.0f, 0.0f, 0.0f); + speed = glm::vec3(0.0f, 0.0f, 0.0f); dim.x = 1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIEJECT); @@ -3399,7 +3399,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.02f) ) return; m_lastMotorParticle = aTime; - pos = Math::Vector(0.0f, -1.0f, 0.0f); + pos = glm::vec3(0.0f, -1.0f, 0.0f); pos.x += (Math::Rand()-0.5f)*6.0f; pos.y += (Math::Rand()-0.5f)*3.0f; pos.z += (Math::Rand()-0.5f)*6.0f; @@ -3409,7 +3409,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) h = m_floorHeight; if ( h > 10.0f ) // high enough? { - speed = Math::Vector(0.0f, -10.0f, 0.0f); // against the bottom + speed = glm::vec3(0.0f, -10.0f, 0.0f); // against the bottom } else { @@ -3423,7 +3423,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f); - pos = Math::Vector(0.0f, 1.0f, 0.0f); + pos = glm::vec3(0.0f, 1.0f, 0.0f); pos = Transform(*mat, pos); speed.x = (Math::Rand()-0.5f)*1.0f; @@ -3463,7 +3463,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.06f) ) return; m_lastMotorParticle = aTime; - pos = Math::Vector(0.0f, 3.0f, 0.0f); + pos = glm::vec3(0.0f, 3.0f, 0.0f); mat = m_object->GetWorldMatrix(0); pos = Transform(*mat, pos); pos.x += (Math::Rand()-0.5f)*1.0f; @@ -3489,7 +3489,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.06f) ) return; m_lastMotorParticle = aTime; - pos = Math::Vector(0.0f, 3.0f, 0.0f); + pos = glm::vec3(0.0f, 3.0f, 0.0f); mat = m_object->GetWorldMatrix(0); pos = Transform(*mat, pos); pos.x += (Math::Rand()-0.5f)*1.0f; @@ -3524,7 +3524,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.1f) ) return; m_lastMotorParticle = aTime; - pos = Math::Vector(-2.5f, 10.3f, -1.3f); + pos = glm::vec3(-2.5f, 10.3f, -1.3f); pos.x += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f; mat = m_object->GetWorldMatrix(0); @@ -3546,7 +3546,7 @@ void CPhysics::MotorParticle(float aTime, float rTime) if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.05f) ) return; m_lastMotorParticle = aTime; - pos = Math::Vector(-3.4f, 1.8f, 0.5f); + pos = glm::vec3(-3.4f, 1.8f, 0.5f); speed = pos; if ( m_linMotion.currentSpeed.x < 0.0f ) @@ -3578,10 +3578,10 @@ void CPhysics::MotorParticle(float aTime, float rTime) // Generates some particles after falling into the water. -void CPhysics::WaterParticle(float aTime, Math::Vector pos, ObjectType type, +void CPhysics::WaterParticle(float aTime, glm::vec3 pos, ObjectType type, float floor, float advance, float turn) { - Math::Vector ppos, speed; + glm::vec3 ppos{ 0, 0, 0 }, speed{ 0, 0, 0 }; glm::vec2 dim; float delay, level, min, max, force, volume, diam; int i, nb; @@ -3625,7 +3625,7 @@ void CPhysics::WaterParticle(float aTime, Math::Vector pos, ObjectType type, pos.y = m_water->GetLevel()-1.0f; dim.x = 2.0f*force; // height dim.y = diam; // diameter - m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, Gfx::PARTIPLOUF0, 1.4f, 0.0f, 0.0f); + m_particle->CreateParticle(pos, glm::vec3(0.0f, 0.0f, 0.0f), dim, Gfx::PARTIPLOUF0, 1.4f, 0.0f, 0.0f); force = (0.5f+force*0.5f); nb = static_cast(force*50.0f*m_engine->GetParticleDensity()); @@ -3697,7 +3697,7 @@ void CPhysics::WaterParticle(float aTime, Math::Vector pos, ObjectType type, void CPhysics::WheelParticle(TraceColor color, float width) { Math::Matrix* mat; - Math::Vector goal1, goal2, wheel1, wheel2; + glm::vec3 goal1{ 0, 0, 0 }, goal2{ 0, 0, 0 }, wheel1{ 0, 0, 0 }, wheel2{ 0, 0, 0 }; float dist1, dist2, step; mat = m_object->GetWorldMatrix(0); diff --git a/src/physics/physics.h b/src/physics/physics.h index 1b0e9dc1..078cccc6 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -72,23 +72,23 @@ enum PhysicsMode struct Motion { - Math::Vector advanceAccel; // acceleration starting (+) - Math::Vector recedeAccel; // acceleration starting (+) - Math::Vector stopAccel; // acceleration stoping (+) - Math::Vector motorAccel; // current acceleration (+/-) + glm::vec3 advanceAccel{ 0, 0, 0 }; // acceleration starting (+) + glm::vec3 recedeAccel{ 0, 0, 0 }; // acceleration starting (+) + glm::vec3 stopAccel{ 0, 0, 0 }; // acceleration stoping (+) + glm::vec3 motorAccel{ 0, 0, 0 }; // current acceleration (+/-) - Math::Vector advanceSpeed; // forward speed (+) - Math::Vector recedeSpeed; // reversing speed (+) - Math::Vector motorSpeed; // desired speed (+/-) - Math::Vector currentSpeed; // current speed (+/-) + glm::vec3 advanceSpeed{ 0, 0, 0 }; // forward speed (+) + glm::vec3 recedeSpeed{ 0, 0, 0 }; // reversing speed (+) + glm::vec3 motorSpeed{ 0, 0, 0 }; // desired speed (+/-) + glm::vec3 currentSpeed{ 0, 0, 0 }; // current speed (+/-) - Math::Vector terrainForce; // power of resistance of the ground (+) - Math::Vector terrainSpeed; // speed of the ground (+/-) - Math::Vector terrainSlide; // limit sliding speed (+) + glm::vec3 terrainForce{ 0, 0, 0 }; // power of resistance of the ground (+) + glm::vec3 terrainSpeed{ 0, 0, 0 }; // speed of the ground (+/-) + glm::vec3 terrainSlide{ 0, 0, 0 }; // limit sliding speed (+) - Math::Vector realSpeed; // real speed(+/-) + glm::vec3 realSpeed{ 0, 0, 0 }; // real speed(+/-) - Math::Vector finalInclin; // final inclination + glm::vec3 finalInclin{ 0, 0, 0 }; // final inclination }; @@ -114,8 +114,8 @@ public: float GetFloorHeight(); - void SetLinMotion(PhysicsMode mode, Math::Vector value); - Math::Vector GetLinMotion(PhysicsMode mode); + void SetLinMotion(PhysicsMode mode, glm::vec3 value); + glm::vec3 GetLinMotion(PhysicsMode mode); void SetLinMotionX(PhysicsMode mode, float value); void SetLinMotionY(PhysicsMode mode, float value); void SetLinMotionZ(PhysicsMode mode, float value); @@ -123,8 +123,8 @@ public: float GetLinMotionY(PhysicsMode mode); float GetLinMotionZ(PhysicsMode mode); - void SetCirMotion(PhysicsMode mode, Math::Vector value); - Math::Vector GetCirMotion(PhysicsMode mode); + void SetCirMotion(PhysicsMode mode, glm::vec3 value); + glm::vec3 GetCirMotion(PhysicsMode mode); void SetCirMotionX(PhysicsMode mode, float value); void SetCirMotionY(PhysicsMode mode, float value); void SetCirMotionZ(PhysicsMode mode, float value); @@ -149,11 +149,11 @@ public: void SetFreeze(bool bFreeze); bool GetFreeze(); - void SetMotorSpeed(Math::Vector speed); + void SetMotorSpeed(glm::vec3 speed); void SetMotorSpeedX(float speed); void SetMotorSpeedY(float speed); void SetMotorSpeedZ(float speed); - Math::Vector GetMotorSpeed(); + glm::vec3 GetMotorSpeed(); float GetMotorSpeedX(); float GetMotorSpeedY(); float GetMotorSpeedZ(); @@ -181,10 +181,10 @@ protected: void MotorUpdate(float aTime, float rTime); void EffectUpdate(float aTime, float rTime); void UpdateMotionStruct(float rTime, Motion &motion); - void FloorAdapt(float aTime, float rTime, Math::Vector &pos, Math::Vector &angle); - void FloorAngle(const Math::Vector &pos, Math::Vector &angle); - int ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle); - bool JostleObject(CJostleableObject* pObj, Math::Vector iPos, float iRad); + void FloorAdapt(float aTime, float rTime, glm::vec3 &pos, glm::vec3 &angle); + void FloorAngle(const glm::vec3 &pos, glm::vec3 &angle); + int ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle); + bool JostleObject(CJostleableObject* pObj, glm::vec3 iPos, float iRad); bool JostleObject(CObject* pObj, float force); bool ExploOther(ObjectType iType, CObject *pObj, ObjectType oType, float force); int ExploHimself(ObjectType iType, ObjectType oType, float force); @@ -192,7 +192,7 @@ protected: void PowerParticle(float factor, bool bBreak); void CrashParticle(float crash); void MotorParticle(float aTime, float rTime); - void WaterParticle(float aTime, Math::Vector pos, ObjectType type, float floor, float advance, float turn); + void WaterParticle(float aTime, glm::vec3 pos, ObjectType type, float floor, float advance, float turn); void WheelParticle(TraceColor color, float width); void SetFalling(); @@ -210,7 +210,7 @@ protected: float m_gravity; // force of gravity float m_time; // absolute time - Math::Vector m_motorSpeed; // motor speed (-1..1) + glm::vec3 m_motorSpeed{ 0, 0, 0 }; // motor speed (-1..1) Motion m_linMotion; // linear motion Motion m_cirMotion; // circular motion bool m_bMotor; @@ -231,7 +231,7 @@ protected: float m_lastPloufParticle; float m_lastFlameParticle; bool m_bWheelParticleBrake; - Math::Vector m_wheelParticlePos[2]; + glm::vec3 m_wheelParticlePos[2]; float m_absorbWater; float m_reactorTemperature; float m_timeReactorFail; diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index fb06bde5..d520dd91 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -574,8 +574,7 @@ void CALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) { m_eye = eye; m_lookat = lookat; - Math::Vector forward = lookat - eye; - forward.Normalize(); + Math::Vector forward = glm::normalize(lookat - eye); float orientation[] = {forward.x, forward.y, forward.z, 0.f, -1.0f, 0.0f}; alListener3f(AL_POSITION, eye.x, eye.y, eye.z); diff --git a/src/sound/sound.h b/src/sound/sound.h index dadfbd0d..df9d50e5 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -26,12 +26,9 @@ #include "sound/sound_type.h" -#include +#include "math/vector.h" -namespace Math -{ -struct Vector; -} // namespace Math +#include /*! * Maximum possible audio volume diff --git a/test/unit/math/vector_test.cpp b/test/unit/math/vector_test.cpp index bbf0385c..c999b168 100644 --- a/test/unit/math/vector_test.cpp +++ b/test/unit/math/vector_test.cpp @@ -38,7 +38,7 @@ TEST(VectorTest, LengthTest) Math::Vector vec(-1.288447945923275, 0.681452565308134, -0.633761098985957); const float expectedLength = 1.58938001708428; - EXPECT_TRUE(Math::IsEqual(vec.Length(), expectedLength, TEST_TOLERANCE)); + EXPECT_TRUE(Math::IsEqual(glm::length(vec), expectedLength, TEST_TOLERANCE)); } TEST(VectorTest, NormalizeTest) @@ -46,7 +46,7 @@ TEST(VectorTest, NormalizeTest) Math::Vector vec(1.848877241804398, -0.157262961268577, -1.963031403332377); const Math::Vector expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797); - vec.Normalize(); + vec = glm::normalize(vec); EXPECT_TRUE(Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE)); } @@ -69,7 +69,7 @@ TEST(VectorTest, CrossTest) Math::Vector expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581); Math::Vector expectedReverseCross = -expectedCross; - EXPECT_TRUE(Math::VectorsEqual(vecA.CrossMultiply(vecB), expectedCross, TEST_TOLERANCE)); + EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecA, vecB), expectedCross, TEST_TOLERANCE)); - EXPECT_TRUE(Math::VectorsEqual(vecB.CrossMultiply(vecA), expectedReverseCross, TEST_TOLERANCE)); + EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecB, vecA), expectedReverseCross, TEST_TOLERANCE)); }