From 9691974b1a63ff77bc941f96f1ba2e1f9cc5cdc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Fri, 24 Dec 2021 02:36:54 +0100 Subject: [PATCH] Refactored Math::Point in CLighting, CParticle, CParticleGenerator and CText --- src/graphics/engine/lightning.cpp | 30 ++++---- src/graphics/engine/lightning.h | 5 +- src/graphics/engine/particle.cpp | 114 +++++++++++++++--------------- src/graphics/engine/particle.h | 16 ++--- src/graphics/engine/text.cpp | 38 +++++----- src/graphics/engine/text.h | 14 ++-- src/ui/controls/control.h | 2 + src/ui/particles_generator.cpp | 6 +- src/ui/particles_generator.h | 5 +- 9 files changed, 115 insertions(+), 115 deletions(-) diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index 02f898f7..49e76f9b 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -229,10 +229,10 @@ void CLightning::Draw() m_engine->SetTexture("textures/effect00.png"); m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK); - Math::Point texInf; + glm::vec2 texInf; texInf.x = 64.5f/256.0f; texInf.y = 33.0f/256.0f; - Math::Point texSup; + glm::vec2 texSup; texSup.x = 95.5f/256.0f; texSup.y = 34.0f/256.0f; // blank @@ -249,43 +249,43 @@ void CLightning::Draw() Math::Vector p2 = p1; p2.y += 8.0f+0.2f*i; - Math::Point rot; + glm::vec2 rot; Math::Vector p = p1; p.x += m_segments[i].width; - rot = Math::RotatePoint(Math::Point(p1.x, p1.z), a+Math::PI/2.0f, Math::Point(p.x, p.z)); + 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; corner[0].y = p1.y; corner[0].z = rot.y+m_segments[i].shift.y; - rot = Math::RotatePoint(Math::Point(p1.x, p1.z), a-Math::PI/2.0f, Math::Point(p.x, p.z)); + rot = Math::RotatePoint({ p1.x, p1.z }, a - Math::PI / 2.0f, { p.x, p.z }); corner[1].x = rot.x+m_segments[i].shift.x; corner[1].y = p1.y; corner[1].z = rot.y+m_segments[i].shift.y; p = p2; p.x += m_segments[i+1].width; - rot = Math::RotatePoint(Math::Point(p2.x, p2.z), a+Math::PI/2.0f, Math::Point(p.x, p.z)); + rot = Math::RotatePoint({ p2.x, p2.z }, a + Math::PI / 2.0f, { p.x, p.z }); corner[2].x = rot.x+m_segments[i+1].shift.x; corner[2].y = p2.y; corner[2].z = rot.y+m_segments[i+1].shift.y; - rot = Math::RotatePoint(Math::Point(p2.x, p2.z), a-Math::PI/2.0f, Math::Point(p.x, p.z)); + rot = Math::RotatePoint({ p2.x, p2.z }, a - Math::PI / 2.0f, { p.x, p.z }); corner[3].x = rot.x+m_segments[i+1].shift.x; corner[3].y = p2.y; corner[3].z = rot.y+m_segments[i+1].shift.y; if (p2.y < p1.y) { - vertex[0] = { corner[1], n, Math::Point(texSup.x, texSup.y) }; - vertex[1] = { corner[0], n, Math::Point(texInf.x, texSup.y) }; - vertex[2] = { corner[3], n, Math::Point(texSup.x, texInf.y) }; - vertex[3] = { corner[2], n, Math::Point(texInf.x, texInf.y) }; + vertex[0] = { corner[1], n, { texSup.x, texSup.y } }; + vertex[1] = { corner[0], n, { texInf.x, texSup.y } }; + vertex[2] = { corner[3], n, { texSup.x, texInf.y } }; + vertex[3] = { corner[2], n, { texInf.x, texInf.y } }; } else { - vertex[0] = { corner[0], n, Math::Point(texSup.x, texSup.y) }; - vertex[1] = { corner[1], n, Math::Point(texInf.x, texSup.y) }; - vertex[2] = { corner[2], n, Math::Point(texSup.x, texInf.y) }; - vertex[3] = { corner[3], n, Math::Point(texInf.x, texInf.y) }; + vertex[0] = { corner[0], n, { texSup.x, texSup.y } }; + vertex[1] = { corner[1], n, { texInf.x, texSup.y } }; + vertex[2] = { corner[2], n, { texSup.x, texInf.y } }; + vertex[3] = { corner[3], n, { texInf.x, texInf.y } }; } device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index 531ac21e..02191f48 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -24,9 +24,10 @@ #pragma once -#include "math/point.h" #include "math/vector.h" +#include + #include class CObject; @@ -108,7 +109,7 @@ protected: struct LightningSegment { - Math::Point shift; + glm::vec2 shift; float width = 0.0f; }; std::vector m_segments; diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 35779bec..ba28ed3a 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, Math::Point dim, +int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, const glm::vec2& dim, ParticleType type, float duration, float mass, float windSensitivity, int sheet) @@ -509,7 +509,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, - ParticleType type, Math::Point dim, + ParticleType type, const glm::vec2& dim, float duration, int sheet) { int t = -1; @@ -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, Math::Point dim, +int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, const glm::vec2& dim, ParticleType type, float duration, float mass, float length, float width) { @@ -714,7 +714,7 @@ void CParticle::SetPosition(int channel, Math::Vector pos) m_particle[channel].pos = pos; } -void CParticle::SetDimension(int channel, Math::Point dim) +void CParticle::SetDimension(int channel, const glm::vec2& dim) { if (!CheckChannel(channel)) return; m_particle[channel].dim = dim; @@ -738,7 +738,7 @@ void CParticle::SetIntensity(int channel, float intensity) m_particle[channel].intensity = intensity; } -void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, +void CParticle::SetParam(int channel, Math::Vector pos, const glm::vec2& dim, float zoom, float angle, float intensity) { if (!CheckChannel(channel)) return; @@ -791,7 +791,7 @@ void CParticle::FrameParticle(float rTime) Math::Vector wind = m_terrain->GetWind(); Math::Vector eye = m_engine->GetEyePt(); - Math::Point ts, ti; + glm::vec2 ts, ti; Math::Vector pos; for (int i = 0; i < MAXPARTICULE*MAXPARTITYPE; i++) @@ -1121,7 +1121,7 @@ void CParticle::FrameParticle(float rTime) speed.x = 0.0f; speed.z = 0.0f; speed.y = 0.0f; - Math::Point dim; + glm::vec2 dim; dim.x = Math::Rand()*6.0f+6.0f; dim.y = dim.x; float duration = Math::Rand()*1.0f+1.0f; @@ -1168,7 +1168,7 @@ void CParticle::FrameParticle(float rTime) speed.x = 0.0f; speed.z = 0.0f; speed.y = 0.0f; - Math::Point dim; + glm::vec2 dim; dim.x = Math::Rand()*6.0f+6.0f; dim.y = dim.x; float duration = Math::Rand()*1.0f+1.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), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f); + CreateParticle(m_particle[i].pos, Math::Vector(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), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f); + CreateParticle(m_particle[i].pos, Math::Vector(0.0f, 0.0f, 0.0f), { 6.0f, 6.0f }, PARTIGUNDEL, 2.0f); if (m_lastTimeGunDel > 0.2f) { m_lastTimeGunDel = 0.0f; @@ -1321,7 +1321,7 @@ void CParticle::FrameParticle(float rTime) speed.x = 0.0f; speed.z = 0.0f; speed.y = 0.0f; - Math::Point dim; + glm::vec2 dim; dim.x = Math::Rand()*4.0f+2.0f; dim.y = dim.x; float duration = Math::Rand()*0.7f+0.7f; @@ -1356,7 +1356,7 @@ void CParticle::FrameParticle(float rTime) speed.x = 0.0f; speed.z = 0.0f; speed.y = 0.0f; - Math::Point dim; + glm::vec2 dim; dim.x = Math::Rand()*4.0f+2.0f; dim.y = dim.x; float duration = Math::Rand()*0.7f+0.7f; @@ -1898,7 +1898,7 @@ void CParticle::FrameParticle(float rTime) pos = m_particle[i].pos; Math::Vector speed = Math::Vector(0.0f, 0.0f, 0.0f); - Math::Point dim; + glm::vec2 dim; dim.x = 1.0f*(Math::Rand()*0.8f+0.6f); dim.y = dim.x; CreateParticle(pos, speed, dim, PARTIGAS, 0.5f); @@ -1917,7 +1917,7 @@ void CParticle::FrameParticle(float rTime) DeleteRank(i); pos = m_particle[i].pos; - Math::Point dim; + glm::vec2 dim; dim.x = m_particle[i].dim.x/4.0f; dim.y = dim.x; float duration = m_particle[i].duration; @@ -2514,7 +2514,7 @@ void CParticle::TrackDraw(int i, ParticleType type) mat.LoadIdentity(); m_device->SetTransform(TRANSFORM_WORLD, mat); - Math::Point texInf, texSup; + glm::vec2 texInf{ 0, 0 }, texSup{ 0, 0 }; if (type == PARTITRACK1) // technical explosion? { @@ -2624,43 +2624,43 @@ void CParticle::TrackDraw(int i, ParticleType type) Math::Vector n = Normalize(p1-eye); Math::Vector p; - Math::Point rot; + glm::vec2 rot; p = p1; p.x += f1*m_track[i].width; - rot = Math::RotatePoint(Math::Point(p1.x, p1.z), a+Math::PI/2.0f, Math::Point(p.x, p.z)); + rot = Math::RotatePoint({ p1.x, p1.z }, a + Math::PI / 2.0f, { p.x, p.z }); corner[0].x = rot.x; corner[0].y = p1.y; corner[0].z = rot.y; - rot = Math::RotatePoint(Math::Point(p1.x, p1.z), a-Math::PI/2.0f, Math::Point(p.x, p.z)); + rot = Math::RotatePoint({ p1.x, p1.z }, a - Math::PI / 2.0f, { p.x, p.z }); corner[1].x = rot.x; corner[1].y = p1.y; corner[1].z = rot.y; p = p2; p.x += f2*m_track[i].width; - rot = Math::RotatePoint(Math::Point(p2.x, p2.z), a+Math::PI/2.0f, Math::Point(p.x, p.z)); + rot = Math::RotatePoint({ p2.x, p2.z }, a + Math::PI / 2.0f, { p.x, p.z }); corner[2].x = rot.x; corner[2].y = p2.y; corner[2].z = rot.y; - rot = Math::RotatePoint(Math::Point(p2.x, p2.z), a-Math::PI/2.0f, Math::Point(p.x, p.z)); + rot = Math::RotatePoint({ p2.x, p2.z }, a - Math::PI / 2.0f, { p.x, p.z }); corner[3].x = rot.x; corner[3].y = p2.y; corner[3].z = rot.y; if (p2.y < p1.y) { - vertex[0] = { corner[1], n, Math::Point(texSup.x, texSup.y) }; - vertex[1] = { corner[0], n, Math::Point(texInf.x, texSup.y) }; - vertex[2] = { corner[3], n, Math::Point(texSup.x, texInf.y) }; - vertex[3] = { corner[2], n, Math::Point(texInf.x, texInf.y) }; + vertex[0] = { corner[1], n, { texSup.x, texSup.y } }; + vertex[1] = { corner[0], n, { texInf.x, texSup.y } }; + vertex[2] = { corner[3], n, { texSup.x, texInf.y } }; + vertex[3] = { corner[2], n, { texInf.x, texInf.y } }; } else { - vertex[0] = { corner[0], n, Math::Point(texSup.x, texSup.y) }; - vertex[1] = { corner[1], n, Math::Point(texInf.x, texSup.y) }; - vertex[2] = { corner[2], n, Math::Point(texSup.x, texInf.y) }; - vertex[3] = { corner[3], n, Math::Point(texInf.x, texInf.y) }; + vertex[0] = { corner[0], n, { texSup.x, texSup.y } }; + vertex[1] = { corner[1], n, { texInf.x, texSup.y } }; + vertex[2] = { corner[2], n, { texSup.x, texInf.y } }; + vertex[3] = { corner[3], n, { texInf.x, texInf.y } }; } m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); @@ -2736,10 +2736,10 @@ void CParticle::DrawParticleNorm(int i) corner[3].y = pos.y-dim.y; corner[3].z = 0.0f; - vertex[0] = { corner[1], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texSup.y) }; - vertex[1] = { corner[0], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texSup.y) }; - vertex[2] = { corner[3], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texInf.y) }; - vertex[3] = { corner[2], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texInf.y) }; + vertex[0] = { corner[1], n, { m_particle[i].texSup.x, m_particle[i].texSup.y } }; + vertex[1] = { corner[0], n, { m_particle[i].texInf.x, m_particle[i].texSup.y } }; + vertex[2] = { corner[3], n, { m_particle[i].texSup.x, m_particle[i].texInf.y } }; + vertex[3] = { corner[2], n, { m_particle[i].texInf.x, m_particle[i].texInf.y } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); @@ -2787,10 +2787,10 @@ void CParticle::DrawParticleNorm(int i) corner[3].y = -dim.y; corner[3].z = 0.0f; - vertex[0] = { corner[1], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texSup.y) }; - vertex[1] = { corner[0], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texSup.y) }; - vertex[2] = { corner[3], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texInf.y) }; - vertex[3] = { corner[2], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texInf.y) }; + vertex[0] = { corner[1], n, { m_particle[i].texSup.x, m_particle[i].texSup.y } }; + vertex[1] = { corner[0], n, { m_particle[i].texInf.x, m_particle[i].texSup.y } }; + vertex[2] = { corner[3], n, { m_particle[i].texSup.x, m_particle[i].texInf.y } }; + vertex[3] = { corner[2], n, { m_particle[i].texInf.x, m_particle[i].texInf.y } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4, m_particle[i].color); m_engine->AddStatisticTriangle(2); @@ -2851,10 +2851,10 @@ void CParticle::DrawParticleFlat(int i) corner[3].z = 0.0f; Vertex vertex[4]; - vertex[0] = { corner[1], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texSup.y) }; - vertex[1] = { corner[0], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texSup.y) }; - vertex[2] = { corner[3], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texInf.y) }; - vertex[3] = { corner[2], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texInf.y) }; + vertex[0] = { corner[1], n, { m_particle[i].texSup.x, m_particle[i].texSup.y } }; + vertex[1] = { corner[0], n, { m_particle[i].texInf.x, m_particle[i].texSup.y } }; + vertex[2] = { corner[3], n, { m_particle[i].texSup.x, m_particle[i].texInf.y } }; + vertex[3] = { corner[2], n, { m_particle[i].texInf.x, m_particle[i].texInf.y } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); @@ -2938,10 +2938,10 @@ void CParticle::DrawParticleFog(int i) Vertex vertex[4]; - vertex[0] = { corner[1], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texSup.y) }; - vertex[1] = { corner[0], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texSup.y) }; - vertex[2] = { corner[3], n, Math::Point(m_particle[i].texSup.x, m_particle[i].texInf.y) }; - vertex[3] = { corner[2], n, Math::Point(m_particle[i].texInf.x, m_particle[i].texInf.y) }; + vertex[0] = { corner[1], n, { m_particle[i].texSup.x, m_particle[i].texSup.y } }; + vertex[1] = { corner[0], n, { m_particle[i].texInf.x, m_particle[i].texSup.y } }; + vertex[2] = { corner[3], n, { m_particle[i].texSup.x, m_particle[i].texInf.y } }; + vertex[3] = { corner[2], n, { m_particle[i].texInf.x, m_particle[i].texInf.y } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); @@ -2960,7 +2960,7 @@ void CParticle::DrawParticleRay(int i) if (object != nullptr) pos += object->GetPosition(); - float a = Math::RotateAngle(Math::Point(pos.x,pos.z), Math::Point(goal.x,goal.z), Math::Point(eye.x,eye.z)); + 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); @@ -3092,10 +3092,10 @@ void CParticle::DrawParticleRay(int i) if (r % 4 < 2) Math::Swap(texInf.y, texSup.y); - vertex[0] = { corner[1], n, Math::Point(texSup.x, texSup.y) }; - vertex[1] = { corner[0], n, Math::Point(texInf.x, texSup.y) }; - vertex[2] = { corner[3], n, Math::Point(texSup.x, texInf.y) }; - vertex[3] = { corner[2], n, Math::Point(texInf.x, texInf.y) }; + vertex[0] = { corner[1], n, { texSup.x, texSup.y } }; + vertex[1] = { corner[0], n, { texInf.x, texSup.y } }; + vertex[2] = { corner[3], n, { texSup.x, texInf.y } }; + vertex[3] = { corner[2], n, { texInf.x, texInf.y } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); @@ -3192,8 +3192,8 @@ void CParticle::DrawParticleSphere(int i) tu0 = ts.x+(ti.x-ts.x)*tu0; float tu1 = tu0; - vertex[j++] = { v0, v0, Math::Point(tu0, tv0) }; - vertex[j++] = { v1, v1, Math::Point(tu1, tv1) }; + vertex[j++] = { v0, v0, { tu0, tv0 } }; + vertex[j++] = { v1, v1, { tu1, tv1 } }; } } @@ -3287,8 +3287,8 @@ void CParticle::DrawParticleCylinder(int i) tu0 = ts.x+(ti.x-ts.x)*tu0; float tu1 = tu0; - vertex[j++] = { v0, v0, Math::Point(tu0, tv0) }; - vertex[j++] = { v1, v1, Math::Point(tu1, tv1) }; + vertex[j++] = { v0, v0, { tu0, tv0 } }; + vertex[j++] = { v1, v1, { tu1, tv1 } }; } } @@ -3344,10 +3344,10 @@ void CParticle::DrawParticleWheel(int i) ti.y = ti.y-dp; Vertex vertex[4]; - vertex[0] = { pos[0], n, Math::Point(ts.x, ts.y) }; - vertex[1] = { pos[1], n, Math::Point(ti.x, ts.y) }; - vertex[2] = { pos[2], n, Math::Point(ts.x, ti.y) }; - vertex[3] = { pos[3], n, Math::Point(ti.x, ti.y) }; + vertex[0] = { pos[0], n, { ts.x, ts.y } }; + vertex[1] = { pos[1], n, { ti.x, ts.y } }; + vertex[2] = { pos[2], n, { ts.x, ti.y } }; + vertex[3] = { pos[3], n, { ti.x, ti.y } }; m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4, TraceColorColor(m_wheelTrace[i].color)); m_engine->AddStatisticTriangle(2); diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index a998dfe8..7d9242a0 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -176,12 +176,12 @@ struct Particle Math::Vector speed; // speed of displacement float windSensitivity = 0.0f; short bounce = 0; // number of rebounds - Math::Point dim; // dimensions of the rectangle + glm::vec2 dim; // dimensions of the rectangle float zoom = 0.0f; // zoom (0..1) float angle = 0.0f; // angle of rotation float intensity = 0.0f; // intensity - Math::Point texSup; // coordinated upper texture - Math::Point texInf; // coordinated lower texture + glm::vec2 texSup; // coordinated upper texture + glm::vec2 texInf; // coordinated lower texture float time = 0.0f; // age of the particle (0..n) float phaseTime = 0.0f; // age at the beginning of phase float testTime = 0.0f; // time since last test @@ -236,7 +236,7 @@ public: void FlushParticle(int sheet); //! Creates a new particle - int CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, + int CreateParticle(Math::Vector pos, Math::Vector speed, const glm::vec2& dim, ParticleType type, float duration = 1.0f, float mass = 0.0f, float windSensitivity = 1.0f, int sheet = 0); @@ -251,11 +251,11 @@ public: float windSensitivity = 1.0f, int sheet = 0); //! Creates a new linear particle (radius) - int CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim, + int CreateRay(Math::Vector pos, Math::Vector 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, Math::Point dim, ParticleType type, + int CreateTrack(Math::Vector pos, Math::Vector 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 @@ -271,11 +271,11 @@ public: //! Specifies the parent object that created the particle void SetObjectFather(int channel, CObject *object); void SetPosition(int channel, Math::Vector pos); - void SetDimension(int channel, Math::Point dim); + 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, Math::Point dim, float zoom, float angle, float intensity); + void SetParam(int channel, Math::Vector 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 diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index fca61c09..37a993b9 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -306,7 +306,7 @@ void CText::SetTabSize(int tabSize) void CText::DrawText(const std::string &text, std::vector::iterator format, std::vector::iterator end, - float size, Math::Point pos, float width, TextAlign align, + float size, glm::vec2 pos, float width, TextAlign align, int eol, Color color) { float sw = 0.0f; @@ -330,7 +330,7 @@ void CText::DrawText(const std::string &text, std::vector::iterato } void CText::DrawText(const std::string &text, FontType font, - float size, Math::Point pos, float width, TextAlign align, + float size, glm::vec2 pos, float width, TextAlign align, int eol, Color color) { float sw = 0.0f; @@ -355,8 +355,8 @@ void CText::DrawText(const std::string &text, FontType font, void CText::SizeText(const std::string &text, std::vector::iterator format, std::vector::iterator endFormat, - float size, Math::Point pos, TextAlign align, - Math::Point &start, Math::Point &end) + float size, glm::vec2 pos, TextAlign align, + glm::vec2 &start, glm::vec2 &end) { start = end = pos; @@ -378,8 +378,8 @@ void CText::SizeText(const std::string &text, std::vector::iterato } void CText::SizeText(const std::string &text, FontType font, - float size, Math::Point pos, TextAlign align, - Math::Point &start, Math::Point &end) + float size, glm::vec2 pos, TextAlign align, + glm::vec2 &start, glm::vec2 &end) { start = end = pos; @@ -407,7 +407,7 @@ float CText::GetAscent(FontType font, float size) CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); glm::ivec2 wndSize = { 0, TTF_FontAscent(cf->font) }; - Math::Point ifSize = m_engine->WindowToInterfaceSize(wndSize); + glm::vec2 ifSize = m_engine->WindowToInterfaceSize(wndSize); return ifSize.y; } @@ -418,7 +418,7 @@ float CText::GetDescent(FontType font, float size) CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); glm::ivec2 wndSize = { 0, TTF_FontDescent(cf->font) }; - Math::Point ifSize = m_engine->WindowToInterfaceSize(wndSize); + glm::vec2 ifSize = m_engine->WindowToInterfaceSize(wndSize); return ifSize.y; } @@ -429,7 +429,7 @@ float CText::GetHeight(FontType font, float size) CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); glm::ivec2 wndSize = { 0, TTF_FontHeight(cf->font) }; - Math::Point ifSize = m_engine->WindowToInterfaceSize(wndSize); + glm::vec2 ifSize = m_engine->WindowToInterfaceSize(wndSize); return ifSize.y; } @@ -489,7 +489,7 @@ float CText::GetStringWidth(std::string text, FontType font, float size) assert(cf != nullptr); glm::ivec2 wndSize{}; TTF_SizeUTF8(cf->font, text.c_str(), &wndSize.x, &wndSize.y); - Math::Point ifSize = m_engine->WindowToInterfaceSize(wndSize); + glm::vec2 ifSize = m_engine->WindowToInterfaceSize(wndSize); return ifSize.x; } @@ -517,7 +517,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); - Math::Point charSize; + glm::vec2 charSize; auto it = cf->cache.find(ch); if (it != cf->cache.end()) { @@ -1001,7 +1001,7 @@ void CText::DrawHighlight(FontMetaChar hl, const glm::ivec2& pos, const glm::ive else // more than 1024x768? h = 2.0f; // 2 pixels - Math::Point p1, p2; + glm::vec2 p1, p2; p1.x = pos.x; p1.y = pos.y - size.y; p2.x = pos.x + size.x; @@ -1046,7 +1046,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, glm::iv unsigned int texID = m_engine->LoadTexture("textures/interface/button" + StrUtils::ToString((icon/64) + 1) + ".png").id; icon = icon%64; - Math::Point uv1, uv2; + glm::vec2 uv1, uv2; uv1.x = (32.0f / 256.0f) * (icon%8); uv1.y = (32.0f / 256.0f) * (icon/8); uv2.x = (32.0f / 256.0f) + uv1.x; @@ -1088,14 +1088,14 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, glm::iv CharTexture tex = GetCharTexture(ch, font, size); - Math::Point p1(pos.x, pos.y - tex.charSize.y); - Math::Point p2(pos.x + tex.charSize.x, pos.y); + glm::vec2 p1(pos.x, pos.y - tex.charSize.y); + glm::vec2 p2(pos.x + tex.charSize.x, pos.y); const float halfPixelMargin = 0.5f; - Math::Point texCoord1(static_cast(tex.charPos.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, - static_cast(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); - Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x - halfPixelMargin) / FONT_TEXTURE_SIZE.x, - static_cast(tex.charPos.y + tex.charSize.y - halfPixelMargin) / FONT_TEXTURE_SIZE.y); + glm::vec2 texCoord1(static_cast(tex.charPos.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, + static_cast(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); + glm::vec2 texCoord2(static_cast(tex.charPos.x + tex.charSize.x - halfPixelMargin) / FONT_TEXTURE_SIZE.x, + static_cast(tex.charPos.y + tex.charSize.y - halfPixelMargin) / FONT_TEXTURE_SIZE.y); glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 }; diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 84c85baf..99c77258 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -27,8 +27,6 @@ #include "graphics/core/color.h" -#include "math/point.h" - #include #include #include @@ -269,22 +267,22 @@ public: //! Draws text (multi-format) void DrawText(const std::string &text, std::vector::iterator format, std::vector::iterator end, - float size, Math::Point pos, float width, TextAlign align, + float size, glm::vec2 pos, float width, TextAlign align, int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f)); //! Draws text (one font) void DrawText(const std::string &text, FontType font, - float size, Math::Point pos, float width, TextAlign align, + float size, glm::vec2 pos, float width, TextAlign align, int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f)); //! Calculates dimensions for text (multi-format) void SizeText(const std::string &text, std::vector::iterator format, std::vector::iterator endFormat, - float size, Math::Point pos, TextAlign align, - Math::Point &start, Math::Point &end); + float size, glm::vec2 pos, TextAlign align, + glm::vec2&start, glm::vec2&end); //! Calculates dimensions for text (one font) void SizeText(const std::string &text, FontType font, - float size, Math::Point pos, TextAlign align, - Math::Point &start, Math::Point &end); + float size, glm::vec2 pos, TextAlign align, + glm::vec2&start, glm::vec2&end); //! Returns the ascent font metric float GetAscent(FontType font, float size); diff --git a/src/ui/controls/control.h b/src/ui/controls/control.h index d2c1b2f8..c5bd691e 100644 --- a/src/ui/controls/control.h +++ b/src/ui/controls/control.h @@ -23,6 +23,8 @@ #include "graphics/engine/text.h" +#include "math/point.h" + #include class CRobotMain; diff --git a/src/ui/particles_generator.cpp b/src/ui/particles_generator.cpp index e948f630..91c34100 100644 --- a/src/ui/particles_generator.cpp +++ b/src/ui/particles_generator.cpp @@ -28,7 +28,7 @@ namespace UI m_particleManager = Gfx::CEngine::GetInstancePointer()->GetParticle(); } - void CParticlesGenerator::GenerateMouseParticles(Math::Point mousePosition, bool buttonPressed) + void CParticlesGenerator::GenerateMouseParticles(const glm::vec2& mousePosition, bool buttonPressed) { Gfx::ParticleType particleType = buttonPressed ? Gfx::ParticleType::PARTISCRAPS : Gfx::ParticleType::PARTILENS1; m_particleManager->CreateParticle(Math::Vector(mousePosition.x, mousePosition.y, 0), CreateRandomSpeedForMouseParticles(), @@ -36,10 +36,10 @@ namespace UI CreateRandomDurationForMouseParticles(), 2.0f, 0.0f, Gfx::SH_INTERFACE); } - Math::Point CParticlesGenerator::CreateRandomDimensionsForMouseParticles(bool buttonPressed) + glm::vec2 CParticlesGenerator::CreateRandomDimensionsForMouseParticles(bool buttonPressed) { float dimensionX = buttonPressed ? (0.005f + Math::Rand() * 0.005f) : (0.01f + Math::Rand() * 0.01f); - return Math::Point(dimensionX, dimensionX / 0.75f); + return { dimensionX, dimensionX / 0.75f }; } Math::Vector CParticlesGenerator::CreateRandomSpeedForMouseParticles() diff --git a/src/ui/particles_generator.h b/src/ui/particles_generator.h index f1dbc29c..ee8bfbc8 100644 --- a/src/ui/particles_generator.h +++ b/src/ui/particles_generator.h @@ -21,7 +21,6 @@ #include "graphics/engine/particle.h" -#include "math/point.h" #include "math/vector.h" namespace UI @@ -36,10 +35,10 @@ namespace UI /** * \brief generates particles after mouse cursor movement */ - void GenerateMouseParticles(Math::Point mousePosition, bool buttonPressed); + void GenerateMouseParticles(const glm::vec2& mousePosition, bool buttonPressed); private: Gfx::CParticle* m_particleManager; - Math::Point CreateRandomDimensionsForMouseParticles(bool buttonPressed); + glm::vec2 CreateRandomDimensionsForMouseParticles(bool buttonPressed); Math::Vector CreateRandomSpeedForMouseParticles(); float CreateRandomDurationForMouseParticles(); };