From ed28eff066edc11b4af32b6b281108842f6fa28d Mon Sep 17 00:00:00 2001 From: docentYT <63965954+docentYT@users.noreply.github.com> Date: Mon, 27 Apr 2026 00:36:03 +0200 Subject: [PATCH] use glm instead of Math3D in world --- scene/scene.cpp | 2 +- vehicle/Driver.cpp | 6 ++-- world/Segment.cpp | 41 +++++++++++---------- world/Segment.h | 51 +++++++++++--------------- world/Spring.cpp | 9 +++-- world/Spring.h | 5 ++- world/Track.cpp | 90 +++++++++++++++++++++++----------------------- world/Track.h | 4 +-- world/TrkFoll.h | 6 ++-- 9 files changed, 101 insertions(+), 113 deletions(-) diff --git a/scene/scene.cpp b/scene/scene.cpp index d147f0d7..12971b73 100644 --- a/scene/scene.cpp +++ b/scene/scene.cpp @@ -517,7 +517,7 @@ basic_cell::find( glm::dvec3 const &Point, float const Radius, bool const Onlyco std::tuple basic_cell::find( glm::dvec3 const &Point, TTrack const *Exclude ) const { - Math3D::vector3 point { Point.x, Point.y, Point.z }; // sad workaround until math classes unification + glm::dvec3 point{Point.x, Point.y, Point.z}; // sad workaround until math classes unification // TODO: Is it needed? int endpointid; for( auto *path : m_directories.paths ) { diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 9a1f5d84..765fdebe 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -59,12 +59,14 @@ double GetDistanceToEvent(TTrack const *track, basic_event const *event, double double seg_len = scan_dir > 0 ? 0.0 : 1.0; double const dzielnik = 1.0 / segment->GetLength();// rozdzielczosc mniej wiecej 1m int krok = 0; // krok obliczeniowy do sprawdzania czy odwracamy - len2 = (pos_event - segment->FastGetPoint(seg_len)).LengthSquared(); + auto temp = pos_event - segment->FastGetPoint(seg_len); + len2 = glm::dot(temp, temp); do { len1 = len2; seg_len += scan_dir > 0 ? dzielnik : -dzielnik; - len2 = (pos_event - segment->FastGetPoint(seg_len)).LengthSquared(); + temp = pos_event - segment->FastGetPoint(seg_len); + len2 = glm::dot(temp, temp); ++krok; } while ((len1 > len2) && (seg_len >= dzielnik && (seg_len <= (1.0 - dzielnik)))); //trzeba sprawdzić czy seg_len nie osiągnął skrajnych wartości, bo wtedy diff --git a/world/Segment.cpp b/world/Segment.cpp index 8e31ac8a..09d28be5 100644 --- a/world/Segment.cpp +++ b/world/Segment.cpp @@ -37,9 +37,9 @@ TSegment::TSegment(TTrack *owner) : pOwner( owner ) {} -bool TSegment::Init(Math3D::vector3 NewPoint1, Math3D::vector3 NewPoint2, double fNewStep, double fNewRoll1, double fNewRoll2) +bool TSegment::Init(glm::dvec3 NewPoint1, glm::dvec3 NewPoint2, double fNewStep, double fNewRoll1, double fNewRoll2) { // wersja dla prostego - wyliczanie punktów kontrolnych - Math3D::vector3 dir; + glm::dvec3 dir; // NOTE: we're enforcing division also for straight track, to ensure dense enough mesh for per-vertex lighting /* @@ -60,7 +60,7 @@ bool TSegment::Init(Math3D::vector3 NewPoint1, Math3D::vector3 NewPoint2, double } }; -bool TSegment::Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, Math3D::vector3 NewCPointIn, Math3D::vector3 &NewPoint2, double fNewStep, double fNewRoll1, double fNewRoll2, bool bIsCurve) +bool TSegment::Init(glm::dvec3 &NewPoint1, glm::dvec3 NewCPointOut, glm::dvec3 NewCPointIn, glm::dvec3 &NewPoint2, double fNewStep, double fNewRoll1, double fNewRoll2, bool bIsCurve) { // wersja uniwersalna (dla krzywej i prostego) Point1 = NewPoint1; CPointOut = NewCPointOut; @@ -107,7 +107,7 @@ bool TSegment::Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, M fLength = ComputeLength(); } else { - fLength = ( Point1 - Point2 ).Length(); + fLength = glm::length(Point1 - Point2); } if (fLength <= 0) { @@ -142,12 +142,12 @@ bool TSegment::Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, M return true; } -Math3D::vector3 TSegment::GetFirstDerivative(double const fTime) const +glm::dvec3 TSegment::GetFirstDerivative(double const fTime) const { double fOmTime = 1.0 - fTime; double fPowTime = fTime; - Math3D::vector3 kResult = fOmTime * (CPointOut - Point1); + glm::dvec3 kResult = fOmTime * (CPointOut - Point1); // int iDegreeM1 = 3 - 1; @@ -170,14 +170,14 @@ double TSegment::RombergIntegral(double const fA, double const fB) const double ms_apfRom[2][ms_iOrder]; ms_apfRom[0][0] = - 0.5 * fH * ((GetFirstDerivative(fA).Length()) + (GetFirstDerivative(fB).Length())); + 0.5 * fH * ((glm::length(GetFirstDerivative(fA))) + glm::length(GetFirstDerivative(fB))); for (int i0 = 2, iP0 = 1; i0 <= ms_iOrder; i0++, iP0 *= 2, fH *= 0.5) { // approximations via the trapezoid rule double fSum = 0.0; int i1; for (i1 = 1; i1 <= iP0; i1++) - fSum += (GetFirstDerivative(fA + fH * (i1 - 0.5)).Length()); + fSum += glm::length(GetFirstDerivative(fA + fH * (i1 - 0.5))); // Richardson extrapolation ms_apfRom[1][0] = 0.5 * (ms_apfRom[0][0] + fH * fSum); @@ -207,7 +207,7 @@ double TSegment::GetTFromS(double const s) const if( std::abs( fDifference ) < fTolerance ) { return fTime; } - fTime -= fDifference / GetFirstDerivative(fTime).Length(); + fTime -= fDifference / glm::length(GetFirstDerivative(fTime)); ++iteration; } while( iteration < 10 ); // arbitrary limit @@ -220,12 +220,12 @@ double TSegment::GetTFromS(double const s) const return fTime; }; -Math3D::vector3 TSegment::RaInterpolate(double const t) const +glm::dvec3 TSegment::RaInterpolate(double const t) const { // wyliczenie XYZ na krzywej Beziera z użyciem współczynników return t * (t * (t * vA + vB) + vC) + Point1; // 9 mnożeń, 9 dodawań }; -Math3D::vector3 TSegment::RaInterpolate0(double const t) const +glm::dvec3 TSegment::RaInterpolate0(double const t) const { // wyliczenie XYZ na krzywej Beziera, na użytek liczenia długości nie jest dodawane Point1 return t * (t * (t * vA + vB) + vC); // 9 mnożeń, 6 dodawań }; @@ -237,15 +237,15 @@ double TSegment::ComputeLength() const // McZapkie-150503: dlugosc miedzy punkta // poprzedniej // Ra: ewentualnie rozpoznać łuk okręgu płaskiego i liczyć ze wzoru na długość łuku double t, l = 0; - Math3D::vector3 last = Math3D::vector3(0, 0, 0); // długość liczona po przesunięciu odcinka do początku układu - Math3D::vector3 tmp = Point2 - Point1; - int m = 20.0 * tmp.Length(); // było zawsze do 10000, teraz jest liczone odcinkami po około 5cm + glm::dvec3 last{0, 0, 0}; // długość liczona po przesunięciu odcinka do początku układu + glm::dvec3 tmp = Point2 - Point1; + int m = 20.0 * glm::length(tmp); // było zawsze do 10000, teraz jest liczone odcinkami po około 5cm for (int i = 1; i <= m; i++) { t = double(i) / double(m); // wyznaczenie parametru na krzywej z przedziału (0,1> // tmp=Interpolate(t,p1,cp1,cp2,p2); tmp = RaInterpolate0(t); // obliczenie punktu dla tego parametru - t = Math3D::vector3(tmp - last).Length(); // obliczenie długości wektora + t = glm::length(tmp - last); // obliczenie długości wektora l += t; // zwiększenie wyliczanej długości last = tmp; } @@ -296,7 +296,7 @@ TSegment::find_nearest_point( glm::dvec3 const &Point ) const { const double fDirectionOffset = 0.1; // długość wektora do wyliczenia kierunku -Math3D::vector3 TSegment::GetDirection(double const fDistance) const +glm::dvec3 TSegment::GetDirection(double const fDistance) const { // takie toporne liczenie pochodnej dla podanego dystansu od Point1 double t1 = GetTFromS(fDistance - fDirectionOffset); if (t1 <= 0.0) @@ -307,7 +307,7 @@ Math3D::vector3 TSegment::GetDirection(double const fDistance) const return (FastGetPoint(t2) - FastGetPoint(t1)); } -Math3D::vector3 TSegment::FastGetDirection(double fDistance, double fOffset) +glm::dvec3 TSegment::FastGetDirection(double fDistance, double fOffset) { // takie toporne liczenie pochodnej dla parametru 0.0÷1.0 double t1 = fDistance - fOffset; if (t1 <= 0.0) @@ -338,8 +338,7 @@ Math3D::vector3 TSegment::GetPoint(double const fDistance) const }; */ // ustalenie pozycji osi na torze, przechyłki, pochylenia i kierunku jazdy -void TSegment::RaPositionGet(double const fDistance, Math3D::vector3 &p, Math3D::vector3 &a) const { - +void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &p, glm::dvec3 &a) const { if (bCurve) { // można by wprowadzić uproszczony wzór dla okręgów płaskich auto const t = GetTFromS(fDistance); // aproksymacja dystansu na krzywej Beziera na parametr (t) @@ -364,7 +363,7 @@ void TSegment::RaPositionGet(double const fDistance, Math3D::vector3 &p, Math3D: } }; -Math3D::vector3 TSegment::FastGetPoint(double const t) const +glm::dvec3 TSegment::FastGetPoint(double const t) const { // return (bCurve?Interpolate(t,Point1,CPointOut,CPointIn,Point2):((1.0-t)*Point1+(t)*Point2)); return ( @@ -373,7 +372,7 @@ Math3D::vector3 TSegment::FastGetPoint(double const t) const interpolate( Point1, Point2, t ) ); } -bool TSegment::RenderLoft( gfx::vertex_array &Output, Math3D::vector3 const &Origin, const gfx::vertex_array &ShapePoints, bool const Transition, double fTextureLength, double Texturescale, int iSkip, int iEnd, std::pair fOffsetX, glm::vec3 **p, bool bRender) +bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin, const gfx::vertex_array &ShapePoints, bool const Transition, double fTextureLength, double Texturescale, int iSkip, int iEnd, std::pair fOffsetX, glm::vec3 **p, bool bRender) { // generowanie trójkątów dla odcinka trajektorii ruchu // standardowo tworzy triangle_strip dla prostego albo ich zestaw dla łuku // po modyfikacji - dla ujemnego (iNumShapePoints) w dodatkowych polach tabeli podany jest przekrój końcowy diff --git a/world/Segment.h b/world/Segment.h index 3e1b64c1..9da9fcc5 100644 --- a/world/Segment.h +++ b/world/Segment.h @@ -10,9 +10,9 @@ http://mozilla.org/MPL/2.0/. #pragma once #include "utilities/Classes.h" -#include "utilities/dumb3d.h" #include "rendering/geometrybank.h" #include "utilities/utilities.h" +#include struct map_colored_paths { std::vector switches; @@ -42,7 +42,7 @@ struct segment_data { class TSegment { // aproksymacja toru (zwrotnica ma dwa takie, jeden z nich jest aktywny) private: - Math3D::vector3 Point1, CPointOut, CPointIn, Point2; + glm::dvec3 Point1, CPointOut, CPointIn, Point2; float fRoll1 { 0.f }, fRoll2 { 0.f }; // przechyłka na końcach @@ -52,63 +52,54 @@ class TSegment int iSegCount = 0; // ilość odcinków do rysowania krzywej double fDirection = 0.0; // Ra: kąt prostego w planie; dla łuku kąt od Point1 double fStoop = 0.0; // Ra: kąt wzniesienia; dla łuku od Point1 - Math3D::vector3 vA, vB, vC; // współczynniki wielomianów trzeciego stopnia vD==Point1 + glm::dvec3 vA, vB, vC; // współczynniki wielomianów trzeciego stopnia vD==Point1 TTrack *pOwner = nullptr; // wskaźnik na właściciela - Math3D::vector3 - GetFirstDerivative(double const fTime) const; - double - RombergIntegral(double const fA, double const fB) const; - double - GetTFromS(double const s) const; - Math3D::vector3 - RaInterpolate(double const t) const; - Math3D::vector3 - RaInterpolate0(double const t) const; + glm::dvec3 GetFirstDerivative(double const fTime) const; + double RombergIntegral(double const fA, double const fB) const; + double GetTFromS(double const s) const; + glm::dvec3 RaInterpolate(double const t) const; + glm::dvec3 RaInterpolate0(double const t) const; public: bool bCurve = false; TSegment(TTrack *owner); - bool - Init( Math3D::vector3 NewPoint1, Math3D::vector3 NewPoint2, double fNewStep, double fNewRoll1 = 0, double fNewRoll2 = 0); - bool - Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, Math3D::vector3 NewCPointIn, Math3D::vector3 &NewPoint2, double fNewStep, double fNewRoll1 = 0, double fNewRoll2 = 0, bool bIsCurve = true); + bool Init(glm::dvec3 NewPoint1, glm::dvec3 NewPoint2, double fNewStep, double fNewRoll1 = 0, double fNewRoll2 = 0); + bool Init(glm::dvec3 &NewPoint1, glm::dvec3 NewCPointOut, glm::dvec3 NewCPointIn, glm::dvec3 &NewPoint2, double fNewStep, double fNewRoll1 = 0, double fNewRoll2 = 0, bool bIsCurve = true); double ComputeLength() const; // McZapkie-150503 // finds point on segment closest to specified point in 3d space. returns: point on segment as value in range 0-1 double find_nearest_point( glm::dvec3 const &Point ) const; - inline - Math3D::vector3 + inline + glm::dvec3 GetDirection1() const { return bCurve ? CPointOut - Point1 : CPointOut; }; inline - Math3D::vector3 + glm::dvec3 GetDirection2() const { return bCurve ? CPointIn - Point2 : CPointIn; }; - Math3D::vector3 + glm::dvec3 GetDirection(double const fDistance) const; inline - Math3D::vector3 + glm::dvec3 GetDirection() const { return CPointOut; }; - Math3D::vector3 + glm::dvec3 FastGetDirection(double const fDistance, double const fOffset); /* Math3D::vector3 GetPoint(double const fDistance) const; */ - void - RaPositionGet(double const fDistance, Math3D::vector3 &p, Math3D::vector3 &a) const; - Math3D::vector3 - FastGetPoint(double const t) const; + void RaPositionGet(double const fDistance, glm::dvec3 &p, glm::dvec3 &a) const; + glm::dvec3 FastGetPoint(double const t) const; inline - Math3D::vector3 + glm::dvec3 FastGetPoint_0() const { return Point1; }; inline - Math3D::vector3 + glm::dvec3 FastGetPoint_1() const { return Point2; }; inline @@ -123,7 +114,7 @@ public: r2 = fRoll2; } bool - RenderLoft( gfx::vertex_array &Output, Math3D::vector3 const &Origin, gfx::vertex_array const &ShapePoints, bool const Transition, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, std::pair fOffsetX = {0.f, 0.f}, glm::vec3 **p = nullptr, bool bRender = true ); + RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin, gfx::vertex_array const &ShapePoints, bool const Transition, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, std::pair fOffsetX = {0.f, 0.f}, glm::vec3 **p = nullptr, bool bRender = true ); /* void Render(); diff --git a/world/Spring.cpp b/world/Spring.cpp index 05ec3a9b..49992411 100644 --- a/world/Spring.cpp +++ b/world/Spring.cpp @@ -17,15 +17,14 @@ void TSpring::Init(double nKs, double nKd) { kd = Kd; } -Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2) { - - Math3D::vector3 springForce; +glm::dvec3 TSpring::ComputateForces(glm::dvec3 const &pPosition1, glm::dvec3 const &pPosition2) { + glm::vec3 springForce; // p1 = &system[spring->p1]; // p2 = &system[spring->p2]; // VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance auto deltaP = pPosition1 - pPosition2; // dist = VectorLength(&deltaP); // Magnitude of deltaP - auto dist = deltaP.Length(); + auto dist = glm::length(deltaP); if( dist > restLen ) { // Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest) @@ -35,7 +34,7 @@ Math3D::vector3 TSpring::ComputateForces( Math3D::vector3 const &pPosition1, Mat auto deltaV = pPosition1 - pPosition2; // Dterm = (DotProduct(&deltaV,&deltaP) * spring->Kd) / dist; // Damping Term - auto Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist; + auto Dterm = (glm::dot(deltaV,deltaP) * Kd) / dist; //Dterm = 0; // ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector diff --git a/world/Spring.h b/world/Spring.h index d527041d..6800ba29 100644 --- a/world/Spring.h +++ b/world/Spring.h @@ -10,7 +10,6 @@ http://mozilla.org/MPL/2.0/. #ifndef ParticlesH #define ParticlesH -#include "utilities/dumb3d.h" /* #define STATIC_THRESHOLD 0.17f const double m_Kd = 0.02f; // DAMPING FACTOR @@ -28,8 +27,8 @@ public: // void Init(TParticnp1, TParticle *np2, double nKs= 0.5f, double nKd= 0.002f, // double nrestLen= -1.0f); void Init(double nKs = 0.5f, double nKd = 0.002f); - Math3D::vector3 ComputateForces( Math3D::vector3 const &pPosition1, Math3D::vector3 const &pPosition2); -//private: + glm::dvec3 ComputateForces(glm::dvec3 const &pPosition1, glm::dvec3 const &pPosition2); + //private: // members double restLen { 0.01 }; // LENGTH OF SPRING AT REST double Ks { 0.0 }; // SPRING CONSTANT diff --git a/world/Track.cpp b/world/Track.cpp index 22387323..60411db0 100644 --- a/world/Track.cpp +++ b/world/Track.cpp @@ -23,7 +23,6 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/DynObj.h" #include "vehicle/Driver.h" #include "model/AnimModel.h" -#include "world/Track.h" #include "utilities/Timer.h" #include "utilities/Logs.h" #include "rendering/renderer.h" @@ -218,7 +217,7 @@ TTrack * TTrack::Create400m(int what, double dx) trk->m_visible = false; // nie potrzeba pokazywać, zresztą i tak nie ma tekstur trk->iCategoryFlag = what; // taki sam typ plus informacja, że dodatkowy trk->Init(); // utworzenie segmentu - trk->Segment->Init( Math3D::vector3( -dx, 0, 0 ), Math3D::vector3( -dx, 0, 400 ), 10.0, 0, 0 ); // prosty + trk->Segment->Init(glm::dvec3(-dx, 0, 0), glm::dvec3(-dx, 0, 400), 10.0, 0, 0); // prosty trk->location( glm::dvec3{ -dx, 0, 200 } ); //środek, aby się mogło wyświetlić simulation::Paths.insert( trk ); simulation::Region->insert( trk ); @@ -237,7 +236,7 @@ TTrack * TTrack::NullCreate(int dir) trk->iCategoryFlag = (iCategoryFlag & 15) | 0x80; // taki sam typ plus informacja, że dodatkowy float r1, r2; Segment->GetRolls(r1, r2); // pobranie przechyłek na początku toru - Math3D::vector3 p1, cv1, cv2, p2; // będziem tworzyć trajektorię lotu + glm::dvec3 p1, cv1, cv2, p2; // będziem tworzyć trajektorię lotu if (iCategoryFlag & 1) { // tylko dla kolei trk->iDamageFlag = 128; // wykolejenie @@ -247,21 +246,21 @@ TTrack * TTrack::NullCreate(int dir) { //łączenie z nowym torem case 0: p1 = Segment->FastGetPoint_0(); - p2 = p1 - 450.0 * Normalize(Segment->GetDirection1()); + p2 = p1 - 450.0 * glm::normalize(Segment->GetDirection1()); // bo prosty, kontrolne wyliczane przy zmiennej przechyłce trk->Segment->Init(p1, p2, 5, -RadToDeg(r1), 70.0); ConnectPrevPrev(trk, 0); break; case 1: p1 = Segment->FastGetPoint_1(); - p2 = p1 - 450.0 * Normalize(Segment->GetDirection2()); + p2 = p1 - 450.0 * glm::normalize(Segment->GetDirection2()); // bo prosty, kontrolne wyliczane przy zmiennej przechyłce trk->Segment->Init(p1, p2, 5, RadToDeg(r2), 70.0); ConnectNextPrev(trk, 0); break; case 3: // na razie nie możliwe p1 = SwitchExtension->Segments[1]->FastGetPoint_1(); // koniec toru drugiego zwrotnicy - p2 = p1 - 450.0 * Normalize( SwitchExtension->Segments[1]->GetDirection2()); // przedłużenie na wprost + p2 = p1 - 450.0 * glm::normalize(SwitchExtension->Segments[1]->GetDirection2()); // przedłużenie na wprost trk->Segment->Init(p1, p2, 5, RadToDeg(r2), 70.0); // bo prosty, kontrolne wyliczane przy zmiennej przechyłce ConnectNextPrev(trk, 0); // trk->ConnectPrevNext(trk,dir); @@ -288,24 +287,24 @@ TTrack * TTrack::NullCreate(int dir) { //łączenie z nowym torem case 0: p1 = Segment->FastGetPoint_0(); - cv1 = -20.0 * Normalize(Segment->GetDirection1()); // pierwszy wektor kontrolny + cv1 = -20.0 * glm::normalize(Segment->GetDirection1()); // pierwszy wektor kontrolny p2 = p1 + cv1 + cv1; // 40m // bo prosty, kontrolne wyliczane przy zmiennej przechyłce - trk->Segment->Init(p1, p1 + cv1, p2 + Math3D::vector3(-cv1.z, cv1.y, cv1.x), p2, 2, -RadToDeg(r1), 0.0); + trk->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(-cv1.z, cv1.y, cv1.x), p2, 2, -RadToDeg(r1), 0.0); ConnectPrevPrev(trk, 0); // bo prosty, kontrolne wyliczane przy zmiennej przechyłce - trk2->Segment->Init(p1, p1 + cv1, p2 + Math3D::vector3(cv1.z, cv1.y, -cv1.x), p2, 2, -RadToDeg(r1), 0.0); + trk2->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(cv1.z, cv1.y, -cv1.x), p2, 2, -RadToDeg(r1), 0.0); trk2->iPrevDirection = 0; // zwrotnie do tego samego odcinka break; case 1: p1 = Segment->FastGetPoint_1(); - cv1 = -20.0 * Normalize(Segment->GetDirection2()); // pierwszy wektor kontrolny + cv1 = -20.0 * glm::normalize(Segment->GetDirection2()); // pierwszy wektor kontrolny p2 = p1 + cv1 + cv1; // bo prosty, kontrolne wyliczane przy zmiennej przechyłce - trk->Segment->Init(p1, p1 + cv1, p2 + Math3D::vector3(-cv1.z, cv1.y, cv1.x), p2, 2, RadToDeg(r2), 0.0); + trk->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(-cv1.z, cv1.y, cv1.x), p2, 2, RadToDeg(r2), 0.0); ConnectNextPrev(trk, 0); // bo prosty, kontrolne wyliczane przy zmiennej przechyłce - trk2->Segment->Init(p1, p1 + cv1, p2 + Math3D::vector3(cv1.z, cv1.y, -cv1.x), p2, 2, RadToDeg(r2), 0.0); + trk2->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(cv1.z, cv1.y, -cv1.x), p2, 2, RadToDeg(r2), 0.0); trk2->iPrevDirection = 1; // zwrotnie do tego samego odcinka break; } @@ -387,7 +386,7 @@ void TTrack::ConnectNextNext(TTrack *pTrack, int typ) void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) { // pobranie obiektu trajektorii ruchu - Math3D::vector3 pt, vec, p1, p2, cp1, cp2, p3, p4, cp3, cp4; // dodatkowe punkty potrzebne do skrzyżowań + glm::dvec3 pt, vec, p1, p2, cp1, cp2, p3, p4, cp3, cp4; // dodatkowe punkty potrzebne do skrzyżowań double a1, a2, r1, r2, r3, r4; std::string str; size_t i; //,state; //Ra: teraz już nie ma początkowego stanu zwrotnicy we wpisie @@ -560,10 +559,10 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) // na przechyłce doliczyć jeszcze pół przechyłki } - if( ( ( ( p1 + p1 + p2 ) / 3.0 - p1 - cp1 ).Length() < 0.02 ) - || ( ( ( p1 + p2 + p2 ) / 3.0 - p2 + cp1 ).Length() < 0.02 ) ) { + if( (glm::length(( p1 + p1 + p2 ) / 3.0 - p1 - cp1) < 0.02 ) + || ( glm::length(( p1 + p2 + p2 ) / 3.0 - p2 + cp1) < 0.02 ) ) { // "prostowanie" prostych z kontrolnymi, dokładność 2cm - cp1 = cp2 = Math3D::vector3( 0, 0, 0 ); + cp1 = cp2 = glm::dvec3(0, 0, 0); } if( fRadius != 0 ) { @@ -576,22 +575,22 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) } else { // HACK: crude check whether claimed straight is an actual straight piece - if( ( cp1 == Math3D::vector3() ) - && ( cp2 == Math3D::vector3() ) ) { + if ((cp1 == glm::dvec3()) && (cp2 == glm::dvec3())) + { segsize = 10.0; // for straights, 10m per segment works good enough } else { // HACK: divide roughly in 10 segments. segsize = clamp( - ( p1 - p2 ).Length() * 0.1, + glm::length( p1 - p2 ) * 0.1, 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); } } - if( ( cp1 == Math3D::vector3( 0, 0, 0 ) ) - && ( cp2 == Math3D::vector3( 0, 0, 0 ) ) ) { + if ((cp1 == glm::dvec3()) && (cp2 == glm::dvec3())) + { // Ra: hm, czasem dla prostego są podane... // gdy prosty, kontrolne wyliczane przy zmiennej przechyłce Segment->Init( p1, p2, segsize, r1, r2 ); @@ -656,10 +655,10 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( eType != tt_Cross ) { // dla skrzyżowań muszą być podane kontrolne - if( ( ( ( p1 + p1 + p2 ) / 3.0 - p1 - cp1 ).Length() < 0.02 ) - || ( ( ( p1 + p2 + p2 ) / 3.0 - p2 + cp1 ).Length() < 0.02 ) ) { + if( ( glm::length(( p1 + p1 + p2 ) / 3.0 - p1 - cp1 ) < 0.02 ) + || ( glm::length(( p1 + p2 + p2 ) / 3.0 - p2 + cp1 ) < 0.02 ) ) { // "prostowanie" prostych z kontrolnymi, dokładność 2cm - cp1 = cp2 = Math3D::vector3( 0, 0, 0 ); + cp1 = cp2 = glm::dvec3(0, 0, 0); } } @@ -673,22 +672,22 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) } else { // HACK: crude check whether claimed straight is an actual straight piece - if( ( cp1 == Math3D::vector3() ) - && ( cp2 == Math3D::vector3() ) ) { + if ((cp1 == glm::dvec3()) && (cp2 == glm::dvec3())) + { segsize = 10.0; // for straights, 10m per segment works good enough } else { // HACK: divide roughly in 10 segments. segsize = clamp( - ( p1 - p2 ).Length() * 0.1, + glm::length( p1 - p2 ) * 0.1, 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); } } - if( ( cp1 == Math3D::vector3( 0, 0, 0 ) ) - && ( cp2 == Math3D::vector3( 0, 0, 0 ) ) ) { + if ((cp1 == glm::dvec3()) && (cp2 == glm::dvec3())) + { // Ra: hm, czasem dla prostego są podane... // gdy prosty, kontrolne wyliczane przy zmiennej przechyłce SwitchExtension->Segments[ 0 ]->Init( p1, p2, segsize, r1, r2 ); @@ -720,10 +719,10 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( eType != tt_Cross ) { // dla skrzyżowań muszą być podane kontrolne - if( ( ( ( p3 + p3 + p4 ) / 3.0 - p3 - cp3 ).Length() < 0.02 ) - || ( ( ( p3 + p4 + p4 ) / 3.0 - p4 + cp3 ).Length() < 0.02 ) ) { + if( ( glm::length(( p3 + p3 + p4 ) / 3.0 - p3 - cp3) < 0.02 ) + || ( glm::length(( p3 + p4 + p4 ) / 3.0 - p4 + cp3) < 0.02 ) ) { // "prostowanie" prostych z kontrolnymi, dokładność 2cm - cp3 = cp4 = Math3D::vector3( 0, 0, 0 ); + cp3 = cp4 = glm::dvec3(0, 0, 0); } } @@ -737,22 +736,22 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) } else { // HACK: crude check whether claimed straight is an actual straight piece - if( ( cp3 == Math3D::vector3() ) - && ( cp4 == Math3D::vector3() ) ) { + if ((cp3 == glm::dvec3()) && (cp4 == glm::dvec3())) + { segsize = 10.0; // for straights, 10m per segment works good enough } else { // HACK: divide roughly in 10 segments. segsize = clamp( - ( p3 - p4 ).Length() * 0.1, + glm::length( p3 - p4 ) * 0.1, 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); } } - if( ( cp3 == Math3D::vector3( 0, 0, 0 ) ) - && ( cp4 == Math3D::vector3( 0, 0, 0 ) ) ) { + if ((cp3 == glm::dvec3()) && (cp4 == glm::dvec3())) + { // Ra: hm, czasem dla prostego są podane... // gdy prosty, kontrolne wyliczane przy zmiennej przechyłce SwitchExtension->Segments[ 1 ]->Init( p3, p4, segsize, r3, r4 ); @@ -770,7 +769,8 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if (eType == tt_Cross) { // Ra 2014-07: dla skrzyżowań będą dodatkowe segmenty SwitchExtension->Segments[2]->Init(p2, cp2 + p2, cp4 + p4, p4, segsize, r2, r4); // z punktu 2 do 4 - if (LengthSquared3(p3 - p1) < 0.01) // gdy mniej niż 10cm, to mamy skrzyżowanie trzech dróg + auto p1p3 = p3 - p1; + if (glm::dot(p1p3, p1p3) < 0.01) // gdy mniej niż 10cm, to mamy skrzyżowanie trzech dróg SwitchExtension->iRoads = 3; else // dla 4 dróg będą dodatkowe 3 segmenty { @@ -785,7 +785,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( eType == tt_Switch ) // Ra: zamienić później na iloczyn wektorowy { - Math3D::vector3 v1, v2; + glm::dvec3 v1, v2; double a1, a2; v1 = SwitchExtension->Segments[0]->FastGetPoint_1() - SwitchExtension->Segments[0]->FastGetPoint_0(); @@ -1517,14 +1517,14 @@ void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) { case tt_Cross: // skrzyżowanie dróg rysujemy inaczej { // ustalenie współrzędnych środka - przecięcie Point1-Point2 z CV4-Point4 double a[4]; // kąty osi ulic wchodzących - Math3D::vector3 p[4]; // punkty się przydadzą do obliczeń + glm::dvec3 p[4]; // punkty się przydadzą do obliczeń // na razie połowa odległości pomiędzy Point1 i Point2, potem się dopracuje a[0] = a[1] = 0.5; // parametr do poszukiwania przecięcia łuków // modyfikować a[0] i a[1] tak, aby trafić na przecięcie odcinka 34 p[0] = SwitchExtension->Segments[0]->FastGetPoint(a[0]); // współrzędne środka pierwszego odcinka p[1] = SwitchExtension->Segments[1]->FastGetPoint(a[1]); //-//- drugiego // p[2]=p[1]-p[0]; //jeśli różne od zera, przeliczyć a[0] i a[1] i wyznaczyć nowe punkty - Math3D::vector3 oxz = p[0]; // punkt mapowania środka tekstury skrzyżowania + glm::dvec3 oxz = p[0]; // punkt mapowania środka tekstury skrzyżowania p[0] = SwitchExtension->Segments[0]->GetDirection1(); // Point1 - pobranie wektorów kontrolnych p[1] = SwitchExtension->Segments[1]->GetDirection2(); // Point3 (bo zamienione) p[2] = SwitchExtension->Segments[0]->GetDirection2(); // Point2 @@ -2042,9 +2042,7 @@ TTrack * TTrack::RaAnimate() cosa = -hlen * std::cos( glm::radians( SwitchExtension->fOffset ) ); SwitchExtension->vTrans = ac->TransGet(); auto middle = location() + SwitchExtension->vTrans; // SwitchExtension->Segments[0]->FastGetPoint(0.5); - Segment->Init( - middle + Math3D::vector3( sina, 0.0, cosa ), - middle - Math3D::vector3( sina, 0.0, cosa ), + Segment->Init(middle + glm::dvec3(sina, 0.0, cosa), middle - glm::dvec3(sina, 0.0, cosa), 10.0 ); // nowy odcinek for( auto dynamic : Dynamics ) { // minimalny ruch, aby przeliczyć pozycję @@ -2086,7 +2084,7 @@ bool TTrack::IsGroupable() return true; }; -bool Equal( Math3D::vector3 v1, Math3D::vector3 *v2) +bool Equal(glm::dvec3 v1, glm::dvec3 *v2) { // sprawdzenie odległości punktów // Ra: powinno być do 100cm wzdłuż toru i ze 2cm w poprzek (na prostej może nie być długiego // kawałka) @@ -2101,7 +2099,7 @@ bool Equal( Math3D::vector3 v1, Math3D::vector3 *v2) // return (SquareMagnitude(v1-*v2)<0.00012); //0.011^2=0.00012 }; -int TTrack::TestPoint( Math3D::vector3 *Point) +int TTrack::TestPoint(glm::dvec3 *Point) { // sprawdzanie, czy tory można połączyć switch (eType) { diff --git a/world/Track.h b/world/Track.h index ffc622db..04d78496 100644 --- a/world/Track.h +++ b/world/Track.h @@ -92,7 +92,7 @@ class TSwitchExtension basic_event *evPlus = nullptr, *evMinus = nullptr; // zdarzenia sygnalizacji rozprucia float fVelocity = -1.0; // maksymalne ograniczenie prędkości (ustawianej eventem) - Math3D::vector3 vTrans; // docelowa translacja przesuwnicy + glm::dvec3 vTrans; // docelowa translacja przesuwnicy material_handle m_material3 = 0; // texture of auto generated switch trackbed gfx::geometry_handle Geometry3; // geometry of auto generated switch trackbed @@ -308,7 +308,7 @@ public: } double WidthTotal(); bool IsGroupable(); - int TestPoint( Math3D::vector3 *Point); + int TestPoint(glm::dvec3 *Point); void MovedUp1(float const dh); void VelocitySet(float v); double VelocityGet(); diff --git a/world/TrkFoll.h b/world/TrkFoll.h index 3bcea7ae..7276fcd4 100644 --- a/world/TrkFoll.h +++ b/world/TrkFoll.h @@ -44,9 +44,9 @@ public: void Render(float fNr); // members double fOffsetH = 0.0; // Ra: odległość środka osi od osi toru (dla samochodów) - użyć do wężykowania - Math3D::vector3 pPosition; // współrzędne XYZ w układzie scenerii - Math3D::vector3 vAngles; // x:przechyłka, y:pochylenie, z:kierunek w planie (w radianach) -private: + glm::dvec3 pPosition; // współrzędne XYZ w układzie scenerii + glm::dvec3 vAngles; // x:przechyłka, y:pochylenie, z:kierunek w planie (w radianach) + private: // methods bool ComputatePosition(); // przeliczenie pozycji na torze // members