From 47ad390f1d503c625d73e2dc1b5cfe07b50a0d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Wed, 29 Dec 2021 00:08:02 +0100 Subject: [PATCH] Refactored Math::Vector in CCamera, CLightManager, CLightning, CMainMovie, glutil.h and geometry.h --- src/graphics/engine/camera.cpp | 120 +++++++++++++++--------------- src/graphics/engine/lightman.cpp | 20 ++--- src/graphics/engine/lightman.h | 12 +-- src/graphics/engine/lightning.cpp | 26 +++---- src/graphics/engine/lightning.h | 6 +- src/graphics/opengl/glutil.cpp | 2 +- src/graphics/opengl/glutil.h | 2 +- src/level/mainmovie.cpp | 18 ++--- src/level/mainmovie.h | 10 +-- src/math/geometry.h | 78 +++++++++---------- 10 files changed, 147 insertions(+), 147 deletions(-) diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 7dd32e01..4d46e74f 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -90,15 +90,15 @@ CCamera::CCamera() m_initDelay = 0.0f; - m_actualEye = Math::Vector(0.0f, 0.0f, 0.0f); - m_actualLookat = Math::Vector(0.0f, 0.0f, 0.0f); - m_finalEye = Math::Vector(0.0f, 0.0f, 0.0f); - m_finalLookat = Math::Vector(0.0f, 0.0f, 0.0f); - m_prevEye = Math::Vector(0.0f, 0.0f, 0.0f); - m_prevLookat = Math::Vector(0.0f, 0.0f, 0.0f); + m_actualEye = glm::vec3(0.0f, 0.0f, 0.0f); + m_actualLookat = glm::vec3(0.0f, 0.0f, 0.0f); + m_finalEye = glm::vec3(0.0f, 0.0f, 0.0f); + m_finalLookat = glm::vec3(0.0f, 0.0f, 0.0f); + m_prevEye = glm::vec3(0.0f, 0.0f, 0.0f); + m_prevLookat = glm::vec3(0.0f, 0.0f, 0.0f); m_focus = 1.0f; - m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); + m_eyePt = glm::vec3(0.0f, 0.0f, 0.0f); m_directionH = 0.0f; m_directionV = 0.0f; m_heightEye = 40.0f; @@ -114,7 +114,7 @@ CCamera::CCamera() m_fixDirectionH = 0.0f; m_fixDirectionV = 0.0f; - m_visitGoal = Math::Vector(0.0f, 0.0f, 0.0f); + m_visitGoal = glm::vec3(0.0f, 0.0f, 0.0f); m_visitDist = 0.0f; m_visitTime = 0.0f; m_visitType = CAM_TYPE_NULL; @@ -130,10 +130,10 @@ CCamera::CCamera() m_centeringProgress = 0.0f; m_effectType = CAM_EFFECT_NULL; - m_effectPos = Math::Vector(0.0f, 0.0f, 0.0f); + m_effectPos = glm::vec3(0.0f, 0.0f, 0.0f); m_effectForce = 0.0f; m_effectProgress = 0.0f; - m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); + m_effectOffset = glm::vec3(0.0f, 0.0f, 0.0f); m_overType = CAM_OVER_EFFECT_NULL; m_overForce = 0.0f; @@ -142,8 +142,8 @@ CCamera::CCamera() m_overFadeIn = 0.0f; m_overFadeOut = 0.0f; - m_scriptEye = Math::Vector(0.0f, 0.0f, 0.0f); - m_scriptLookat = Math::Vector(0.0f, 0.0f, 0.0f); + m_scriptEye = glm::vec3(0.0f, 0.0f, 0.0f); + m_scriptLookat = glm::vec3(0.0f, 0.0f, 0.0f); m_effect = true; m_blood = true; @@ -206,7 +206,7 @@ bool CCamera::GetCameraInvertY() return m_cameraInvertY; } -void CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) +void CCamera::Init(glm::vec3 eye, glm::vec3 lookat, float delay) { m_initDelay = delay; @@ -280,7 +280,7 @@ void CCamera::SetType(CameraType type) m_engine->SetFocus(m_focus); // gives initial focus m_type = type; - Math::Vector upVec = Math::Vector(0.0f, 1.0f, 0.0f); + glm::vec3 upVec = glm::vec3(0.0f, 1.0f, 0.0f); SetViewParams(m_prevEye, m_prevLookat, upVec); return; } @@ -377,7 +377,7 @@ CameraSmooth CCamera::GetSmooth() return m_smooth; } -void CCamera::StartVisit(Math::Vector goal, float dist) +void CCamera::StartVisit(glm::vec3 goal, float dist) { m_visitType = m_type; SetType(CAM_TYPE_VISIT); @@ -392,7 +392,7 @@ void CCamera::StopVisit() SetType(m_visitType); // presents the initial type } -void CCamera::GetCamera(Math::Vector &eye, Math::Vector &lookat) +void CCamera::GetCamera(glm::vec3 &eye, glm::vec3 &lookat) { eye = m_eyePt; lookat = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); @@ -471,12 +471,12 @@ void CCamera::FlushEffect() m_effectType = CAM_EFFECT_NULL; m_effectForce = 0.0f; m_effectProgress = 0.0f; - m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); + m_effectOffset = glm::vec3(0.0f, 0.0f, 0.0f); CApplication::GetInstancePointer()->StopForceFeedbackEffect(); } -void CCamera::StartEffect(CameraEffect effect, Math::Vector pos, float force) +void CCamera::StartEffect(CameraEffect effect, glm::vec3 pos, float force) { if ( !m_effect ) return; @@ -494,7 +494,7 @@ void CCamera::EffectFrame(const Event &event) if (m_effectType == CAM_EFFECT_NULL) return; - m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); + m_effectOffset = glm::vec3(0.0f, 0.0f, 0.0f); float force = m_effectForce; @@ -593,7 +593,7 @@ void CCamera::SetOverBaseColor(Color color) m_overColorBase = color; } -void CCamera::StartOver(CameraOverEffect effect, Math::Vector pos, float force) +void CCamera::StartOver(CameraOverEffect effect, glm::vec3 pos, float force) { m_overType = effect; m_overTime = 0.0f; @@ -748,8 +748,8 @@ void CCamera::OverFrame(const Event &event) } } -void CCamera::UpdateCameraAnimation(const Math::Vector &eyePt, - const Math::Vector &lookatPt, +void CCamera::UpdateCameraAnimation(const glm::vec3 &eyePt, + const glm::vec3 &lookatPt, float rTime) { if (m_initDelay > 0.0f) @@ -796,19 +796,19 @@ void CCamera::UpdateCameraAnimation(const Math::Vector &eyePt, m_actualLookat = (m_finalLookat - m_actualLookat) / dist * prog + m_actualLookat; } - Math::Vector eye = m_effectOffset+m_actualEye; + glm::vec3 eye = m_effectOffset+m_actualEye; m_water->AdjustEye(eye); float h = m_terrain->GetFloorLevel(eye); if (eye.y < h + 4.0f) eye.y = h + 4.0f; - Math::Vector lookat = m_effectOffset+m_actualLookat; + glm::vec3 lookat = m_effectOffset+m_actualLookat; SetViewParams(eye, lookat); } -void CCamera::IsCollision(Math::Vector &eye, Math::Vector lookat) +void CCamera::IsCollision(glm::vec3 &eye, glm::vec3 lookat) { if (m_type == CAM_TYPE_BACK ) IsCollisionBack(); if (m_type == CAM_TYPE_FIX ) IsCollisionFix (eye, lookat); @@ -823,12 +823,12 @@ void CCamera::IsCollisionBack() else iType = m_cameraObj->GetType(); - Math::Vector min{}; + glm::vec3 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{}; + glm::vec3 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); @@ -869,7 +869,7 @@ void CCamera::IsCollisionBack() oType == OBJECT_WORM ) continue; Math::Sphere objSphere = obj->GetCameraCollisionSphere(); - Math::Vector oPos = objSphere.pos; + glm::vec3 oPos = objSphere.pos; float oRadius = objSphere.radius; if ( oRadius <= 2.0f ) continue; // ignores small objects @@ -880,7 +880,7 @@ void CCamera::IsCollisionBack() oPos.y-oRadius > max.y || oPos.z-oRadius > max.z ) continue; - Math::Vector proj = Math::Projection(m_actualEye, m_actualLookat, oPos); + glm::vec3 proj = Math::Projection(m_actualEye, m_actualLookat, oPos); float dpp = Math::Distance(proj, oPos); if ( dpp > oRadius ) continue; @@ -902,7 +902,7 @@ void CCamera::IsCollisionBack() } } -void CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) +void CCamera::IsCollisionFix(glm::vec3 &eye, glm::vec3 lookat) { for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { @@ -927,7 +927,7 @@ void CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) type == OBJECT_WORM ) continue; Math::Sphere objSphere = obj->GetCameraCollisionSphere(); - Math::Vector objPos = objSphere.pos; + glm::vec3 objPos = objSphere.pos; float objRadius = objSphere.radius; if (objRadius == 0.0f) 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 = Math::Projection(eye, lookat, objPos); + glm::vec3 proj = Math::Projection(eye, lookat, objPos); eye = (lookat - eye) * objRadius / dist + proj; return; } @@ -1069,7 +1069,7 @@ bool CCamera::EventProcess(const Event &event) bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) { - Math::Vector cameraMove = CalculateCameraMovement(event, keysAllowed); + glm::vec3 cameraMove = CalculateCameraMovement(event, keysAllowed); float factor = m_heightEye * 0.5f + 30.0f; bool secondary = m_input->GetKeyState(INPUT_SLOT_CAM_ALT) || event.mouseButtonsState & MOUSE_BUTTON_MIDDLE; // TODO: make mouse button a keybinding @@ -1104,7 +1104,7 @@ bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) { m_eyePt.y += m_heightEye; - Math::Vector pos = m_eyePt; + glm::vec3 pos = m_eyePt; if (m_terrain->AdjustToFloor(pos, true)) { pos.y -= 2.0f; @@ -1114,7 +1114,7 @@ bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) } - Math::Vector lookatPt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); + glm::vec3 lookatPt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); if (m_terrain->AdjustToFloor(lookatPt, true)) lookatPt.y += m_heightLookat; @@ -1126,7 +1126,7 @@ bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) bool CCamera::EventFrameBack(const Event &event) { - Math::Vector cameraMove = CalculateCameraMovement(event); + glm::vec3 cameraMove = CalculateCameraMovement(event); m_addDirectionH += cameraMove.x; m_addDirectionV += cameraMove.y; m_backDist += cameraMove.z; @@ -1178,7 +1178,7 @@ bool CCamera::EventFrameBack(const Event &event) { ObjectType type = m_cameraObj->GetType(); - Math::Vector lookatPt = m_cameraObj->GetPosition(); + glm::vec3 lookatPt = m_cameraObj->GetPosition(); if (type == OBJECT_BASE ) lookatPt.y += 40.0f; else if (type == OBJECT_HUMAN) lookatPt.y += 1.0f; else if (type == OBJECT_TECH ) lookatPt.y += 1.0f; @@ -1237,7 +1237,7 @@ bool CCamera::EventFrameBack(const Event &event) ground = dynamic_cast(*m_cameraObj).GetPhysics()->GetLand(); if ( ground ) // ground? { - Math::Vector pos = lookatPt + (lookatPt - m_eyePt); + glm::vec3 pos = lookatPt + (lookatPt - m_eyePt); float floor = m_terrain->GetHeightToFloor(pos) - 4.0f; if (floor > 0.0f) m_eyePt.y += floor; // shows the descent in front @@ -1257,7 +1257,7 @@ bool CCamera::EventFrameBack(const Event &event) bool CCamera::EventFrameFix(const Event &event) { - Math::Vector cameraMove = CalculateCameraMovement(event); + glm::vec3 cameraMove = CalculateCameraMovement(event); m_fixDirectionH += cameraMove.x; m_fixDirectionV += cameraMove.y; m_fixDist += cameraMove.z; @@ -1269,7 +1269,7 @@ bool CCamera::EventFrameFix(const Event &event) if (m_cameraObj != nullptr) { - Math::Vector lookatPt = m_cameraObj->GetPosition(); + glm::vec3 lookatPt = m_cameraObj->GetPosition(); float h = m_fixDirectionH; float v = m_fixDirectionV; @@ -1291,7 +1291,7 @@ bool CCamera::EventFrameFix(const Event &event) bool CCamera::EventFrameExplo(const Event &event) { - Math::Vector cameraMove = CalculateCameraMovement(event); + glm::vec3 cameraMove = CalculateCameraMovement(event); m_directionH += cameraMove.x; m_directionH = Math::NormAngle(m_directionH); @@ -1301,7 +1301,7 @@ bool CCamera::EventFrameExplo(const Event &event) { m_eyePt.y += m_heightEye; - Math::Vector pos = m_eyePt; + glm::vec3 pos = m_eyePt; if ( m_terrain->AdjustToFloor(pos, false) ) { pos.y += 2.0f; @@ -1311,7 +1311,7 @@ bool CCamera::EventFrameExplo(const Event &event) } - Math::Vector lookatPt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); + glm::vec3 lookatPt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); if (m_terrain->AdjustToFloor(lookatPt, true)) lookatPt.y += m_heightLookat; @@ -1326,10 +1326,10 @@ bool CCamera::EventFrameOnBoard(const Event &event) if (m_cameraObj != nullptr) { assert(m_cameraObj->Implements(ObjectInterfaceType::Controllable)); - Math::Vector lookatPt, upVec; + glm::vec3 lookatPt, upVec; dynamic_cast(*m_cameraObj).AdjustCamera(m_eyePt, m_directionH, m_directionV, lookatPt, upVec, m_type); - Math::Vector eye = m_effectOffset * 0.3f + m_eyePt; - Math::Vector lookat = m_effectOffset * 0.3f + lookatPt; + glm::vec3 eye = m_effectOffset * 0.3f + m_eyePt; + glm::vec3 lookat = m_effectOffset * 0.3f + lookatPt; SetViewParams(eye, lookat, upVec); m_actualEye = eye; @@ -1342,7 +1342,7 @@ bool CCamera::EventFrameVisit(const Event &event) { m_visitTime += event.rTime; - Math::Vector cameraMove = CalculateCameraMovement(event); + glm::vec3 cameraMove = CalculateCameraMovement(event); // ZoomIn/ZoomOut m_visitDist += cameraMove.z; @@ -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 = Math::RotateView(m_visitGoal, angleH, angleV, m_visitDist); + glm::vec3 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); @@ -1369,17 +1369,17 @@ bool CCamera::EventFrameScript(const Event &event) return true; } -void CCamera::SetScriptCameraAnimateEye(Math::Vector eye) +void CCamera::SetScriptCameraAnimateEye(glm::vec3 eye) { m_scriptEye = eye; } -void CCamera::SetScriptCameraAnimateLookat(Math::Vector lookat) +void CCamera::SetScriptCameraAnimateLookat(glm::vec3 lookat) { m_scriptLookat = lookat; } -void CCamera::SetScriptCamera(Math::Vector eye, Math::Vector lookat) +void CCamera::SetScriptCamera(glm::vec3 eye, glm::vec3 lookat) { SetScriptCameraAnimate(eye, lookat); @@ -1388,14 +1388,14 @@ void CCamera::SetScriptCamera(Math::Vector eye, Math::Vector lookat) m_actualLookat = m_finalLookat = m_scriptLookat; } -void CCamera::SetScriptCameraAnimate(Math::Vector eye, Math::Vector lookat) +void CCamera::SetScriptCameraAnimate(glm::vec3 eye, glm::vec3 lookat) { m_scriptEye = eye; m_scriptLookat = lookat; } -void CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, - const Math::Vector &up) +void CCamera::SetViewParams(const glm::vec3 &eye, const glm::vec3 &lookat, + const glm::vec3 &up) { m_engine->SetViewParams(eye, lookat, up); @@ -1403,10 +1403,10 @@ void CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, m_engine->SetRankView(under ? 1 : 0); } -Math::Vector CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat, +glm::vec3 CCamera::ExcludeTerrain(glm::vec3 eye, glm::vec3 lookat, float &angleH, float &angleV) { - Math::Vector pos = eye; + glm::vec3 pos = eye; if (m_terrain->AdjustToFloor(pos)) { float dist = Math::DistanceProjected(lookat, pos); @@ -1420,7 +1420,7 @@ Math::Vector CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat, return eye; } -Math::Vector CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, +glm::vec3 CCamera::ExcludeObject(glm::vec3 eye, glm::vec3 lookat, float &angleH, float &angleV) { return eye; @@ -1434,7 +1434,7 @@ Math::Vector CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, break; int j = 0; - Math::Vector oPos; + glm::vec3 oPos; float oRad; while (obj->GetCrashSphere(j++, oPos, oRad)) { @@ -1452,9 +1452,9 @@ void CCamera::SetCameraSpeed(float speed) m_speed = speed; } -Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllowed) +glm::vec3 CCamera::CalculateCameraMovement(const Event &event, bool keysAllowed) { - Math::Vector delta{}; + glm::vec3 delta{}; delta.x += m_mouseDelta.x * 2*Math::PI; delta.y -= m_mouseDelta.y * Math::PI; diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 2021f274..d63d85d0 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -177,8 +177,8 @@ int CLightManager::CreateLight(LightPriority priority) m_dynLights[index].light.type = LIGHT_DIRECTIONAL; m_dynLights[index].light.diffuse = Color(0.5f, 0.5f, 0.5f); m_dynLights[index].light.ambient = Color(0.0f, 0.0f, 0.0f); - m_dynLights[index].light.position = Math::Vector(-100.0f, 100.0f, -100.0f); - m_dynLights[index].light.direction = Math::Vector( 1.0f, -1.0f, 1.0f); + m_dynLights[index].light.position = glm::vec3(-100.0f, 100.0f, -100.0f); + m_dynLights[index].light.direction = glm::vec3( 1.0f, -1.0f, 1.0f); m_dynLights[index].intensity.Init(1.0f); // maximum m_dynLights[index].colorRed.Init(0.5f); @@ -256,7 +256,7 @@ bool CLightManager::SetLightExcludeType(int lightRank, EngineObjectType type) return true; } -bool CLightManager::SetLightPos(int lightRank, const Math::Vector &pos) +bool CLightManager::SetLightPos(int lightRank, const glm::vec3 &pos) { if ( (lightRank < 0) || (lightRank >= static_cast( m_dynLights.size() )) ) return false; @@ -265,15 +265,15 @@ bool CLightManager::SetLightPos(int lightRank, const Math::Vector &pos) return true; } -Math::Vector CLightManager::GetLightPos(int lightRank) +glm::vec3 CLightManager::GetLightPos(int lightRank) { if ( (lightRank < 0) || (lightRank >= static_cast( m_dynLights.size() )) ) - return Math::Vector(0.0f, 0.0f, 0.0f); + return glm::vec3(0.0f, 0.0f, 0.0f); return m_dynLights[lightRank].light.position; } -bool CLightManager::SetLightDir(int lightRank, const Math::Vector &dir) +bool CLightManager::SetLightDir(int lightRank, const glm::vec3 &dir) { if ( (lightRank < 0) || (lightRank >= static_cast( m_dynLights.size() )) ) return false; @@ -282,10 +282,10 @@ bool CLightManager::SetLightDir(int lightRank, const Math::Vector &dir) return true; } -Math::Vector CLightManager::GetLightDir(int lightRank) +glm::vec3 CLightManager::GetLightDir(int lightRank) { if ( (lightRank < 0) || (lightRank >= static_cast( m_dynLights.size() )) ) - return Math::Vector(0.0f, 0.0f, 0.0f); + return glm::vec3(0.0f, 0.0f, 0.0f); return m_dynLights[lightRank].light.direction; } @@ -401,7 +401,7 @@ void CLightManager::UpdateProgression(float rTime) if (m_dynLights[i].includeType == ENG_OBJTYPE_METAL) { - Math::Vector dir = m_engine->GetEyePt() - m_engine->GetLookatPt(); + glm::vec3 dir = m_engine->GetEyePt() - m_engine->GetLookatPt(); float angle = Math::RotateAngle(dir.x, dir.z); angle += Math::PI * 0.5f * i; m_dynLights[i].light.direction.x = sinf(2.0f * angle); @@ -496,7 +496,7 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) // ----------- -CLightManager::CLightsComparator::CLightsComparator(Math::Vector eyePos, EngineObjectType objectType) +CLightManager::CLightsComparator::CLightsComparator(glm::vec3 eyePos, EngineObjectType objectType) { m_eyePos = eyePos; m_objectType = objectType; diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 4fab7e99..2dd7e3e7 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -178,14 +178,14 @@ public: bool SetLightExcludeType(int lightRank, EngineObjectType type); //! Sets the position of dynamic light - bool SetLightPos(int lightRank, const Math::Vector &pos); + bool SetLightPos(int lightRank, const glm::vec3 &pos); //! Returns the position of dynamic light - Math::Vector GetLightPos(int lightRank); + glm::vec3 GetLightPos(int lightRank); //! Sets the direction of dynamic light - bool SetLightDir(int lightRank, const Math::Vector &dir); + bool SetLightDir(int lightRank, const glm::vec3 &dir); //! Returns the direction of dynamic light - Math::Vector GetLightDir(int lightRank); + glm::vec3 GetLightDir(int lightRank); //! Sets the destination intensity for dynamic light's intensity progression bool SetLightIntensity(int lightRank, float value); @@ -215,14 +215,14 @@ protected: class CLightsComparator { public: - CLightsComparator(Math::Vector eyePos, EngineObjectType objectType); + CLightsComparator(glm::vec3 eyePos, EngineObjectType objectType); bool operator()(const DynamicLight& left, const DynamicLight& right); private: float GetLightWeight(const DynamicLight& dynLight); - Math::Vector m_eyePos; + glm::vec3 m_eyePos = { 0, 0, 0 }; EngineObjectType m_objectType; }; diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index 49e76f9b..8d634914 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -236,22 +236,22 @@ void CLightning::Draw() texSup.x = 95.5f/256.0f; texSup.y = 34.0f/256.0f; // blank - Math::Vector p1 = m_pos; - Math::Vector eye = m_engine->GetEyePt(); + glm::vec3 p1 = m_pos; + glm::vec3 eye = m_engine->GetEyePt(); float a = Math::RotateAngle(eye.x-p1.x, eye.z-p1.z); - Math::Vector n = Math::Normalize(p1-eye); + glm::vec3 n = Math::Normalize(p1-eye); - Math::Vector corner[4]; + glm::vec3 corner[4]; Vertex vertex[4]; for (std::size_t i = 0; i < m_segments.size() - 1; i++) { - Math::Vector p2 = p1; + glm::vec3 p2 = p1; p2.y += 8.0f+0.2f*i; glm::vec2 rot; - Math::Vector p = p1; + glm::vec3 p = p1; p.x += m_segments[i].width; rot = Math::RotatePoint({ p1.x, p1.z }, a + Math::PI / 2.0f, { p.x, p.z }); corner[0].x = rot.x+m_segments[i].shift.x; @@ -295,12 +295,12 @@ void CLightning::Draw() } } -CObject* CLightning::SearchObject(Math::Vector pos) +CObject* CLightning::SearchObject(glm::vec3 pos) { // Lightning conductors std::vector paraObj; paraObj.reserve(100); - std::vector paraObjPos; + std::vector paraObjPos; paraObjPos.reserve(100); // Seeking the object closest to the point of impact of lightning. @@ -326,7 +326,7 @@ CObject* CLightning::SearchObject(Math::Vector pos) float detect = m_magnetic * dynamic_cast(*obj).GetLightningHitProbability(); if (detect == 0.0f) continue; - Math::Vector oPos = obj->GetPosition(); + glm::vec3 oPos = obj->GetPosition(); float dist = Math::DistanceProjected(oPos, pos); if (dist > detect) continue; if (dist < min) @@ -340,7 +340,7 @@ CObject* CLightning::SearchObject(Math::Vector pos) return nullptr; // nothing found // Under the protection of a lightning conductor? - Math::Vector oPos = bestObj->GetPosition(); + glm::vec3 oPos = bestObj->GetPosition(); for (int i = paraObj.size()-1; i >= 0; i--) { float dist = Math::DistanceProjected(oPos, paraObjPos[i]); @@ -352,17 +352,17 @@ CObject* CLightning::SearchObject(Math::Vector pos) } -void CLightning::StrikeAtPos(Math::Vector pos) +void CLightning::StrikeAtPos(glm::vec3 pos) { m_pos = pos; - Math::Vector eye = m_engine->GetEyePt(); + glm::vec3 eye = m_engine->GetEyePt(); float dist = Math::Distance(m_pos, eye); float deep = m_engine->GetDeepView(); if (dist < deep) { - Math::Vector pos = eye+((m_pos-eye)*0.2f); // like so close! + glm::vec3 pos = eye+((m_pos-eye)*0.2f); // like so close! m_sound->Play(SOUND_BLITZ, pos); m_camera->StartOver(CAM_OVER_EFFECT_LIGHTNING, m_pos, 1.0f); diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index 02191f48..e3c078aa 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -77,13 +77,13 @@ public: void Draw(); //! Shoots lightning strike at given position - void StrikeAtPos(Math::Vector pos); + void StrikeAtPos(glm::vec3 pos); protected: //! Updates lightning bool EventFrame(const Event &event); //! Seeks for the object closest to the lightning - CObject* SearchObject(Math::Vector pos); + CObject* SearchObject(glm::vec3 pos); protected: CEngine* m_engine = nullptr; @@ -98,7 +98,7 @@ protected: float m_speed = 0.0f; float m_progress = 0.0f; - Math::Vector m_pos; + glm::vec3 m_pos = { 0, 0, 0 }; enum class LightningPhase { diff --git a/src/graphics/opengl/glutil.cpp b/src/graphics/opengl/glutil.cpp index 0edfb838..72583ca7 100644 --- a/src/graphics/opengl/glutil.cpp +++ b/src/graphics/opengl/glutil.cpp @@ -413,7 +413,7 @@ GLenum TranslateGfxBlendFunc(BlendFunc func) return 0; } -bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius) +bool InPlane(glm::vec3 normal, float originPlane, glm::vec3 center, float radius) { float distance = originPlane + Math::DotProduct(normal, center); diff --git a/src/graphics/opengl/glutil.h b/src/graphics/opengl/glutil.h index 37c29acb..3460bf56 100644 --- a/src/graphics/opengl/glutil.h +++ b/src/graphics/opengl/glutil.h @@ -88,7 +88,7 @@ BlendFunc TranslateGLBlendFunc(GLenum flag); GLenum TranslateGfxBlendFunc(BlendFunc func); -bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius); +bool InPlane(glm::vec3 normal, float originPlane, glm::vec3 center, float radius); GLenum TranslateTextureCoordinate(int index); diff --git a/src/level/mainmovie.cpp b/src/level/mainmovie.cpp index 27339766..9affecff 100644 --- a/src/level/mainmovie.cpp +++ b/src/level/mainmovie.cpp @@ -73,7 +73,7 @@ void CMainMovie::Flush() bool CMainMovie::Start(MainMovieType type, float time) { Math::Matrix* mat; - Math::Vector pos; + glm::vec3 pos{ 0, 0, 0 }; CObject* pObj; m_type = type; @@ -98,10 +98,10 @@ bool CMainMovie::Start(MainMovieType type, float time) m_camera->SetScriptCamera(m_initialEye, m_initialLookat); mat = pObj->GetWorldMatrix(0); - m_finalLookat[0] = Math::Transform(*mat, Math::Vector( 1.6f, 1.0f, 1.2f)); - m_finalEye[0] = Math::Transform(*mat, Math::Vector(-1.5f, 5.0f, 3.0f)); - m_finalLookat[1] = Math::Transform(*mat, Math::Vector( 1.6f, 1.0f, 1.2f)); - m_finalEye[1] = Math::Transform(*mat, Math::Vector( 0.8f, 3.0f, 0.8f)); + m_finalLookat[0] = Math::Transform(*mat, glm::vec3( 1.6f, 1.0f, 1.2f)); + m_finalEye[0] = Math::Transform(*mat, glm::vec3(-1.5f, 5.0f, 3.0f)); + m_finalLookat[1] = Math::Transform(*mat, glm::vec3( 1.6f, 1.0f, 1.2f)); + m_finalEye[1] = Math::Transform(*mat, glm::vec3( 0.8f, 3.0f, 0.8f)); } if ( m_type == MM_SATCOMclose ) @@ -152,9 +152,6 @@ bool CMainMovie::IsExist() bool CMainMovie::EventProcess(const Event &event) { - Math::Vector initialEye, initialLookat, finalEye, finalLookat, eye, lookat; - float progress; - if ( m_type == MM_NONE ) return true; m_progress += event.rTime*m_speed; @@ -163,7 +160,10 @@ bool CMainMovie::EventProcess(const Event &event) { if ( m_progress < 1.0f ) { - progress = 1.0f-powf(1.0f-m_progress, 3.0f); + glm::vec3 initialEye, initialLookat; + glm::vec3 finalEye, finalLookat, eye, lookat; + + float progress = 1.0f-powf(1.0f-m_progress, 3.0f); if ( progress < 0.6f ) { diff --git a/src/level/mainmovie.h b/src/level/mainmovie.h index 0f8e9e06..4bb72a4a 100644 --- a/src/level/mainmovie.h +++ b/src/level/mainmovie.h @@ -24,7 +24,7 @@ #pragma once -#include "math/vector.h" +#include class CRobotMain; @@ -70,9 +70,9 @@ protected: MainMovieType m_stopType; float m_speed; float m_progress; - Math::Vector m_initialEye; - Math::Vector m_initialLookat; - Math::Vector m_finalEye[2]; - Math::Vector m_finalLookat[2]; + glm::vec3 m_initialEye; + glm::vec3 m_initialLookat; + glm::vec3 m_finalEye[2]; + glm::vec3 m_finalLookat[2]; }; diff --git a/src/math/geometry.h b/src/math/geometry.h index 183298c4..c0b0b2e3 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -156,13 +156,13 @@ inline void RotatePoint(float cx, float cy, float angle, float &px, float &py) * \param angleH,angleV rotation angles [radians] (positive is CCW) * \param p the point to be rotated */ -inline void RotatePoint(const Math::Vector ¢er, float angleH, float angleV, Math::Vector &p) +inline void RotatePoint(const glm::vec3 ¢er, float angleH, float angleV, glm::vec3 &p) { p.x -= center.x; p.y -= center.y; p.z -= center.z; - Math::Vector b; + glm::vec3 b{}; b.x = p.x*cosf(angleH) - p.z*sinf(angleH); b.y = p.z*sinf(angleV) + p.y*cosf(angleV); b.z = p.x*sinf(angleH) + p.z*cosf(angleH); @@ -178,18 +178,18 @@ inline void RotatePoint(const Math::Vector ¢er, float angleH, float angleV, * \param angleH,angleV rotation angles [radians] (positive is CCW) * \param p the point to be rotated */ -inline void RotatePoint2(const Math::Vector center, float angleH, float angleV, Math::Vector &p) +inline void RotatePoint2(const glm::vec3 center, float angleH, float angleV, glm::vec3 &p) { p.x -= center.x; p.y -= center.y; p.z -= center.z; - Math::Vector a; + glm::vec3 a{}; a.x = p.x*cosf(angleH) - p.z*sinf(angleH); a.y = p.y; a.z = p.x*sinf(angleH) + p.z*cosf(angleH); - Math::Vector b; + glm::vec3 b{}; b.x = a.x; b.y = a.z*sinf(angleV) + a.y*cosf(angleV); b.z = a.z*cosf(angleV) - a.y*sinf(angleV); @@ -264,12 +264,12 @@ inline float RotateAngle(const glm::vec2¢er, const glm::vec2&p1, const glm:: * \param at view direction * \param worldUp up vector */ -inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from, - const Math::Vector &at, const Math::Vector &worldUp) +inline void LoadViewMatrix(Math::Matrix &mat, const glm::vec3 &from, + const glm::vec3 &at, const glm::vec3 &worldUp) { // Get the z basis vector, which points straight ahead. This is the // difference from the eyepoint to the lookat point. - Math::Vector view = at - from; + glm::vec3 view = at - from; float length = glm::length(view); assert(! IsZero(length) ); @@ -281,18 +281,18 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from, // vector onto the up vector. The projection is the y basis vector. float dotProduct = DotProduct(worldUp, view); - Math::Vector up = worldUp - dotProduct * view; + glm::vec3 up = worldUp - dotProduct * view; // 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 = glm::length(up)) ) { - up = Math::Vector(0.0f, 1.0f, 0.0f) - view.y * view; + up = glm::vec3(0.0f, 1.0f, 0.0f) - view.y * view; // If we still have near-zero length, resort to a different axis. if ( IsZero(length = glm::length(up)) ) { - up = Math::Vector(0.0f, 0.0f, 1.0f) - view.z * view; + up = glm::vec3(0.0f, 0.0f, 1.0f) - view.z * view; assert(! IsZero(glm::length(up)) ); } @@ -303,7 +303,7 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from, // The x basis vector is found simply with the cross product of the y // and z basis vectors - Math::Vector right = CrossProduct(up, view); + glm::vec3 right = CrossProduct(up, view); // Start building the matrix. The first three rows contains the basis // vectors used to rotate the view to point at the lookat point @@ -376,7 +376,7 @@ inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right * \param mat result matrix * \param trans vector of translation */ -inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans) +inline void LoadTranslationMatrix(Math::Matrix &mat, const glm::vec3 &trans) { mat.LoadIdentity(); /* (1,4) */ mat.m[12] = trans.x; @@ -389,7 +389,7 @@ inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans) * \param mat result matrix * \param scale vector with scaling factors for X, Y, Z */ -inline void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale) +inline void LoadScaleMatrix(Math::Matrix &mat, const glm::vec3 &scale) { mat.LoadIdentity(); /* (1,1) */ mat.m[0 ] = scale.x; @@ -445,11 +445,11 @@ inline void LoadRotationZMatrix(Math::Matrix &mat, float angle) * \param dir axis of rotation * \param angle angle [radians] */ -inline void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float angle) +inline void LoadRotationMatrix(Math::Matrix &mat, const glm::vec3 &dir, float angle) { float cos = cosf(angle); float sin = sinf(angle); - Math::Vector v = Normalize(dir); + glm::vec3 v = Normalize(dir); mat.LoadIdentity(); @@ -467,7 +467,7 @@ inline void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float } //! Calculates the matrix to make three rotations in the order X, Z and Y -inline void LoadRotationXZYMatrix(Math::Matrix &mat, const Math::Vector &angles) +inline void LoadRotationXZYMatrix(Math::Matrix &mat, const glm::vec3 &angles) { Math::Matrix temp; LoadRotationXMatrix(temp, angles.x); @@ -480,7 +480,7 @@ inline void LoadRotationXZYMatrix(Math::Matrix &mat, const Math::Vector &angles) } //! Calculates the matrix to make three rotations in the order Z, X and Y -inline void LoadRotationZXYMatrix(Math::Matrix &mat, const Math::Vector &angles) +inline void LoadRotationZXYMatrix(Math::Matrix &mat, const glm::vec3 &angles) { Math::Matrix temp; LoadRotationZMatrix(temp, angles.z); @@ -493,7 +493,7 @@ inline void LoadRotationZXYMatrix(Math::Matrix &mat, const Math::Vector &angles) } //! Returns the distance between projections on XZ plane of two vectors -inline float DistanceProjected(const Math::Vector &a, const Math::Vector &b) +inline float DistanceProjected(const glm::vec3 &a, const glm::vec3 &b) { return sqrtf( (a.x-b.x)*(a.x-b.x) + (a.z-b.z)*(a.z-b.z) ); @@ -503,10 +503,10 @@ inline float DistanceProjected(const Math::Vector &a, const Math::Vector &b) /** * \param p1,p2,p3 points defining the plane */ -inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3) +inline glm::vec3 NormalToPlane(const glm::vec3 &p1, const glm::vec3 &p2, const glm::vec3 &p3) { - Math::Vector u = p3 - p1; - Math::Vector v = p2 - p1; + glm::vec3 u = p3 - p1; + glm::vec3 v = p2 - p1; return Normalize(CrossProduct(u, v)); } @@ -516,9 +516,9 @@ inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2 * \param p1,p2 line start and end * \param dist scaling factor from \a p1, relative to distance between \a p1 and \a p2 */ -inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist) +inline glm::vec3 SegmentPoint(const glm::vec3 &p1, const glm::vec3 &p2, float dist) { - Math::Vector direction = glm::normalize(p2 - p1); + glm::vec3 direction = glm::normalize(p2 - p1); return p1 + direction * dist; } @@ -528,10 +528,10 @@ inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, * \param p the point * \param a,b,c points defining the plane */ -inline float DistanceToPlane(const Math::Vector &a, const Math::Vector &b, - const Math::Vector &c, const Math::Vector &p) +inline float DistanceToPlane(const glm::vec3 &a, const glm::vec3 &b, + const glm::vec3 &c, const glm::vec3 &p) { - Math::Vector n = NormalToPlane(a, b, c); + glm::vec3 n = NormalToPlane(a, b, c); float d = -(n.x*a.x + n.y*a.y + n.z*a.z); return fabs(n.x*p.x + n.y*p.y + n.z*p.z + d); @@ -542,10 +542,10 @@ inline float DistanceToPlane(const Math::Vector &a, const Math::Vector &b, * \param plane1 array of three vectors defining the first plane * \param plane2 array of three vectors defining the second plane */ -inline bool IsSamePlane(const Math::Vector (&plane1)[3], const Math::Vector (&plane2)[3]) +inline bool IsSamePlane(const glm::vec3 (&plane1)[3], const glm::vec3 (&plane2)[3]) { - Math::Vector n1 = NormalToPlane(plane1[0], plane1[1], plane1[2]); - Math::Vector n2 = NormalToPlane(plane2[0], plane2[1], plane2[2]); + glm::vec3 n1 = NormalToPlane(plane1[0], plane1[1], plane1[2]); + glm::vec3 n2 = NormalToPlane(plane2[0], plane2[1], plane2[2]); if ( fabs(n1.x-n2.x) > 0.1f || fabs(n1.y-n2.y) > 0.1f || @@ -560,8 +560,8 @@ inline bool IsSamePlane(const Math::Vector (&plane1)[3], const Math::Vector (&pl } //! Calculates the intersection "i" right "of" the plane "abc" (TODO: ?) -inline bool Intersect(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, - const Math::Vector &d, const Math::Vector &e, Math::Vector &i) +inline bool Intersect(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, + const glm::vec3 &d, const glm::vec3 &e, glm::vec3 &i) { float d1 = (d.x-a.x)*((b.y-a.y)*(c.z-a.z)-(c.y-a.y)*(b.z-a.z)) - (d.y-a.y)*((b.x-a.x)*(c.z-a.z)-(c.x-a.x)*(b.z-a.z)) + @@ -583,7 +583,7 @@ inline bool Intersect(const Math::Vector &a, const Math::Vector &b, const Math:: //! Calculates the intersection of the straight line passing through p (x, z) /** Line is parallel to the y axis, with the plane abc. Returns p.y. (TODO: ?) */ -inline bool IntersectY(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, Math::Vector &p) +inline bool IntersectY(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, glm::vec3 &p) { float d = (b.x-a.x)*(c.z-a.z) - (c.x-a.x)*(b.z-a.z); float d1 = (p.x-a.x)*(c.z-a.z) - (c.x-a.x)*(p.z-a.z); @@ -598,9 +598,9 @@ inline bool IntersectY(const Math::Vector &a, const Math::Vector &b, const Math: } //! Calculates the end point -inline Math::Vector LookatPoint(const Math::Vector &eye, float angleH, float angleV, float length) +inline glm::vec3 LookatPoint(const glm::vec3 &eye, float angleH, float angleV, float length) { - Math::Vector lookat = eye; + glm::vec3 lookat = eye; lookat.z += length; RotatePoint(eye, angleH, angleV, lookat); @@ -610,7 +610,7 @@ inline Math::Vector LookatPoint(const Math::Vector &eye, float angleH, float ang //! Transforms the point \a p by matrix \a m /** Is equal to multiplying the matrix by the vector (of course without perspective divide). */ -inline Math::Vector Transform(const Math::Matrix &m, const Math::Vector &p) +inline glm::vec3 Transform(const Math::Matrix &m, const glm::vec3 &p) { return MatrixVectorMultiply(m, p); } @@ -620,7 +620,7 @@ inline Math::Vector Transform(const Math::Matrix &m, const Math::Vector &p) * \param p point to project * \param a,b two ends of the line */ -inline Math::Vector Projection(const Math::Vector &a, const Math::Vector &b, const Math::Vector &p) +inline glm::vec3 Projection(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &p) { float k = DotProduct(b - a, p - a); k /= DotProduct(b - a, b - a); @@ -629,7 +629,7 @@ inline Math::Vector Projection(const Math::Vector &a, const Math::Vector &b, con } //! Calculates point of view to look at a center two angles and a distance -inline Math::Vector RotateView(Math::Vector center, float angleH, float angleV, float dist) +inline glm::vec3 RotateView(glm::vec3 center, float angleH, float angleV, float dist) { Math::Matrix mat1, mat2; LoadRotationZMatrix(mat1, -angleV); @@ -637,7 +637,7 @@ inline Math::Vector RotateView(Math::Vector center, float angleH, float angleV, Math::Matrix mat = MultiplyMatrices(mat2, mat1); - Math::Vector eye; + glm::vec3 eye{}; eye.x = 0.0f+dist; eye.y = 0.0f; eye.z = 0.0f;