From 6277e10b3f69c348a146b4ab6dfd62f98ca088f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Wed, 29 Dec 2021 01:55:48 +0100 Subject: [PATCH] Refactored Math::Vector in CParticle, CPlanet, CPyro, CTerrain, CText, CWater, ModelInput and few structures --- src/graphics/engine/particle.cpp | 175 ++++++++++++------------ src/graphics/engine/particle.h | 40 +++--- src/graphics/engine/planet.cpp | 10 +- src/graphics/engine/pyro.cpp | 160 +++++++++++----------- src/graphics/engine/pyro.h | 16 +-- src/graphics/engine/terrain.cpp | 118 ++++++++-------- src/graphics/engine/terrain.h | 56 ++++---- src/graphics/engine/text.cpp | 8 +- src/graphics/engine/water.cpp | 58 ++++---- src/graphics/engine/water.h | 12 +- src/graphics/model/model_crash_sphere.h | 6 +- src/graphics/model/model_input.cpp | 6 +- src/graphics/model/model_io_structs.h | 6 +- 13 files changed, 333 insertions(+), 338 deletions(-) diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 6cd1de85..9be23b20 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -175,7 +175,7 @@ static char RandomLetter() } /** Returns the channel of the particle created or -1 on error. */ -int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, const glm::vec2& dim, +int CParticle::CreateParticle(glm::vec3 pos, glm::vec3 speed, const glm::vec2& dim, ParticleType type, float duration, float mass, float windSensitivity, int sheet) @@ -355,7 +355,7 @@ int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, const glm::v } /** Returns the channel of the particle created or -1 on error */ -int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, +int CParticle::CreateFrag(glm::vec3 pos, glm::vec3 speed, EngineTriangle *triangle, ParticleType type, float duration, float mass, @@ -398,17 +398,17 @@ int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, m_totalInterface[t][sheet] ++; - Math::Vector p1; + glm::vec3 p1; p1.x = m_triangle[i].triangle[0].position.x; p1.y = m_triangle[i].triangle[0].position.y; p1.z = m_triangle[i].triangle[0].position.z; - Math::Vector p2; + glm::vec3 p2; p2.x = m_triangle[i].triangle[1].position.x; p2.y = m_triangle[i].triangle[1].position.y; p2.z = m_triangle[i].triangle[1].position.z; - Math::Vector p3; + glm::vec3 p3; p3.x = m_triangle[i].triangle[2].position.x; p3.y = m_triangle[i].triangle[2].position.y; p3.z = m_triangle[i].triangle[2].position.z; @@ -418,9 +418,9 @@ int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, float l3 = Math::Distance(p3, p1); float dx = fabs(Math::Min(l1, l2, l3))*0.5f; float dy = fabs(Math::Max(l1, l2, l3))*0.5f; - p1 = Math::Vector(-dx, dy, 0.0f); - p2 = Math::Vector( dx, dy, 0.0f); - p3 = Math::Vector(-dx, -dy, 0.0f); + p1 = glm::vec3(-dx, dy, 0.0f); + p2 = glm::vec3( dx, dy, 0.0f); + p3 = glm::vec3(-dx, -dy, 0.0f); m_triangle[i].triangle[0].position.x = p1.x; m_triangle[i].triangle[0].position.y = p1.y; @@ -434,7 +434,7 @@ int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, m_triangle[i].triangle[2].position.y = p3.y; m_triangle[i].triangle[2].position.z = p3.z; - Math::Vector n(0.0f, 0.0f, -1.0f); + glm::vec3 n(0.0f, 0.0f, -1.0f); m_triangle[i].triangle[0].normal.x = n.x; m_triangle[i].triangle[0].normal.y = n.y; @@ -460,7 +460,7 @@ int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, /** Returns the channel of the particle created or -1 on error */ -int CParticle::CreatePart(Math::Vector pos, Math::Vector speed, +int CParticle::CreatePart(glm::vec3 pos, glm::vec3 speed, ParticleType type, float duration, float mass, float weight, float windSensitivity, int sheet) @@ -508,7 +508,7 @@ int CParticle::CreatePart(Math::Vector pos, Math::Vector speed, } /** Returns the channel of the particle created or -1 on error */ -int CParticle::CreateRay(Math::Vector pos, Math::Vector goal, +int CParticle::CreateRay(glm::vec3 pos, glm::vec3 goal, ParticleType type, const glm::vec2& dim, float duration, int sheet) { @@ -537,7 +537,7 @@ int CParticle::CreateRay(Math::Vector pos, Math::Vector goal, m_particle[i].duration = duration; m_particle[i].pos = pos; m_particle[i].goal = goal; - m_particle[i].speed = Math::Vector(0.0f, 0.0f, 0.0f); + m_particle[i].speed = glm::vec3(0.0f, 0.0f, 0.0f); m_particle[i].windSensitivity = 0.0f; m_particle[i].dim = dim; m_particle[i].zoom = 1.0f; @@ -566,7 +566,7 @@ int CParticle::CreateRay(Math::Vector pos, Math::Vector goal, } /** "length" is the length of the tail of drag (in seconds)! */ -int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, const glm::vec2& dim, +int CParticle::CreateTrack(glm::vec3 pos, glm::vec3 speed, const glm::vec2& dim, ParticleType type, float duration, float mass, float length, float width) { @@ -598,8 +598,8 @@ int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, const glm::vec2 return channel; } -void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, - const Math::Vector &p3, const Math::Vector &p4, +void CParticle::CreateWheelTrace(const glm::vec3 &p1, const glm::vec3 &p2, + const glm::vec3 &p3, const glm::vec3 &p4, TraceColor color) { int max = MAXWHEELTRACE; @@ -708,7 +708,7 @@ void CParticle::SetObjectFather(int channel, CObject *object) m_particle[channel].objFather = object; } -void CParticle::SetPosition(int channel, Math::Vector pos) +void CParticle::SetPosition(int channel, glm::vec3 pos) { if (!CheckChannel(channel)) return; m_particle[channel].pos = pos; @@ -738,7 +738,7 @@ void CParticle::SetIntensity(int channel, float intensity) m_particle[channel].intensity = intensity; } -void CParticle::SetParam(int channel, Math::Vector pos, const glm::vec2& dim, float zoom, +void CParticle::SetParam(int channel, glm::vec3 pos, const glm::vec2& dim, float zoom, float angle, float intensity) { if (!CheckChannel(channel)) return; @@ -757,7 +757,7 @@ void CParticle::SetPhase(int channel, ParticlePhase phase, float duration) m_particle[channel].phaseTime = m_particle[channel].time; } -bool CParticle::GetPosition(int channel, Math::Vector &pos) +bool CParticle::GetPosition(int channel, glm::vec3 &pos) { if (!CheckChannel(channel)) return false; pos = m_particle[channel].pos; @@ -788,11 +788,11 @@ void CParticle::FrameParticle(float rTime) m_absTime += rTime; } - Math::Vector wind = m_terrain->GetWind(); - Math::Vector eye = m_engine->GetEyePt(); + glm::vec3 wind = m_terrain->GetWind(); + glm::vec3 eye = m_engine->GetEyePt(); glm::vec2 ts, ti; - Math::Vector pos; + glm::vec3 pos = { 0, 0, 0 }; for (int i = 0; i < MAXPARTICULE*MAXPARTITYPE; i++) { @@ -1117,7 +1117,7 @@ void CParticle::FrameParticle(float rTime) { pos = m_particle[i].goal; m_terrain->AdjustToFloor(pos, true); - Math::Vector speed; + glm::vec3 speed; speed.x = 0.0f; speed.z = 0.0f; speed.y = 0.0f; @@ -1164,7 +1164,7 @@ void CParticle::FrameParticle(float rTime) if (m_exploGunCounter % 2 == 0) { pos = m_particle[i].pos; - Math::Vector speed; + glm::vec3 speed; speed.x = 0.0f; speed.z = 0.0f; speed.y = 0.0f; @@ -1224,7 +1224,7 @@ void CParticle::FrameParticle(float rTime) { if (object->GetType() == OBJECT_MOBILErs && dynamic_cast(*object).GetActiveShieldRadius() > 0.0f) // protected by shield? { - CreateParticle(m_particle[i].pos, Math::Vector(0.0f, 0.0f, 0.0f), { 6.0f, 6.0f }, PARTIGUNDEL, 2.0f); + CreateParticle(m_particle[i].pos, glm::vec3(0.0f, 0.0f, 0.0f), { 6.0f, 6.0f }, PARTIGUNDEL, 2.0f); if (m_lastTimeGunDel > 0.2f) { m_lastTimeGunDel = 0.0f; @@ -1272,7 +1272,7 @@ void CParticle::FrameParticle(float rTime) { if (object->GetType() == OBJECT_MOBILErs && dynamic_cast(*object).GetActiveShieldRadius() > 0.0f) { - CreateParticle(m_particle[i].pos, Math::Vector(0.0f, 0.0f, 0.0f), { 6.0f, 6.0f }, PARTIGUNDEL, 2.0f); + CreateParticle(m_particle[i].pos, glm::vec3(0.0f, 0.0f, 0.0f), { 6.0f, 6.0f }, PARTIGUNDEL, 2.0f); if (m_lastTimeGunDel > 0.2f) { m_lastTimeGunDel = 0.0f; @@ -1317,10 +1317,7 @@ void CParticle::FrameParticle(float rTime) { pos = m_particle[i].goal; m_terrain->AdjustToFloor(pos, true); - Math::Vector speed; - speed.x = 0.0f; - speed.z = 0.0f; - speed.y = 0.0f; + glm::vec3 speed = { 0, 0, 0 }; glm::vec2 dim; dim.x = Math::Rand()*4.0f+2.0f; dim.y = dim.x; @@ -1352,10 +1349,7 @@ void CParticle::FrameParticle(float rTime) if (m_exploGunCounter % 2 == 0) { pos = m_particle[i].pos; - Math::Vector speed; - speed.x = 0.0f; - speed.z = 0.0f; - speed.y = 0.0f; + glm::vec3 speed = { 0, 0, 0 }; glm::vec2 dim; dim.x = Math::Rand()*4.0f+2.0f; dim.y = dim.x; @@ -1897,7 +1891,7 @@ void CParticle::FrameParticle(float rTime) m_particle[i].testTime = 0.0f; pos = m_particle[i].pos; - Math::Vector speed = Math::Vector(0.0f, 0.0f, 0.0f); + glm::vec3 speed = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec2 dim; dim.x = 1.0f*(Math::Rand()*0.8f+0.6f); dim.y = dim.x; @@ -1925,7 +1919,7 @@ void CParticle::FrameParticle(float rTime) int total = static_cast((10.0f*m_engine->GetParticleDensity())); for (int j = 0; j < total; j++) { - Math::Vector speed; + glm::vec3 speed; speed.x = (Math::Rand()-0.5f)*20.0f; speed.y = (Math::Rand()-0.5f)*20.0f; speed.z = (Math::Rand()-0.5f)*20.0f; @@ -1934,7 +1928,7 @@ void CParticle::FrameParticle(float rTime) total = static_cast((5.0f*m_engine->GetParticleDensity())); for (int j = 0; j < total; j++) { - Math::Vector speed; + glm::vec3 speed; speed.x = (Math::Rand()-0.5f)*20.0f; speed.y = (Math::Rand()-0.5f)*20.0f; speed.z = (Math::Rand()-0.5f)*20.0f; @@ -2457,7 +2451,7 @@ void CParticle::FrameParticle(float rTime) } } -bool CParticle::TrackMove(int i, Math::Vector pos, float progress) +bool CParticle::TrackMove(int i, glm::vec3 pos, float progress) { if (i < 0 || i >= MAXTRACK) return true; if (! m_track[i].used) return true; @@ -2466,7 +2460,7 @@ bool CParticle::TrackMove(int i, Math::Vector pos, float progress) { int h = m_track[i].head; - Math::Vector last; + glm::vec3 last = { 0, 0, 0 }; if ( m_track[i].posUsed == 1 || m_track[i].last+m_track[i].step <= progress ) @@ -2602,14 +2596,14 @@ void CParticle::TrackDraw(int i, ParticleType type) } h = m_track[i].head; - Math::Vector p1 = m_track[i].pos[h]; + glm::vec3 p1 = m_track[i].pos[h]; float f1 = m_track[i].intensity; - Math::Vector eye = m_engine->GetEyePt(); + glm::vec3 eye = m_engine->GetEyePt(); float a = Math::RotateAngle(eye.x-p1.x, eye.z-p1.z); Vertex vertex[4]; - Math::Vector corner[4]; + glm::vec3 corner[4]; for (int counter = 0; counter < m_track[i].posUsed-1; counter++) { @@ -2619,14 +2613,13 @@ void CParticle::TrackDraw(int i, ParticleType type) h --; if (h < 0) h = MAXTRACKLEN-1; - Math::Vector p2 = m_track[i].pos[h]; + glm::vec3 p2 = m_track[i].pos[h]; - Math::Vector n = glm::normalize(p1-eye); + glm::vec3 n = glm::normalize(p1-eye); - Math::Vector p; glm::vec2 rot; - p = p1; + glm::vec3 p = p1; p.x += f1*m_track[i].width; rot = Math::RotatePoint({ p1.x, p1.z }, a + Math::PI / 2.0f, { p.x, p.z }); corner[0].x = rot.x; @@ -2676,14 +2669,14 @@ void CParticle::DrawParticleTriangle(int i) { if (m_particle[i].zoom == 0.0f) return; - Math::Vector eye = m_engine->GetEyePt(); - Math::Vector pos = m_particle[i].pos; + glm::vec3 eye = m_engine->GetEyePt(); + glm::vec3 pos = m_particle[i].pos; CObject* object = m_particle[i].objLink; if (object != nullptr) pos += object->GetPosition(); - Math::Vector angle; + glm::vec3 angle; angle.x = -Math::RotateAngle(Math::DistanceProjected(pos, eye), pos.y-eye.y); angle.y = Math::RotateAngle(pos.z-eye.z, pos.x-eye.x); angle.z = m_particle[i].angle; @@ -2707,14 +2700,14 @@ void CParticle::DrawParticleNorm(int i) if (m_particle[i].intensity == 0.0f) return; - Math::Vector corner[4]; + glm::vec3 corner[4]; Vertex vertex[4]; if (m_particle[i].sheet == SH_INTERFACE) { - Math::Vector pos = m_particle[i].pos; + glm::vec3 pos = m_particle[i].pos; - Math::Vector n(0.0f, 0.0f, -1.0f); + glm::vec3 n(0.0f, 0.0f, -1.0f); glm::vec2 dim; dim.x = m_particle[i].dim.x * zoom; @@ -2746,14 +2739,14 @@ void CParticle::DrawParticleNorm(int i) } else { - Math::Vector eye = m_engine->GetEyePt(); - Math::Vector pos = m_particle[i].pos; + glm::vec3 eye = m_engine->GetEyePt(); + glm::vec3 pos = m_particle[i].pos; CObject* object = m_particle[i].objLink; if (object != nullptr) pos += object->GetPosition(); - Math::Vector angle; + glm::vec3 angle; angle.x = -Math::RotateAngle(Math::DistanceProjected(pos, eye), pos.y-eye.y); angle.y = Math::RotateAngle(pos.z-eye.z, pos.x-eye.x); angle.z = m_particle[i].angle; @@ -2765,7 +2758,7 @@ void CParticle::DrawParticleNorm(int i) mat.Set(3, 4, pos.z); m_device->SetTransform(TRANSFORM_WORLD, mat); - Math::Vector n(0.0f, 0.0f, -1.0f); + glm::vec3 n(0.0f, 0.0f, -1.0f); glm::vec2 dim; dim.x = m_particle[i].dim.x * zoom; @@ -2802,13 +2795,13 @@ void CParticle::DrawParticleFlat(int i) if (m_particle[i].zoom == 0.0f) return; if (m_particle[i].intensity == 0.0f) return; - Math::Vector pos = m_particle[i].pos; + glm::vec3 pos = m_particle[i].pos; CObject* object = m_particle[i].objLink; if (object != nullptr) pos += object->GetPosition(); - Math::Vector angle; + glm::vec3 angle; angle.x = Math::PI/2.0f; angle.y = 0.0f; angle.z = m_particle[i].angle; @@ -2816,7 +2809,7 @@ void CParticle::DrawParticleFlat(int i) if (m_engine->GetRankView() == 1) // underwater? pos.y -= 1.0f; - Math::Vector eye = m_engine->GetEyePt(); + glm::vec3 eye = m_engine->GetEyePt(); if (pos.y > eye.y) // seen from below? angle.x = -Math::PI/2.0f; @@ -2827,13 +2820,13 @@ void CParticle::DrawParticleFlat(int i) mat.Set(3, 4, pos.z); m_device->SetTransform(TRANSFORM_WORLD, mat); - Math::Vector n(0.0f, 0.0f, -1.0f); + glm::vec3 n(0.0f, 0.0f, -1.0f); glm::vec2 dim; dim.x = m_particle[i].dim.x * m_particle[i].zoom; dim.y = m_particle[i].dim.y * m_particle[i].zoom; - Math::Vector corner[4]; + glm::vec3 corner[4]; corner[0].x = dim.x; corner[0].y = dim.y; corner[0].z = 0.0f; @@ -2865,7 +2858,7 @@ void CParticle::DrawParticleFog(int i) if (!m_engine->GetFog()) return; if (m_particle[i].intensity == 0.0f) return; - Math::Vector pos = m_particle[i].pos; + glm::vec3 pos = m_particle[i].pos; glm::vec2 dim; dim.x = m_particle[i].dim.x; @@ -2897,7 +2890,7 @@ void CParticle::DrawParticleFog(int i) if (object != nullptr) pos += object->GetPosition(); - Math::Vector angle; + glm::vec3 angle; angle.x = Math::PI/2.0f; angle.y = 0.0f; angle.z = m_particle[i].angle; @@ -2905,7 +2898,7 @@ void CParticle::DrawParticleFog(int i) if (m_engine->GetRankView() == 1) // underwater? pos.y -= 1.0f; - Math::Vector eye = m_engine->GetEyePt(); + glm::vec3 eye = m_engine->GetEyePt(); if (pos.y > eye.y) // seen from below? angle.x = -Math::PI/2.0f; @@ -2916,9 +2909,9 @@ void CParticle::DrawParticleFog(int i) mat.Set(3, 4, pos.z); m_device->SetTransform(TRANSFORM_WORLD, mat); - Math::Vector n(0.0f, 0.0f, -1.0f); + glm::vec3 n(0.0f, 0.0f, -1.0f); - Math::Vector corner[4]; + glm::vec3 corner[4]; corner[0].x = dim.x; corner[0].y = dim.y; @@ -2952,9 +2945,9 @@ void CParticle::DrawParticleRay(int i) if (m_particle[i].zoom == 0.0f) return; if (m_particle[i].intensity == 0.0f) return; - Math::Vector eye = m_engine->GetEyePt(); - Math::Vector pos = m_particle[i].pos; - Math::Vector goal = m_particle[i].goal; + glm::vec3 eye = m_engine->GetEyePt(); + glm::vec3 pos = m_particle[i].pos; + glm::vec3 goal = m_particle[i].goal; CObject* object = m_particle[i].objLink; if (object != nullptr) @@ -2963,8 +2956,8 @@ void CParticle::DrawParticleRay(int i) float a = Math::RotateAngle({ pos.x,pos.z }, { goal.x, goal.z }, { eye.x, eye.z }); bool left = (a < Math::PI); - Math::Vector proj = Math::Projection(pos, goal, eye); - Math::Vector angle; + glm::vec3 proj = Math::Projection(pos, goal, eye); + glm::vec3 angle; angle.x = -Math::RotateAngle(Math::DistanceProjected(proj, eye), proj.y-eye.y); angle.y = Math::RotateAngle(pos.z-goal.z, pos.x-goal.x)+Math::PI/2.0f; angle.z = -Math::RotateAngle(Math::DistanceProjected(pos, goal), pos.y-goal.y); @@ -2977,7 +2970,7 @@ void CParticle::DrawParticleRay(int i) mat.Set(3, 4, pos.z); m_device->SetTransform(TRANSFORM_WORLD, mat); - Math::Vector n(0.0f, 0.0f, left ? 1.0f : -1.0f); + glm::vec3 n(0.0f, 0.0f, left ? 1.0f : -1.0f); glm::vec2 dim; dim.x = m_particle[i].dim.x * m_particle[i].zoom; @@ -3053,7 +3046,7 @@ void CParticle::DrawParticleRay(int i) } } - Math::Vector corner[4]; + glm::vec3 corner[4]; corner[0].x = adv; corner[2].x = adv; @@ -3124,7 +3117,7 @@ void CParticle::DrawParticleSphere(int i) if (m_particle[i].angle != 0.0f) { - Math::Vector angle; + glm::vec3 angle; angle.x = m_particle[i].angle*0.4f; angle.y = m_particle[i].angle*1.0f; angle.z = m_particle[i].angle*0.7f; @@ -3169,7 +3162,7 @@ void CParticle::DrawParticleSphere(int i) float r0 = sinf((ring+0)*deltaRingAngle); float r1 = sinf((ring+1)*deltaRingAngle); - Math::Vector v0, v1; + glm::vec3 v0, v1; v0.y = cosf((ring+0)*deltaRingAngle); v1.y = cosf((ring+1)*deltaRingAngle); @@ -3263,7 +3256,7 @@ void CParticle::DrawParticleCylinder(int i) int j = 0; for (int ring = 0; ring < numRings; ring++) { - Math::Vector v0, v1; + glm::vec3 v0, v1; float r0 = 1.0f*d[ring+0]; // radius at the base float r1 = 1.0f*d[ring+1]; // radius at the top @@ -3326,13 +3319,13 @@ void CParticle::DrawParticleWheel(int i) m_engine->SetTexture("textures/effect03.png"); m_engine->SetState(ENG_RSTATE_ALPHA); - Math::Vector pos[4]; + glm::vec3 pos[4]; pos[0] = m_wheelTrace[i].pos[0]; pos[1] = m_wheelTrace[i].pos[1]; pos[2] = m_wheelTrace[i].pos[2]; pos[3] = m_wheelTrace[i].pos[3]; - Math::Vector n(0.0f, 1.0f, 0.0f); + glm::vec3 n(0.0f, 1.0f, 0.0f); glm::vec2 ts(160.0f/256.0f, 224.0f/256.0f); glm::vec2 ti(ts.x+16.0f/256.0f, ts.y+16.0f/256.0f); @@ -3356,13 +3349,13 @@ void CParticle::DrawParticleWheel(int i) } else { - Math::Vector pos[4]; + glm::vec3 pos[4]; pos[0] = m_wheelTrace[i].pos[0]; pos[1] = m_wheelTrace[i].pos[1]; pos[2] = m_wheelTrace[i].pos[2]; pos[3] = m_wheelTrace[i].pos[3]; - Math::Vector n(0.0f, 1.0f, 0.0f); + glm::vec3 n(0.0f, 1.0f, 0.0f); Vertex vertex[4]; vertex[0] = { pos[0], n }; @@ -3486,7 +3479,7 @@ void CParticle::DrawParticle(int sheet) } } -CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, +CObject* CParticle::SearchObjectGun(glm::vec3 old, glm::vec3 pos, ParticleType type, CObject *father) { if (m_main->GetMovieLock()) return nullptr; // current movie? @@ -3495,8 +3488,8 @@ CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, if (type == PARTIGUN2) min = 2.0f; // shooting insect? if (type == PARTIGUN3) min = 3.0f; // suiciding spider? - Math::Vector box1 = old; - Math::Vector box2 = pos; + glm::vec3 box1 = old; + glm::vec3 box2 = pos; if (box1.x > box2.x) Math::Swap(box1.x, box2.x); // box1 < box2 if (box1.y > box2.y) Math::Swap(box1.y, box2.y); if (box1.z > box2.z) Math::Swap(box1.z, box2.z); @@ -3545,7 +3538,7 @@ CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, if (!obj->Implements(ObjectInterfaceType::Damageable) && !obj->IsBulletWall()) continue; if (obj->Implements(ObjectInterfaceType::Jostleable)) continue; - Math::Vector oPos = obj->GetPosition(); + glm::vec3 oPos = obj->GetPosition(); if (obj->GetType() == OBJECT_MOBILErs) { @@ -3587,7 +3580,7 @@ CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, oPos.y+oRadius < box1.y || oPos.y-oRadius > box2.y || oPos.z+oRadius < box1.z || oPos.z-oRadius > box2.z ) continue; - Math::Vector p = Math::Projection(old, pos, oPos); + glm::vec3 p = Math::Projection(old, pos, oPos); float ddist = Math::Distance(p, oPos)-oRadius; float obj_dist = Math::Distance(old, oPos); if (ddist < min && obj_dist < best_dist) @@ -3601,15 +3594,15 @@ CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, return best; } -CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, +CObject* CParticle::SearchObjectRay(glm::vec3 pos, glm::vec3 goal, ParticleType type, CObject *father) { if (m_main->GetMovieLock()) return nullptr; // current movie? float min = 10.0f; - Math::Vector box1 = pos; - Math::Vector box2 = goal; + glm::vec3 box1 = pos; + glm::vec3 box2 = goal; if (box1.x > box2.x) Math::Swap(box1.x, box2.x); // box1 < box2 if (box1.y > box2.y) Math::Swap(box1.y, box2.y); if (box1.z > box2.z) Math::Swap(box1.z, box2.z); @@ -3640,13 +3633,13 @@ CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, oType != OBJECT_MOTHER && oType != OBJECT_NEST ) continue; - Math::Vector oPos = obj->GetPosition(); + glm::vec3 oPos = obj->GetPosition(); if ( oPos.x < box1.x || oPos.x > box2.x || // outside the box? oPos.y < box1.y || oPos.y > box2.y || oPos.z < box1.z || oPos.z > box2.z ) continue; - Math::Vector p = Math::Projection(pos, goal, oPos); + glm::vec3 p = Math::Projection(pos, goal, oPos); float dist = Math::Distance(p, oPos); if (dist < min) return obj; } @@ -3654,7 +3647,7 @@ CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, return nullptr; } -void CParticle::Play(SoundType sound, Math::Vector pos, float amplitude) +void CParticle::Play(SoundType sound, glm::vec3 pos, float amplitude) { if (m_sound == nullptr) m_sound = CApplication::GetInstancePointer()->GetSound(); @@ -3662,7 +3655,7 @@ void CParticle::Play(SoundType sound, Math::Vector pos, float amplitude) m_sound->Play(sound, pos, amplitude); } -Color CParticle::GetFogColor(Math::Vector pos) +Color CParticle::GetFogColor(glm::vec3 pos) { Color result; result.r = 0.0f; diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 7d9242a0..d4e71124 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -171,9 +171,9 @@ struct Particle float mass = 0.0f; // mass of the particle (in rebounding) float weight = 0.0f; // weight of the particle (for noise) float duration = 0.0f; // length of life - Math::Vector pos; // absolute position (relative if object links) - Math::Vector goal; // goal position (if ray) - Math::Vector speed; // speed of displacement + glm::vec3 pos = { 0, 0, 0 }; // absolute position (relative if object links) + glm::vec3 goal = { 0, 0, 0 }; // goal position (if ray) + glm::vec3 speed = { 0, 0, 0 }; // speed of displacement float windSensitivity = 0.0f; short bounce = 0; // number of rebounds glm::vec2 dim; // dimensions of the rectangle @@ -203,14 +203,14 @@ struct Track float width = 0.0f; // tail width int posUsed = 0.0f; // number of positions in "pos" int head = 0; // head to write index - Math::Vector pos[MAXTRACKLEN]; + glm::vec3 pos[MAXTRACKLEN]; float len[MAXTRACKLEN] = {}; }; struct WheelTrace { TraceColor color = TraceColor::Black; - Math::Vector pos[4]; + glm::vec3 pos[4]; }; @@ -236,31 +236,31 @@ public: void FlushParticle(int sheet); //! Creates a new particle - int CreateParticle(Math::Vector pos, Math::Vector speed, const glm::vec2& dim, + int CreateParticle(glm::vec3 pos, glm::vec3 speed, const glm::vec2& dim, ParticleType type, float duration = 1.0f, float mass = 0.0f, float windSensitivity = 1.0f, int sheet = 0); //! Creates a new triangular particle (debris) - int CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle* triangle, + int CreateFrag(glm::vec3 pos, glm::vec3 speed, EngineTriangle* triangle, ParticleType type, float duration = 1.0f, float mass = 0.0f, float windSensitivity = 1.0f, int sheet = 0); //! Creates a new particle being a part of object - int CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type, + int CreatePart(glm::vec3 pos, glm::vec3 speed, ParticleType type, float duration = 1.0f, float mass = 0.0f, float weight = 0.0f, float windSensitivity = 1.0f, int sheet = 0); //! Creates a new linear particle (radius) - int CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, const glm::vec2& dim, + int CreateRay(glm::vec3 pos, glm::vec3 goal, ParticleType type, const glm::vec2& dim, float duration = 1.0f, int sheet = 0); //! Creates a particle with a trail - int CreateTrack(Math::Vector pos, Math::Vector speed, const glm::vec2& dim, ParticleType type, + int CreateTrack(glm::vec3 pos, glm::vec3 speed, const glm::vec2& dim, ParticleType type, float duration = 1.0f, float mass = 0.0f, float length = 10.0f, float width = 1.0f); //! Creates a tire mark - void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, - const Math::Vector &p4, TraceColor color); + void CreateWheelTrace(const glm::vec3 &p1, const glm::vec3 &p2, const glm::vec3 &p3, + const glm::vec3 &p4, TraceColor color); //! Removes all particles of a given type void DeleteParticle(ParticleType type); @@ -270,19 +270,19 @@ public: void SetObjectLink(int channel, CObject *object); //! Specifies the parent object that created the particle void SetObjectFather(int channel, CObject *object); - void SetPosition(int channel, Math::Vector pos); + void SetPosition(int channel, glm::vec3 pos); void SetDimension(int channel, const glm::vec2& dim); void SetZoom(int channel, float zoom); void SetAngle(int channel, float angle); void SetIntensity(int channel, float intensity); - void SetParam(int channel, Math::Vector pos, const glm::vec2& dim, float zoom, float angle, float intensity); + void SetParam(int channel, glm::vec3 pos, const glm::vec2& dim, float zoom, float angle, float intensity); void SetPhase(int channel, ParticlePhase phase, float duration); //! Returns the position of the particle - bool GetPosition(int channel, Math::Vector &pos); + bool GetPosition(int channel, glm::vec3 &pos); //! Returns the color if you're in the fog or black if you're not - Color GetFogColor(Math::Vector pos); + Color GetFogColor(glm::vec3 pos); //! Indicates whether a sheet is updated or not void SetFrameUpdate(int sheet, bool update); @@ -322,13 +322,13 @@ protected: //! Draws a tire mark void DrawParticleWheel(int i); //! Seeks if an object collided with a bullet - CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father); + CObject* SearchObjectGun(glm::vec3 old, glm::vec3 pos, ParticleType type, CObject *father); //! Seeks if an object collided with a ray - CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father); + CObject* SearchObjectRay(glm::vec3 pos, glm::vec3 goal, ParticleType type, CObject *father); //! Sounded one - void Play(SoundType sound, Math::Vector pos, float amplitude); + void Play(SoundType sound, glm::vec3 pos, float amplitude); //! Moves a drag; returns true if the drag is finished - bool TrackMove(int i, Math::Vector pos, float progress); + bool TrackMove(int i, glm::vec3 pos, float progress); //! Draws a drag void TrackDraw(int i, ParticleType type); diff --git a/src/graphics/engine/planet.cpp b/src/graphics/engine/planet.cpp index d1a18502..e7601afe 100644 --- a/src/graphics/engine/planet.cpp +++ b/src/graphics/engine/planet.cpp @@ -98,7 +98,7 @@ void CPlanet::Draw() float eyeDirH = m_engine->GetEyeDirH(); float eyeDirV = m_engine->GetEyeDirV(); - 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 dp = 0.5f/256.0f; for (const auto& planet : m_planets) @@ -141,10 +141,10 @@ void CPlanet::Draw() Vertex quad[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 } } }; device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, quad, 4); diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 34e96e85..10cf5be0 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -80,9 +80,9 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) int objRank = obj->GetObjectRank(0); if (objRank == -1) return false; - Math::Vector min, max; + glm::vec3 min{}, max{}; m_engine->GetObjectBBox(objRank, min, max); - Math::Vector pos = obj->GetPosition(); + glm::vec3 pos = obj->GetPosition(); DisplayError(type, obj); // displays eventual messages @@ -159,14 +159,14 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) { m_power = true; Math::Matrix* mat = obj->GetWorldMatrix(0); - m_posPower = Math::Transform(*mat, Math::Vector(-15.0f, 7.0f, 0.0f)); + m_posPower = Math::Transform(*mat, glm::vec3(-15.0f, 7.0f, 0.0f)); m_pos = m_posPower; } if ( oType == OBJECT_ENERGY ) { m_power = true; Math::Matrix* mat = obj->GetWorldMatrix(0); - m_posPower = Math::Transform(*mat, Math::Vector(-7.0f, 6.0f, 0.0f)); + m_posPower = Math::Transform(*mat, glm::vec3(-7.0f, 6.0f, 0.0f)); m_pos = m_posPower; } if ( oType == OBJECT_NUCLEAR ) @@ -395,7 +395,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) { m_speed = 1.0f/15.0f; - pos = Math::Vector(-3.0f, 2.0f, 0.0f); + pos = glm::vec3(-3.0f, 2.0f, 0.0f); Math::Matrix* mat = obj->GetWorldMatrix(0); m_pos = Math::Transform(*mat, pos); @@ -498,7 +498,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) for (int i = 0; i < total; i++) { pos = m_posPower; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*30.0f; speed.z = (Math::Rand()-0.5f)*30.0f; speed.y = Math::Rand()*30.0f; @@ -527,7 +527,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) glm::vec2 dim; dim.x = m_size*0.4f; dim.y = dim.x; - m_particle->CreateParticle(pos, Math::Vector(0.0f,0.0f,0.0f), dim, PARTISPHERE0, 2.0f, 0.0f, 0.0f); + m_particle->CreateParticle(pos, glm::vec3(0.0f,0.0f,0.0f), dim, PARTISPHERE0, 2.0f, 0.0f, 0.0f); } } @@ -538,7 +538,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) for (int i = 0; i < total; i++) { pos = m_pos; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*30.0f; speed.z = (Math::Rand()-0.5f)*30.0f; speed.y = Math::Rand()*50.0f; @@ -554,7 +554,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) for (int i = 0; i < total; i++) { pos = m_pos; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*30.0f; speed.z = (Math::Rand()-0.5f)*30.0f; speed.y = Math::Rand()*50.0f; @@ -576,7 +576,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) pos.x += (Math::Rand()-0.5f)*3.0f; pos.z += (Math::Rand()-0.5f)*3.0f; pos.y += (Math::Rand()-0.5f)*2.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*24.0f; speed.z = (Math::Rand()-0.5f)*24.0f; speed.y = 10.0f+Math::Rand()*10.0f; @@ -593,11 +593,11 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) pos.x += (Math::Rand()-0.5f)*3.0f; pos.z += (Math::Rand()-0.5f)*3.0f; pos.y += (Math::Rand()-0.5f)*2.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*24.0f; speed.z = (Math::Rand()-0.5f)*24.0f; speed.y = 7.0f+Math::Rand()*7.0f; - glm::vec2 dim; + glm::vec2 dim{}; dim.x = 1.0f; dim.y = dim.x; m_particle->CreateTrack(pos, speed, dim, PARTITRACK3, @@ -613,7 +613,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) if (m_size > 10.0f || m_power) { pos = m_pos; - Math::Vector speed(0.0f, 0.0f, 0.0f); + glm::vec3 speed(0.0f, 0.0f, 0.0f); glm::vec2 dim; dim.x = m_size; dim.y = dim.x; @@ -634,7 +634,7 @@ bool CPyro::EventProcess(const Event &event) if (m_soundChannel != -1 && m_object != nullptr) { - Math::Vector pos = m_object->GetPosition(); + glm::vec3 pos = m_object->GetPosition(); m_sound->Position(m_soundChannel, pos); if (m_lightRank != -1) @@ -652,25 +652,25 @@ bool CPyro::EventProcess(const Event &event) if (m_crashSpheres.size() > 0) { int i = rand() % m_crashSpheres.size(); - Math::Vector pos = m_crashSpheres[i].pos; + glm::vec3 pos = m_crashSpheres[i].pos; float radius = m_crashSpheres[i].radius; pos.x += (Math::Rand()-0.5f)*radius*2.0f; pos.z += (Math::Rand()-0.5f)*radius*2.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*radius*0.5f; speed.z = (Math::Rand()-0.5f)*radius*0.5f; speed.y = Math::Rand()*radius*1.0f; - glm::vec2 dim; + glm::vec2 dim{}; dim.x = Math::Rand()*radius*0.5f+radius*0.75f*m_force; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, PARTISMOKE1, 3.0f); } else { - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.x += (Math::Rand()-0.5f)*m_size*0.3f; pos.z += (Math::Rand()-0.5f)*m_size*0.3f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*m_size*0.1f; speed.z = (Math::Rand()-0.5f)*m_size*0.1f; speed.y = Math::Rand()*m_size*0.2f; @@ -688,11 +688,11 @@ bool CPyro::EventProcess(const Event &event) for (int i = 0; i < 10; i++) { - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.x += (Math::Rand()-0.5f)*m_size*0.2f; pos.z += (Math::Rand()-0.5f)*m_size*0.2f; pos.y += (Math::Rand()-0.5f)*m_size*0.5f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*5.0f; speed.z = (Math::Rand()-0.5f)*5.0f; speed.y = Math::Rand()*1.0f; @@ -711,11 +711,11 @@ bool CPyro::EventProcess(const Event &event) int r = static_cast(10.0f*m_engine->GetParticleDensity()); for (int i = 0; i < r; i++) { - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.x += (Math::Rand()-0.5f)*20.0f; pos.z += (Math::Rand()-0.5f)*20.0f; pos.y += 8.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*40.0f; speed.z = (Math::Rand()-0.5f)*40.0f; speed.y = Math::Rand()*40.0f; @@ -735,11 +735,11 @@ bool CPyro::EventProcess(const Event &event) if (m_crashSpheres.size() > 0) { int i = rand() % m_crashSpheres.size(); - Math::Vector pos = m_crashSpheres[i].pos; + glm::vec3 pos = m_crashSpheres[i].pos; float radius = m_crashSpheres[i].radius; pos.x += (Math::Rand()-0.5f)*radius*2.0f; pos.z += (Math::Rand()-0.5f)*radius*2.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*radius*0.5f; speed.z = (Math::Rand()-0.5f)*radius*0.5f; speed.y = Math::Rand()*radius*1.0f; @@ -750,10 +750,10 @@ bool CPyro::EventProcess(const Event &event) } else { - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.x += (Math::Rand()-0.5f)*m_size*0.3f; pos.z += (Math::Rand()-0.5f)*m_size*0.3f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*m_size*0.1f; speed.z = (Math::Rand()-0.5f)*m_size*0.1f; speed.y = Math::Rand()*m_size*0.2f; @@ -769,11 +769,11 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticleSmoke = m_time; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.y -= 2.0f; pos.x += (Math::Rand()-0.5f)*4.0f; pos.z += (Math::Rand()-0.5f)*4.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = 0.0f; speed.z = 0.0f; speed.y = 10.0f+Math::Rand()*10.0f; @@ -789,8 +789,8 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_pos; - Math::Vector speed; + glm::vec3 pos = m_pos; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*m_size*1.0f; speed.z = (Math::Rand()-0.5f)*m_size*1.0f; speed.y = Math::Rand()*m_size*0.50f; @@ -810,11 +810,11 @@ bool CPyro::EventProcess(const Event &event) glm::vec2 dim; dim.x = Math::Rand()*m_size/3.0f+m_size/3.0f; dim.y = dim.x; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.x += (Math::Rand()-0.5f)*m_size*0.5f; pos.z += (Math::Rand()-0.5f)*m_size*0.5f; m_terrain->AdjustToFloor(pos); - Math::Vector speed; + glm::vec3 speed{}; speed.x = 0.0f; speed.z = 0.0f; speed.y = -dim.x/2.0f/4.0f; @@ -833,8 +833,8 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_pos; - Math::Vector speed; + glm::vec3 pos = m_pos; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*m_size*2.0f; speed.z = (Math::Rand()-0.5f)*m_size*2.0f; speed.y = Math::Rand()*m_size*1.0f; @@ -851,8 +851,8 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_pos; - Math::Vector speed; + glm::vec3 pos = m_pos; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*m_size*1.0f; speed.z = (Math::Rand()-0.5f)*m_size*1.0f; speed.y = Math::Rand()*m_size*0.50f; @@ -869,11 +869,11 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticleSmoke = m_time; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.y -= 2.0f; pos.x += (Math::Rand()-0.5f)*4.0f; pos.z += (Math::Rand()-0.5f)*4.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = 0.0f; speed.z = 0.0f; speed.y = 4.0f+Math::Rand()*4.0f; @@ -896,11 +896,11 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.y += factor; pos.x += (Math::Rand()-0.5f)*3.0f; pos.z += (Math::Rand()-0.5f)*3.0f; - Math::Vector speed; + glm::vec3 speed; speed.x = 0.0f; speed.z = 0.0f; speed.y = 5.0f+Math::Rand()*5.0f; @@ -912,13 +912,13 @@ bool CPyro::EventProcess(const Event &event) if(m_object != nullptr) { - Math::Vector angle = m_object->GetRotation(); + glm::vec3 angle = m_object->GetRotation(); angle.y = m_progress*20.0f; angle.x = sinf(m_progress*49.0f)*0.3f; angle.z = sinf(m_progress*47.0f)*0.2f; m_object->SetRotation(angle); - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.y += factor; m_object->SetPosition(pos); @@ -935,11 +935,11 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; m_terrain->AdjustToFloor(pos); pos.x += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f; - Math::Vector speed; + glm::vec3 speed; speed.x = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f; speed.y = 2.0f+Math::Rand()*2.0f; @@ -951,7 +951,7 @@ bool CPyro::EventProcess(const Event &event) if(m_object != nullptr) { - Math::Vector angle = m_object->GetRotation(); + glm::vec3 angle = m_object->GetRotation(); angle.x = sinf(m_progress*49.0f)*0.3f*(1.0f-m_progress); angle.z = sinf(m_progress*47.0f)*0.2f*(1.0f-m_progress); m_object->SetRotation(angle); @@ -966,11 +966,11 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; m_terrain->AdjustToFloor(pos); pos.x += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f; - Math::Vector speed; + glm::vec3 speed; speed.x = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f; speed.y = 2.0f+Math::Rand()*2.0f; @@ -982,7 +982,7 @@ bool CPyro::EventProcess(const Event &event) if(m_object != nullptr) { - Math::Vector angle = m_object->GetRotation(); + glm::vec3 angle = m_object->GetRotation(); angle.y = m_progress*20.0f; angle.x = sinf(m_progress*49.0f)*0.3f; angle.z = sinf(m_progress*47.0f)*0.2f; @@ -998,10 +998,10 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; pos.x += (Math::Rand()-0.5f)*5.0f; pos.z += (Math::Rand()-0.5f)*5.0f; - Math::Vector speed; + glm::vec3 speed; speed.x = 0.0f; speed.z = 0.0f; speed.y = 5.0f+Math::Rand()*5.0f; @@ -1042,11 +1042,11 @@ bool CPyro::EventProcess(const Event &event) float factor = m_size*0.3f; if (m_object->GetType() == OBJECT_SAFE) factor *= 1.3f; if (factor > 40.0f) factor = 40.0f; - Math::Vector pos = m_pos; + glm::vec3 pos = m_pos; m_terrain->AdjustToFloor(pos); pos.x += (Math::Rand()-0.5f)*factor; pos.z += (Math::Rand()-0.5f)*factor; - Math::Vector speed; + glm::vec3 speed; speed.x = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f; speed.y = 4.0f+Math::Rand()*4.0f; @@ -1071,11 +1071,11 @@ bool CPyro::EventProcess(const Event &event) float factor = m_size/25.0f; // 1 = standard size - Math::Vector pos = m_object->GetPosition(); + glm::vec3 pos = m_object->GetPosition(); pos.y -= m_object->GetCharacter()->height; pos.x += (Math::Rand()-0.5f)*(4.0f+8.0f*m_progress)*factor; pos.z += (Math::Rand()-0.5f)*(4.0f+8.0f*m_progress)*factor; - Math::Vector speed; + glm::vec3 speed; speed.x = 0.0f; speed.z = 0.0f; speed.y = 0.0f; @@ -1113,7 +1113,7 @@ bool CPyro::EventProcess(const Event &event) } else { - Math::Vector speed; + glm::vec3 speed; speed.y = 0.0f; speed.x = (Math::Rand()-0.5f)*m_progress*1.0f; speed.z = (Math::Rand()-0.5f)*m_progress*1.0f; @@ -1134,9 +1134,9 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_object->GetPosition(); + glm::vec3 pos = m_object->GetPosition(); pos.y += 1.5f; - Math::Vector speed; + glm::vec3 speed; speed.x = (Math::Rand()-0.5f)*10.0f; speed.z = (Math::Rand()-0.5f)*10.0f; speed.y = 8.0f+Math::Rand()*8.0f; @@ -1156,11 +1156,11 @@ bool CPyro::EventProcess(const Event &event) { m_lastParticle = m_time; - Math::Vector pos = m_object->GetPosition(); + glm::vec3 pos = m_object->GetPosition(); pos.y -= 2.0f; pos.x += (Math::Rand()-0.5f)*10.0f; pos.z += (Math::Rand()-0.5f)*10.0f; - Math::Vector speed; + glm::vec3 speed; speed.x = 0.0f; speed.z = 0.0f; speed.y = 1.0f+Math::Rand()*1.0f; @@ -1349,7 +1349,7 @@ void CPyro::DisplayError(PyroType type, CObject* obj) } } -void CPyro::CreateLight(Math::Vector pos, float height) +void CPyro::CreateLight(glm::vec3 pos, float height) { if (!m_engine->GetLightMode()) return; @@ -1358,8 +1358,8 @@ void CPyro::CreateLight(Math::Vector pos, float height) Gfx::Light light; light.type = LIGHT_SPOT; light.ambient = Gfx::Color(0.0f, 0.0f, 0.0f); - light.position = Math::Vector(pos.x, pos.y+height, pos.z); - light.direction = Math::Vector(0.0f, -1.0f, 0.0f); // against the bottom + light.position = glm::vec3(pos.x, pos.y+height, pos.z); + light.direction = glm::vec3(0.0f, -1.0f, 0.0f); // against the bottom light.spotIntensity = 1.0f; light.attenuation0 = 1.0f; light.attenuation1 = 0.0f; @@ -1473,7 +1473,7 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) for (int i = 0; i < total; i++) { - Math::Vector p1, p2, p3; + glm::vec3 p1, p2, p3; p1.x = buffer[i].triangle[0].position.x; p1.y = buffer[i].triangle[0].position.y; @@ -1521,7 +1521,7 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) buffer[i].triangle[2].position.y = p3.y; buffer[i].triangle[2].position.z = p3.z; - Math::Vector offset; + glm::vec3 offset; offset.x = (buffer[i].triangle[0].position.x+buffer[i].triangle[1].position.x+buffer[i].triangle[2].position.x)/3.0f; offset.y = (buffer[i].triangle[0].position.y+buffer[i].triangle[1].position.y+buffer[i].triangle[2].position.y)/3.0f; offset.z = (buffer[i].triangle[0].position.z+buffer[i].triangle[1].position.z+buffer[i].triangle[2].position.z)/3.0f; @@ -1538,11 +1538,11 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) buffer[i].triangle[1].position.z -= offset.z; buffer[i].triangle[2].position.z -= offset.z; - Math::Vector speed; + glm::vec3 speed; float mass; Math::Matrix* mat = obj->GetWorldMatrix(part); - Math::Vector pos = Math::Transform(*mat, offset); + glm::vec3 pos = Math::Transform(*mat, offset); if ( m_type == PT_FRAGV || m_type == PT_EGG ) { speed.x = (Math::Rand()-0.5f)*10.0f; @@ -1576,7 +1576,7 @@ void CPyro::ExploStart() { m_burnType = m_object->GetType(); - Math::Vector oPos = m_object->GetPosition(); + glm::vec3 oPos = m_object->GetPosition(); m_burnFall = m_terrain->GetHeightToFloor(oPos, true); m_object->Simplify(); @@ -1611,9 +1611,9 @@ void CPyro::ExploStart() // TODO: temporary hack (hopefully) assert(m_object->Implements(ObjectInterfaceType::Old)); - Math::Vector pos = dynamic_cast(*m_object).GetPartPosition(i); + glm::vec3 pos = dynamic_cast(*m_object).GetPartPosition(i); - Math::Vector speed; + glm::vec3 speed; float weight; if (i == 0) // main part? @@ -1626,7 +1626,7 @@ void CPyro::ExploStart() } else { - Math::Vector min, max; + glm::vec3 min, max; m_engine->GetObjectBBox(objRank, min, max); weight = Math::Distance(min, max); // weight according to size! @@ -1652,7 +1652,7 @@ void CPyro::BurnStart() { m_burnType = m_object->GetType(); - Math::Vector oPos = m_object->GetPosition(); + glm::vec3 oPos = m_object->GetPosition(); m_burnFall = m_terrain->GetHeightToFloor(oPos, true); m_object->Simplify(); @@ -1686,7 +1686,7 @@ void CPyro::BurnStart() m_burnPartTotal = 0; - Math::Vector pos, angle; + glm::vec3 pos, angle; if ( m_burnType == OBJECT_DERRICK || m_burnType == OBJECT_FACTORY || @@ -2153,7 +2153,7 @@ void CPyro::BurnStart() } } -void CPyro::BurnAddPart(int part, Math::Vector pos, Math::Vector angle) +void CPyro::BurnAddPart(int part, glm::vec3 pos, glm::vec3 angle) { // TODO: temporary hack (hopefully) assert(m_object->Implements(ObjectInterfaceType::Old)); @@ -2178,7 +2178,7 @@ void CPyro::BurnProgress() for (int i = 0; i < m_burnPartTotal; i++) { - Math::Vector pos = m_burnPart[i].initialPos + m_progress*(m_burnPart[i].finalPos-m_burnPart[i].initialPos); + glm::vec3 pos = m_burnPart[i].initialPos + m_progress*(m_burnPart[i].finalPos-m_burnPart[i].initialPos); if ( i == 0 && m_burnFall > 0.0f ) { float h = powf(m_progress, 2.0f)*1000.0f; @@ -2269,7 +2269,7 @@ void CPyro::FallStart() { m_object->SetLock(true); // usable - Math::Vector pos = m_object->GetPosition(); + glm::vec3 pos = m_object->GetPosition(); m_fallFloor = m_terrain->GetFloorLevel(pos); m_fallSpeed = 0.0f; m_fallBulletTime = 0.0f; @@ -2288,7 +2288,7 @@ CObject* CPyro::FallSearchBeeExplo() if (IsObjectBeingTransported(obj)) continue; - Math::Vector oPos = obj->GetPosition(); + glm::vec3 oPos = obj->GetPosition(); if (obj->GetType() == OBJECT_MOBILErs) { @@ -2332,7 +2332,7 @@ void CPyro::FallProgress(float rTime) if (m_object == nullptr) return; m_fallSpeed += rTime*50.0f; // v2 = v1 + a*dt - Math::Vector pos; + glm::vec3 pos; pos = m_object->GetPosition(); pos.y -= m_fallSpeed*rTime; // dd -= v2*dt @@ -2367,7 +2367,7 @@ void CPyro::FallProgress(float rTime) { if (obj->GetType() == OBJECT_MOBILErs && dynamic_cast(*obj).GetActiveShieldRadius() > 0.0f) // protected by shield? { - m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), + m_particle->CreateParticle(pos, glm::vec3(0.0f, 0.0f, 0.0f), { 6.0f, 6.0f }, PARTIGUNDEL, 2.0f, 0.0f, 0.0f); m_sound->Play(SOUND_GUNDEL); @@ -2401,7 +2401,7 @@ Error CPyro::FallIsEnded() { if (m_fallEnding || m_object == nullptr) return ERR_STOP; - Math::Vector pos = m_object->GetPosition(); + glm::vec3 pos = m_object->GetPosition(); if (pos.y > m_fallFloor) return ERR_CONTINUE; m_sound->Play(SOUND_BOUM, pos); diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index af0ba284..742c3406 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -88,7 +88,7 @@ protected: void DisplayError(PyroType type, CObject* obj); //! Creates light to accompany a pyrotechnic effect - void CreateLight(Math::Vector pos, float height); + void CreateLight(glm::vec3 pos, float height); //! Removes the binding to a pyrotechnic effect void DeleteObject(bool primary, bool secondary); @@ -103,7 +103,7 @@ protected: //! Starts a vehicle fire void BurnStart(); //! Adds a part move - void BurnAddPart(int part, Math::Vector pos, Math::Vector angle); + void BurnAddPart(int part, glm::vec3 pos, glm::vec3 angle); //! Advances of a vehicle fire void BurnProgress(); //! Indicates whether a part should be retained @@ -137,8 +137,8 @@ protected: CRobotMain* m_main = nullptr; CSoundInterface* m_sound = nullptr; - Math::Vector m_pos; // center of the effect - Math::Vector m_posPower; // center of the battery + glm::vec3 m_pos = { 0, 0, 0 }; // center of the effect + glm::vec3 m_posPower = { 0, 0, 0 }; // center of the battery bool m_power = false; // battery exists? PyroType m_type = PT_NULL; float m_force = 0.0f; @@ -167,10 +167,10 @@ protected: struct PyroBurnPart { int part = 0; - Math::Vector initialPos; - Math::Vector finalPos; - Math::Vector initialAngle; - Math::Vector finalAngle; + glm::vec3 initialPos = { 0, 0, 0 }; + glm::vec3 finalPos = { 0, 0, 0 }; + glm::vec3 initialAngle = { 0, 0, 0 }; + glm::vec3 finalAngle = { 0, 0, 0 }; }; PyroBurnPart m_burnPart[10]; int m_burnKeepPart[10] = {}; diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 66e3144a..52a29111 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -54,7 +54,7 @@ CTerrain::CTerrain() m_textureSubdivCount = 1; m_depth = 2; m_maxMaterialID = 0; - m_wind = Math::Vector(0.0f, 0.0f, 0.0f); + m_wind = glm::vec3(0.0f, 0.0f, 0.0f); m_defaultHardness = 0.5f; m_useMaterials = false; @@ -253,7 +253,7 @@ bool CTerrain::LoadResources(const std::string& fileName) return true; } -TerrainRes CTerrain::GetResource(const Math::Vector &pos) +TerrainRes CTerrain::GetResource(const glm::vec3 &pos) { if (m_resources.empty()) return TR_NULL; @@ -401,7 +401,7 @@ bool CTerrain::RandomizeRelief() return true; } -bool CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief) +bool CTerrain::AddReliefPoint(glm::vec3 pos, float scaleRelief) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; int size = (m_mosaicCount*m_brickCount)+1; @@ -480,9 +480,9 @@ void CTerrain::AdjustRelief() } } -Math::Vector CTerrain::GetVector(int x, int y) +glm::vec3 CTerrain::GetVector(int x, int y) { - Math::Vector p; + glm::vec3 p{}; p.x = x*m_brickSize - (m_mosaicCount*m_brickCount*m_brickSize) / 2.0; p.z = y*m_brickSize - (m_mosaicCount*m_brickCount*m_brickSize) / 2.0; @@ -517,17 +517,17 @@ VertexTex2 CTerrain::GetVertex(int x, int y, int step) { VertexTex2 v; - Math::Vector o = GetVector(x, y); + glm::vec3 o = GetVector(x, y); v.coord = o; - Math::Vector a = GetVector(x-step, y ); - Math::Vector b = GetVector(x-step, y+step); - Math::Vector c = GetVector(x, y+step); - Math::Vector d = GetVector(x+step, y ); - Math::Vector e = GetVector(x+step, y-step); - Math::Vector f = GetVector(x, y-step); + glm::vec3 a = GetVector(x-step, y ); + glm::vec3 b = GetVector(x-step, y+step); + glm::vec3 c = GetVector(x, y+step); + glm::vec3 d = GetVector(x+step, y ); + glm::vec3 e = GetVector(x+step, y-step); + glm::vec3 f = GetVector(x, y-step); - Math::Vector s(0.0f, 0.0f, 0.0f); + glm::vec3 s(0.0f, 0.0f, 0.0f); if (x-step >= 0 && y+step <= m_mosaicCount*m_brickCount+1) { @@ -551,7 +551,7 @@ VertexTex2 CTerrain::GetVertex(int x, int y, int step) v.normal = s; int brick = m_brickCount/m_textureSubdivCount; - Math::Vector oo = GetVector((x/brick)*brick, (y/brick)*brick); + glm::vec3 oo = GetVector((x/brick)*brick, (y/brick)*brick); o = GetVector(x, y); v.texCoord.x = (o.x-oo.x)*m_textureScale*m_textureSubdivCount; v.texCoord.y = 1.0f - (o.z-oo.z)*m_textureScale*m_textureSubdivCount; @@ -1150,7 +1150,7 @@ bool CTerrain::InitMaterials(int id) bool CTerrain::GenerateMaterials(int *id, float min, float max, float slope, float freq, - Math::Vector center, float radius) + glm::vec3 center, float radius) { static char random[100] = { @@ -1200,7 +1200,7 @@ bool CTerrain::GenerateMaterials(int *id, float min, float max, { if (radius != 0.0f) { - Math::Vector pos; + glm::vec3 pos = { 0, 0, 0 }; pos.x = (static_cast(x)-m_materialPointCount/2.0f)*group*m_brickSize; pos.z = (static_cast(y)-m_materialPointCount/2.0f)*group*m_brickSize; if (Math::DistanceProjected(pos, center) > radius) continue; @@ -1281,7 +1281,7 @@ bool CTerrain::CreateObjects() } /** ATTENTION: ok only with m_depth = 2! */ -bool CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float height) +bool CTerrain::Terraform(const glm::vec3 &p1, const glm::vec3 &p2, float height) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1369,24 +1369,24 @@ bool CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float h return true; } -void CTerrain::SetWind(Math::Vector speed) +void CTerrain::SetWind(glm::vec3 speed) { m_wind = speed; } -Math::Vector CTerrain::GetWind() +glm::vec3 CTerrain::GetWind() { return m_wind; } -float CTerrain::GetFineSlope(const Math::Vector &pos) +float CTerrain::GetFineSlope(const glm::vec3 &pos) { - Math::Vector n; + glm::vec3 n{}; if (! GetNormal(n, pos)) return 0.0f; return fabs(Math::RotateAngle(glm::length(glm::vec2(n.x, n.z)), n.y) - Math::PI/2.0f); } -float CTerrain::GetCoarseSlope(const Math::Vector &pos) +float CTerrain::GetCoarseSlope(const glm::vec3 &pos) { if (m_relief.empty()) return 0.0f; @@ -1412,7 +1412,7 @@ float CTerrain::GetCoarseSlope(const Math::Vector &pos) return atanf((max-min)/m_brickSize); } -bool CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p) +bool CTerrain::GetNormal(glm::vec3 &n, const glm::vec3 &p) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1422,10 +1422,10 @@ bool CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p) if ( x < 0 || x > m_mosaicCount*m_brickCount || y < 0 || y > m_mosaicCount*m_brickCount ) return false; - Math::Vector p1 = GetVector(x+0, y+0); - Math::Vector p2 = GetVector(x+1, y+0); - Math::Vector p3 = GetVector(x+0, y+1); - Math::Vector p4 = GetVector(x+1, y+1); + glm::vec3 p1 = GetVector(x+0, y+0); + glm::vec3 p2 = GetVector(x+1, y+0); + glm::vec3 p3 = GetVector(x+0, y+1); + glm::vec3 p4 = GetVector(x+1, y+1); if ( fabs(p.z - p2.z) < fabs(p.x - p2.x) ) n = Math::NormalToPlane(p1,p2,p3); @@ -1435,7 +1435,7 @@ bool CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p) return true; } -float CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water) +float CTerrain::GetFloorLevel(const glm::vec3 &pos, bool brut, bool water) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1445,12 +1445,12 @@ float CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water) if ( x < 0 || x > m_mosaicCount*m_brickCount || y < 0 || y > m_mosaicCount*m_brickCount ) return false; - Math::Vector p1 = GetVector(x+0, y+0); - Math::Vector p2 = GetVector(x+1, y+0); - Math::Vector p3 = GetVector(x+0, y+1); - Math::Vector p4 = GetVector(x+1, y+1); + glm::vec3 p1 = GetVector(x+0, y+0); + glm::vec3 p2 = GetVector(x+1, y+0); + glm::vec3 p3 = GetVector(x+0, y+1); + glm::vec3 p4 = GetVector(x+1, y+1); - Math::Vector ps = pos; + glm::vec3 ps = pos; if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) ) { if ( !Math::IntersectY(p1, p2, p3, ps) ) return 0.0f; @@ -1471,7 +1471,7 @@ float CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water) return ps.y; } -float CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water) +float CTerrain::GetHeightToFloor(const glm::vec3 &pos, bool brut, bool water) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1481,12 +1481,12 @@ float CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water) if ( x < 0 || x > m_mosaicCount*m_brickCount || y < 0 || y > m_mosaicCount*m_brickCount ) return false; - Math::Vector p1 = GetVector(x+0, y+0); - Math::Vector p2 = GetVector(x+1, y+0); - Math::Vector p3 = GetVector(x+0, y+1); - Math::Vector p4 = GetVector(x+1, y+1); + glm::vec3 p1 = GetVector(x+0, y+0); + glm::vec3 p2 = GetVector(x+1, y+0); + glm::vec3 p3 = GetVector(x+0, y+1); + glm::vec3 p4 = GetVector(x+1, y+1); - Math::Vector ps = pos; + glm::vec3 ps = pos; if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) ) { if ( !Math::IntersectY(p1, p2, p3, ps) ) return 0.0f; @@ -1507,7 +1507,7 @@ float CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water) return pos.y-ps.y; } -bool CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water) +bool CTerrain::AdjustToFloor(glm::vec3 &pos, bool brut, bool water) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1517,10 +1517,10 @@ bool CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water) if ( x < 0 || x > m_mosaicCount*m_brickCount || y < 0 || y > m_mosaicCount*m_brickCount ) return false; - Math::Vector p1 = GetVector(x+0, y+0); - Math::Vector p2 = GetVector(x+1, y+0); - Math::Vector p3 = GetVector(x+0, y+1); - Math::Vector p4 = GetVector(x+1, y+1); + glm::vec3 p1 = GetVector(x+0, y+0); + glm::vec3 p2 = GetVector(x+1, y+0); + glm::vec3 p3 = GetVector(x+0, y+1); + glm::vec3 p4 = GetVector(x+1, y+1); if (fabs(pos.z - p2.z) < fabs(pos.x - p2.x)) { @@ -1546,7 +1546,7 @@ bool CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water) * \param pos position to adjust * \returns \c false if the initial coordinate was outside terrain area; \c true otherwise */ -bool CTerrain::AdjustToStandardBounds(Math::Vector& pos) +bool CTerrain::AdjustToStandardBounds(glm::vec3& pos) { bool ok = true; @@ -1585,7 +1585,7 @@ bool CTerrain::AdjustToStandardBounds(Math::Vector& pos) * \param margin margin to the terrain border * \returns \c false if the initial coordinate was outside terrain area; \c true otherwise */ -bool CTerrain::AdjustToBounds(Math::Vector& pos, float margin) +bool CTerrain::AdjustToBounds(glm::vec3& pos, float margin) { bool ok = true; float limit = m_mosaicCount*m_brickCount*m_brickSize/2.0f - margin; @@ -1622,7 +1622,7 @@ void CTerrain::FlushBuildingLevel() m_buildingLevels.clear(); } -bool CTerrain::AddBuildingLevel(Math::Vector center, float min, float max, +bool CTerrain::AddBuildingLevel(glm::vec3 center, float min, float max, float height, float factor) { int i = 0; @@ -1652,7 +1652,7 @@ bool CTerrain::AddBuildingLevel(Math::Vector center, float min, float max, return true; } -bool CTerrain::UpdateBuildingLevel(Math::Vector center) +bool CTerrain::UpdateBuildingLevel(glm::vec3 center) { for (int i = 0; i < static_cast( m_buildingLevels.size() ); i++) { @@ -1667,7 +1667,7 @@ bool CTerrain::UpdateBuildingLevel(Math::Vector center) return false; } -bool CTerrain::DeleteBuildingLevel(Math::Vector center) +bool CTerrain::DeleteBuildingLevel(glm::vec3 center) { for (int i = 0; i < static_cast( m_buildingLevels.size() ); i++) { @@ -1684,7 +1684,7 @@ bool CTerrain::DeleteBuildingLevel(Math::Vector center) return false; } -float CTerrain::GetBuildingFactor(const Math::Vector &pos) +float CTerrain::GetBuildingFactor(const glm::vec3 &pos) { for (int i = 0; i < static_cast( m_buildingLevels.size() ); i++) { @@ -1701,7 +1701,7 @@ float CTerrain::GetBuildingFactor(const Math::Vector &pos) return 1.0f; // it is normal on the ground } -void CTerrain::AdjustBuildingLevel(Math::Vector &p) +void CTerrain::AdjustBuildingLevel(glm::vec3 &p) { for (int i = 0; i < static_cast( m_buildingLevels.size() ); i++) { @@ -1720,7 +1720,7 @@ void CTerrain::AdjustBuildingLevel(Math::Vector &p) return; } - Math::Vector border{ 0, 0, 0 }; + glm::vec3 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) / @@ -1737,7 +1737,7 @@ void CTerrain::AdjustBuildingLevel(Math::Vector &p) } } -float CTerrain::GetHardness(const Math::Vector &pos) +float CTerrain::GetHardness(const glm::vec3 &pos) { float factor = GetBuildingFactor(pos); if (factor != 1.0f) return 1.0f; // on building level @@ -1767,7 +1767,7 @@ float CTerrain::GetHardness(const Math::Vector &pos) return tm->hardness; } -void CTerrain::ShowFlatGround(Math::Vector pos) +void CTerrain::ShowFlatGround(glm::vec3 pos) { static char table[41*41] = { 1 }; @@ -1780,7 +1780,7 @@ void CTerrain::ShowFlatGround(Math::Vector pos) int i = x + y*41; table[i] = 0; - Math::Vector p{}; + glm::vec3 p{}; p.x = (x-20)*radius; p.z = (y-20)*radius; p.y = 0.0f; @@ -1800,7 +1800,7 @@ void CTerrain::ShowFlatGround(Math::Vector pos) m_engine->CreateGroundMark(pos, 40.0f, 0.001f, 15.0f, 0.001f, 41, 41, table); } -float CTerrain::GetFlatZoneRadius(Math::Vector center, float max) +float CTerrain::GetFlatZoneRadius(glm::vec3 center, float max) { float angle = GetFineSlope(center); if (angle >= TERRAIN_FLATLIMIT) @@ -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{ 0, 0, 0 }; + glm::vec3 pos{ 0, 0, 0 }; pos.x = result.x; pos.z = result.y; float h = GetFloorLevel(pos, true); @@ -1849,7 +1849,7 @@ void CTerrain::FlushFlyingLimit() m_flyingLimits.clear(); } -void CTerrain::AddFlyingLimit(Math::Vector center, +void CTerrain::AddFlyingLimit(glm::vec3 center, float extRadius, float intRadius, float maxHeight) { @@ -1861,7 +1861,7 @@ void CTerrain::AddFlyingLimit(Math::Vector center, m_flyingLimits.push_back(fl); } -float CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit) +float CTerrain::GetFlyingLimit(glm::vec3 pos, bool noLimit) { if (noLimit) return 280.0f; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index aebb712b..6212c006 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -163,7 +163,7 @@ public: //! Initializes all the ground with one material bool InitMaterials(int id); //! Generates a level in the terrain - bool GenerateMaterials(int *id, float min, float max, float slope, float freq, Math::Vector center, float radius); + bool GenerateMaterials(int *id, float min, float max, float slope, float freq, glm::vec3 center, float radius); //! Clears the relief, resources and all other associated data void FlushRelief(); @@ -179,45 +179,45 @@ public: bool CreateObjects(); //! Modifies the terrain's relief - bool Terraform(const Math::Vector& p1, const Math::Vector& p2, float height); + bool Terraform(const glm::vec3& p1, const glm::vec3& p2, float height); //@{ //! Management of the wind - void SetWind(Math::Vector speed); - Math::Vector GetWind(); + void SetWind(glm::vec3 speed); + glm::vec3 GetWind(); //@} //! Gives the exact slope of the terrain at 2D (XZ) position - float GetFineSlope(const Math::Vector& pos); + float GetFineSlope(const glm::vec3& pos); //! Gives the approximate slope of the terrain at 2D (XZ) position - float GetCoarseSlope(const Math::Vector& pos); + float GetCoarseSlope(const glm::vec3& pos); //! Gives the normal vector at 2D (XZ) position - bool GetNormal(Math::Vector& n, const Math::Vector &p); + bool GetNormal(glm::vec3& n, const glm::vec3 &p); //! Returns the height of the ground level at 2D (XZ) position - float GetFloorLevel(const Math::Vector& pos, bool brut=false, bool water=false); + float GetFloorLevel(const glm::vec3& pos, bool brut=false, bool water=false); //! Returns the distance to the ground level from 3D position - float GetHeightToFloor(const Math::Vector& pos, bool brut=false, bool water=false); + float GetHeightToFloor(const glm::vec3& pos, bool brut=false, bool water=false); //! Modifies the Y coordinate of 3D position to rest on the ground floor - bool AdjustToFloor(Math::Vector& pos, bool brut=false, bool water=false); + bool AdjustToFloor(glm::vec3& pos, bool brut=false, bool water=false); //! Adjusts 3D position so that it is within standard terrain boundaries - bool AdjustToStandardBounds(Math::Vector &pos); + bool AdjustToStandardBounds(glm::vec3 &pos); //! Adjusts 3D position so that it is within terrain boundaries and the given margin - bool AdjustToBounds(Math::Vector& pos, float margin); + bool AdjustToBounds(glm::vec3& pos, float margin); //! Returns the resource type available underground at 2D (XZ) position - TerrainRes GetResource(const Math::Vector& pos); + TerrainRes GetResource(const glm::vec3& pos); //! Empty the table of elevations void FlushBuildingLevel(); //! Adds a new elevation for a building - bool AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor); + bool AddBuildingLevel(glm::vec3 center, float min, float max, float height, float factor); //! Updates the elevation for a building when it was moved up (after a terraforming) - bool UpdateBuildingLevel(Math::Vector center); + bool UpdateBuildingLevel(glm::vec3 center); //! Removes the elevation for a building when it was destroyed - bool DeleteBuildingLevel(Math::Vector center); + bool DeleteBuildingLevel(glm::vec3 center); //! Returns the influence factor whether a position is on a possible rise - float GetBuildingFactor(const Math::Vector& pos); + float GetBuildingFactor(const glm::vec3& pos); //! Returns the hardness of the ground in a given place - float GetHardness(const Math::Vector& pos); + float GetHardness(const glm::vec3& pos); //! Returns number of mosaics int GetMosaicCount(); @@ -229,9 +229,9 @@ public: float GetReliefScale(); //! Shows the flat areas on the ground - void ShowFlatGround(Math::Vector pos); + void ShowFlatGround(glm::vec3 pos); //! Calculates the radius of the largest flat area available - float GetFlatZoneRadius(Math::Vector center, float max); + float GetFlatZoneRadius(glm::vec3 center, float max); //@{ //! Management of the global max flying height @@ -241,17 +241,17 @@ public: //! Empty the table of flying limits void FlushFlyingLimit(); //! Adds a new flying limit - void AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight); + void AddFlyingLimit(glm::vec3 center, float extRadius, float intRadius, float maxHeight); //! Returns the maximum height of flight - float GetFlyingLimit(Math::Vector pos, bool noLimit); + float GetFlyingLimit(glm::vec3 pos, bool noLimit); protected: //! Adds a point of elevation in the buffer of relief - bool AddReliefPoint(Math::Vector pos, float scaleRelief); + bool AddReliefPoint(glm::vec3 pos, float scaleRelief); //! Adjust the edges of each mosaic to be compatible with all lower resolutions void AdjustRelief(); //! Calculates a vector of the terrain - Math::Vector GetVector(int x, int y); + glm::vec3 GetVector(int x, int y); //! Calculates a vertex of the terrain VertexTex2 GetVertex(int x, int y, int step); //! Creates all objects of a mosaic @@ -282,7 +282,7 @@ protected: void FlushMaterialPoints(); //! Adjusts a position according to a possible rise - void AdjustBuildingLevel(Math::Vector &p); + void AdjustBuildingLevel(glm::vec3 &p); protected: CEngine* m_engine; @@ -371,7 +371,7 @@ protected: */ struct BuildingLevel { - Math::Vector center{ 0, 0, 0 }; + glm::vec3 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{ 0, 0, 0 }; + glm::vec3 m_wind{ 0, 0, 0 }; //! Global flying height limit float m_flyingMaxHeight; @@ -396,7 +396,7 @@ protected: */ struct FlyingLimit { - Math::Vector center{ 0, 0, 0 }; + glm::vec3 center{ 0, 0, 0 }; float extRadius = 0.0f; float intRadius = 0.0f; float maxHeight = 0.0f; diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 37a993b9..48b8cdbf 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -1016,10 +1016,10 @@ void CText::DrawHighlight(FontMetaChar hl, const glm::ivec2& pos, const glm::ive VertexCol quad[] = { - { Math::Vector(p1.x, p2.y, 0.0f), grad[3] }, - { Math::Vector(p1.x, p1.y, 0.0f), grad[0] }, - { Math::Vector(p2.x, p2.y, 0.0f), grad[2] }, - { Math::Vector(p2.x, p1.y, 0.0f), grad[1] } + { glm::vec3(p1.x, p2.y, 0.0f), grad[3] }, + { glm::vec3(p1.x, p1.y, 0.0f), grad[0] }, + { glm::vec3(p2.x, p2.y, 0.0f), grad[2] }, + { glm::vec3(p2.x, p1.y, 0.0f), grad[1] } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, quad, 4); diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index 4b57cca8..f9933482 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -92,16 +92,16 @@ void CWater::LavaFrame(float rTime) if (m_time - m_lastLava >= 0.1f) { - Math::Vector eye = m_engine->GetEyePt(); - Math::Vector lookat = m_engine->GetLookatPt(); + glm::vec3 eye = m_engine->GetEyePt(); + glm::vec3 lookat = m_engine->GetLookatPt(); float distance = Math::Rand()*200.0f; float shift = (Math::Rand()-0.5f)*200.0f; - Math::Vector dir = glm::normalize(lookat-eye); - Math::Vector pos = eye + dir*distance; + glm::vec3 dir = glm::normalize(lookat-eye); + glm::vec3 pos = eye + dir*distance; - Math::Vector perp; + glm::vec3 perp{}; perp.x = -dir.z; perp.y = dir.y; perp.z = dir.x; @@ -140,7 +140,7 @@ void CWater::VaporFlush() } } -bool CWater::VaporCreate(ParticleType type, Math::Vector pos, float delay) +bool CWater::VaporCreate(ParticleType type, glm::vec3 pos, float delay) { for (int i = 0; i < static_cast( m_vapors.size() ); i++) { @@ -183,11 +183,11 @@ void CWater::VaporFrame(int i, float rTime) { for (int j = 0; j < 10; j++) { - Math::Vector pos = m_vapors[i].pos; + glm::vec3 pos = m_vapors[i].pos; pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f; pos.y -= 1.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*6.0f; speed.z = (Math::Rand()-0.5f)*6.0f; speed.y = 8.0f+Math::Rand()*5.0f; @@ -199,11 +199,11 @@ void CWater::VaporFrame(int i, float rTime) } else if (m_vapors[i].type == PARTIFLAME) { - Math::Vector pos = m_vapors[i].pos; + glm::vec3 pos = m_vapors[i].pos; pos.x += (Math::Rand()-0.5f)*8.0f; pos.z += (Math::Rand()-0.5f)*8.0f; pos.y -= 2.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f; speed.y = 4.0f+Math::Rand()*4.0f; @@ -214,11 +214,11 @@ void CWater::VaporFrame(int i, float rTime) } else { - Math::Vector pos = m_vapors[i].pos; + glm::vec3 pos = m_vapors[i].pos; pos.x += (Math::Rand()-0.5f)*4.0f; pos.z += (Math::Rand()-0.5f)*4.0f; pos.y -= 2.0f; - Math::Vector speed; + glm::vec3 speed{}; speed.x = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f; speed.y = 8.0f+Math::Rand()*8.0f; @@ -235,7 +235,7 @@ void CWater::VaporFrame(int i, float rTime) } } -void CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm, +void CWater::AdjustLevel(glm::vec3 &pos, glm::vec3 &norm, glm::vec2& uv1, glm::vec2& uv2) { float t1 = m_time*1.5f + pos.x*0.1f * pos.z*0.2f; @@ -249,7 +249,7 @@ void CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm, t1 = m_time*0.50f + pos.x*2.1f + pos.z*1.1f; float t2 = m_time*0.75f + pos.x*2.0f + pos.z*1.0f; - norm = Math::Vector(sinf(t1)*m_glint, 1.0f, sinf(t2)*m_glint); + norm = glm::vec3(sinf(t1)*m_glint, 1.0f, sinf(t2)*m_glint); } /** This surface prevents to see the sky (background) underwater! */ @@ -259,8 +259,8 @@ void CWater::DrawBack() if (m_type[0] == WATER_NULL) return; if (m_lines.empty()) return; - Math::Vector eye = m_engine->GetEyePt(); - Math::Vector lookat = m_engine->GetLookatPt(); + glm::vec3 eye = m_engine->GetEyePt(); + glm::vec3 lookat = m_engine->GetLookatPt(); Material material; material.diffuse = m_diffuse; @@ -280,14 +280,14 @@ void CWater::DrawBack() matrix.LoadIdentity(); device->SetTransform(TRANSFORM_WORLD, matrix); - Math::Vector p; + glm::vec3 p = { 0, 0, 0 }; p.x = eye.x; p.z = eye.z; float dist = Math::DistanceProjected(eye, lookat); p.x = (lookat.x-eye.x)*deep*1.0f/dist + eye.x; p.z = (lookat.z-eye.z)*deep*1.0f/dist + eye.z; - Math::Vector p1, p2; + glm::vec3 p1{}, p2{}; p1.x = (lookat.z-eye.z)*deep*2.0f/dist + p.x; p1.z = -(lookat.x-eye.x)*deep*2.0f/dist + p.z; p2.x = -(lookat.z-eye.z)*deep*2.0f/dist + p.x; @@ -300,10 +300,10 @@ void CWater::DrawBack() VertexCol vertices[4] = { - { Math::Vector(p1.x, p2.y, p1.z), white }, - { Math::Vector(p1.x, p1.y, p1.z), white }, - { Math::Vector(p2.x, p2.y, p2.z), white }, - { Math::Vector(p2.x, p1.y, p2.z), white } + { glm::vec3(p1.x, p2.y, p1.z), white }, + { glm::vec3(p1.x, p1.y, p1.z), white }, + { glm::vec3(p2.x, p2.y, p2.z), white }, + { glm::vec3(p2.x, p1.y, p2.z), white } }; device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertices, 4); @@ -322,7 +322,7 @@ void CWater::DrawSurf() std::vector vertices((m_brickCount+2)*2, Vertex()); - Math::Vector eye = m_engine->GetEyePt(); + glm::vec3 eye = m_engine->GetEyePt(); int rankview = m_engine->GetRankView(); bool under = ( rankview == 1); @@ -367,13 +367,13 @@ void CWater::DrawSurf() 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; // Visible line? - Math::Vector p = pos; + glm::vec3 p = pos; p.x += size*(m_lines[i].len-1); float radius = sqrtf(powf(size, 2.0f)+powf(size*m_lines[i].len, 2.0f)); if (Math::Distance(p, eye) > deep + radius) @@ -385,7 +385,7 @@ void CWater::DrawSurf() int vertexIndex = 0; glm::vec2 uv1, uv2; - Math::Vector n; + glm::vec3 n{}; p.x = pos.x-size; p.z = pos.z-sizez; @@ -440,7 +440,7 @@ bool CWater::GetWater(int x, int y) { for (int dx = 0; dx <= m_subdiv; dx++) { - Math::Vector pos; + glm::vec3 pos{}; pos.x = (x+dx)*size - offset; pos.z = (y+dy)*size - offset; pos.y = 0.0f; @@ -471,7 +471,7 @@ void CWater::CreateLine(int x, int y, int len) void CWater::Create(WaterType type1, WaterType type2, const std::string& fileName, Color diffuse, Color ambient, - float level, float glint, Math::Vector eddy) + float level, float glint, glm::vec3 eddy) { m_type[0] = type1; m_type[1] = type2; @@ -612,7 +612,7 @@ bool CWater::GetLava() return m_lava; } -void CWater::AdjustEye(Math::Vector &eye) +void CWater::AdjustEye(glm::vec3 &eye) { if (m_lava) { diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index 85668db4..c5fc41ab 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -80,7 +80,7 @@ public: void Flush(); //! Creates all expanses of water void Create(WaterType type1, WaterType type2, const std::string& fileName, - Color diffuse, Color ambient, float level, float glint, Math::Vector eddy); + Color diffuse, Color ambient, float level, float glint, glm::vec3 eddy); //! Draw the back surface of the water void DrawBack(); //! Draws the flat surface of the water @@ -100,7 +100,7 @@ public: //@} //! Adjusts the eye of the camera, not to be in the water - void AdjustEye(Math::Vector &eye); + void AdjustEye(glm::vec3 &eye); protected: //! Makes water evolve @@ -108,7 +108,7 @@ protected: //! Makes evolve the steam jets on the lava void LavaFrame(float rTime); //! Adjusts the position to normal, to imitate reflections on an expanse of water at rest - void AdjustLevel(Math::Vector &pos, Math::Vector &norm, glm::vec2& uv1, glm::vec2& uv2); + void AdjustLevel(glm::vec3 &pos, glm::vec3 &norm, glm::vec2& uv1, glm::vec2& uv2); //! Indicates if there is water in a given position bool GetWater(int x, int y); //! Updates the positions, relative to the ground @@ -117,7 +117,7 @@ protected: //! Removes all the steam jets void VaporFlush(); //! Creates a new steam - bool VaporCreate(ParticleType type, Math::Vector pos, float delay); + bool VaporCreate(ParticleType type, glm::vec3 pos, float delay); //! Makes evolve a steam jet void VaporFrame(int i, float rTime); @@ -135,7 +135,7 @@ protected: //! Amplitude of reflections float m_glint = 0.0f; //! Amplitude of swirls - Math::Vector m_eddy; + glm::vec3 m_eddy = { 0, 0, 0 }; //! Diffuse color Color m_diffuse; //! Ambient color @@ -174,7 +174,7 @@ protected: { bool used = false; ParticleType type = PARTIWATER; - Math::Vector pos; + glm::vec3 pos = { 0, 0, 0 }; float delay = 0.0f; float time = 0.0f; float last = 0.0f; diff --git a/src/graphics/model/model_crash_sphere.h b/src/graphics/model/model_crash_sphere.h index 4e15757d..17f3ea5a 100644 --- a/src/graphics/model/model_crash_sphere.h +++ b/src/graphics/model/model_crash_sphere.h @@ -19,7 +19,9 @@ #pragma once -#include "math/vector.h" +#include + +#include namespace Gfx { @@ -30,7 +32,7 @@ namespace Gfx */ struct ModelCrashSphere { - Math::Vector position{ 0, 0, 0 }; + glm::vec3 position = { 0, 0, 0 }; float radius = 0.0f; std::string sound; float hardness = 0.0f; diff --git a/src/graphics/model/model_input.cpp b/src/graphics/model/model_input.cpp index b09892d5..3ccea174 100644 --- a/src/graphics/model/model_input.cpp +++ b/src/graphics/model/model_input.cpp @@ -63,7 +63,7 @@ namespace ModelInput void ReadValuePrefix(std::istream& stream, const std::string& expectedPrefix); VertexTex2 ParseVertexTex2(const std::string& text); Material ParseMaterial(const std::string& text); - Math::Vector ParseVector(const std::string& text); + glm::vec3 ParseVector(const std::string& text); ModelCrashSphere ParseCrashSphere(const std::string& text); ModelShadowSpot ParseShadowSpot(const std::string& text); Math::Sphere ParseCameraCollisionSphere(const std::string& text); @@ -769,9 +769,9 @@ Material ModelInput::ParseMaterial(const std::string& text) return material; } -Math::Vector ModelInput::ParseVector(const std::string& text) +glm::vec3 ModelInput::ParseVector(const std::string& text) { - Math::Vector vector; + glm::vec3 vector = { 0, 0, 0 }; std::stringstream stream; stream.str(text); diff --git a/src/graphics/model/model_io_structs.h b/src/graphics/model/model_io_structs.h index b78f8ee2..d1f706bd 100644 --- a/src/graphics/model/model_io_structs.h +++ b/src/graphics/model/model_io_structs.h @@ -134,11 +134,11 @@ struct ModelMeshHeaderV3 //! Parent mesh name std::string parentName; //! Mesh position - Math::Vector position; + glm::vec3 position = { 0, 0, 0 }; //! Mesh rotation - Math::Vector rotation; + glm::vec3 rotation = { 0, 0, 0 }; //! Mesh scale - Math::Vector scale; + glm::vec3 scale = { 1, 1, 1 }; }; /**