fixed trackbed normal generation

This commit is contained in:
tmj-fstate
2017-09-16 16:59:20 +02:00
parent 6c69a5b8f1
commit 5c08631c7f
5 changed files with 802 additions and 472 deletions

View File

@@ -77,16 +77,9 @@ class TAnimContainer
TAnimContainer();
~TAnimContainer();
bool Init(TSubModel *pNewSubModel);
// std::string inline GetName() { return
// std::string(pSubModel?pSubModel->asName.c_str():""); };
// std::string inline GetName() { return std::string(pSubModel?pSubModel->pName:"");
// };
std::string NameGet()
{
return (pSubModel ? pSubModel->pName : "");
};
// void SetRotateAnim(vector3 vNewRotateAxis, double fNewDesiredAngle, double
// fNewRotateSpeed, bool bResetAngle=false);
inline
std::string NameGet() {
return (pSubModel ? pSubModel->pName : ""); };
void SetRotateAnim(vector3 vNewRotateAngles, double fNewRotateSpeed);
void SetTranslateAnim(vector3 vNewTranslate, double fNewSpeed);
void AnimSetVMD(double fNewSpeed);
@@ -94,24 +87,20 @@ class TAnimContainer
void UpdateModel();
void UpdateModelIK();
bool InMovement(); // czy w trakcie animacji?
double _fastcall AngleGet()
{
return vRotateAngles.z;
}; // jednak ostatnia, T3D ma inny układ
vector3 _fastcall TransGet()
{
return vector3(-vTranslation.x, vTranslation.z, vTranslation.y);
}; // zmiana, bo T3D ma inny układ
void WillBeAnimated()
{
inline
double AngleGet() {
return vRotateAngles.z; }; // jednak ostatnia, T3D ma inny układ
inline
vector3 TransGet() {
return vector3(-vTranslation.x, vTranslation.z, vTranslation.y); }; // zmiana, bo T3D ma inny układ
inline
void WillBeAnimated() {
if (pSubModel)
pSubModel->WillBeAnimated();
};
pSubModel->WillBeAnimated(); };
void EventAssign(TEvent *ev);
TEvent * Event()
{
return evDone;
};
inline
TEvent * Event() {
return evDone; };
};
class TAnimAdvanced

View File

@@ -59,8 +59,8 @@ bool TSegment::Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, M
CPointIn = NewCPointIn;
Point2 = NewPoint2;
// poprawienie przechyłki
fRoll1 = DegToRad(fNewRoll1); // Ra: przeliczone jest bardziej przydatne do obliczeń
fRoll2 = DegToRad(fNewRoll2);
fRoll1 = glm::radians(fNewRoll1); // Ra: przeliczone jest bardziej przydatne do obliczeń
fRoll2 = glm::radians(fNewRoll2);
if (Global::bRollFix)
{ // Ra: poprawianie przechyłki
// Przechyłka powinna być na środku wewnętrznej szyny, a standardowo jest w osi
@@ -78,7 +78,7 @@ bool TSegment::Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, M
CPointOut.y += w1; // prosty ma wektory jednostkowe
pOwner->MovedUp1(w1); // zwrócić trzeba informację o podwyższeniu podsypki
}
if (fRoll2 != 0.0)
if (fRoll2 != 0.f)
{
double w2 = std::abs(std::sin(fRoll2) * 0.75); // 0.5*w2+0.0325; //0.75m dla 1.435
Point2.y += w2; // modyfikacja musi być przed policzeniem dalszych parametrów
@@ -87,9 +87,9 @@ bool TSegment::Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, M
// zwrócić trzeba informację o podwyższeniu podsypki
}
}
// kąt w planie, żeby nie liczyć wielokrotnie
// Ra: ten kąt jeszcze do przemyślenia jest
fDirection = -atan2(Point2.x - Point1.x,
Point2.z - Point1.z); // kąt w planie, żeby nie liczyć wielokrotnie
fDirection = -std::atan2(Point2.x - Point1.x, Point2.z - Point1.z);
bCurve = bIsCurve;
if (bCurve)
{ // przeliczenie współczynników wielomianu, będzie mniej mnożeń i można policzyć pochodne
@@ -101,10 +101,9 @@ bool TSegment::Init( Math3D::vector3 &NewPoint1, Math3D::vector3 NewCPointOut, M
else
fLength = (Point1 - Point2).Length();
fStep = fNewStep;
if (fLength <= 0)
{
if (fLength <= 0) {
ErrorLog( "Bad geometry: zero length spline \"" + pOwner->NameGet() + "\" (location: " + to_string( glm::dvec3{ Point1 } ) + ")" );
// MessageBox(0,"Length<=0","TSegment::Init",MB_OK);
fLength = 0.01; // crude workaround TODO: fix this properly
/*
return false; // zerowe nie mogą być
@@ -355,7 +354,7 @@ Math3D::vector3 TSegment::FastGetPoint(double const t) const
interpolate( Point1, Point2, t ) );
}
bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin, const vector6 *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale, int iSkip, int iEnd, double fOffsetX, Math3D::vector3 **p, bool bRender)
bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin, const basic_vertex *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale, int iSkip, int iEnd, float 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
@@ -365,13 +364,14 @@ bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin,
if( !fTsBuffer )
return false; // prowizoryczne zabezpieczenie przed wysypem - ustalić faktyczną przyczynę
Math3D::vector3 pos1, pos2, dir, parallel1, parallel2, pt, norm;
double s, step, fOffset, tv1, tv2, t, fEnd;
glm::vec3 pos1, pos2, dir, parallel1, parallel2, pt, norm;
float s, step, fOffset, tv1, tv2, t, fEnd;
bool const trapez = iNumShapePoints < 0; // sygnalizacja trapezowatości
iNumShapePoints = std::abs( iNumShapePoints );
fTextureLength *= Texturescale;
float const texturelength = fTextureLength * Texturescale;
float const texturescale = Texturescale;
double m1, jmm1, m2, jmm2; // pozycje względne na odcinku 0...1 (ale nie parametr Beziera)
float m1, jmm1, m2, jmm2; // pozycje względne na odcinku 0...1 (ale nie parametr Beziera)
step = fStep;
tv1 = 1.0; // Ra: to by można było wyliczać dla odcinka, wyglądało by lepiej
s = fStep * iSkip; // iSkip - ile odcinków z początku pominąć
@@ -379,9 +379,9 @@ bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin,
t = fTsBuffer[ i ]; // tabela wattości t dla segmentów
// BUG: length of spline can be 0, we should skip geometry generation for such cases
fOffset = 0.1 / fLength; // pierwsze 10cm
pos1 = FastGetPoint( t ); // wektor początku segmentu
dir = FastGetDirection( t, fOffset ); // wektor kierunku
parallel1 = Normalize( Math3D::vector3( -dir.z, 0.0, dir.x ) ); // wektor poprzeczny
pos1 = glm::dvec3{ FastGetPoint( t ) - Origin }; // wektor początku segmentu
dir = glm::dvec3{ FastGetDirection( t, fOffset ) }; // wektor kierunku
parallel1 = glm::normalize( glm::vec3{ -dir.z, 0.f, dir.x } ); // wektor poprzeczny
if( iEnd == 0 )
iEnd = iSegCount;
fEnd = fLength * double( iEnd ) / double( iSegCount );
@@ -406,26 +406,26 @@ bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin,
while( tv1 < 0.0 ) {
tv1 += 1.0;
}
tv2 = tv1 - step / fTextureLength; // mapowanie na końcu segmentu
tv2 = tv1 - step / texturelength; // mapowanie na końcu segmentu
t = fTsBuffer[ i ]; // szybsze od GetTFromS(s);
pos2 = FastGetPoint( t );
dir = FastGetDirection( t, fOffset ); // nowy wektor kierunku
parallel2 = Normalize( Math3D::vector3( -dir.z, 0.0, dir.x ) ); // wektor poprzeczny
pos2 = glm::dvec3{ FastGetPoint( t ) - Origin };
dir = glm::dvec3{ FastGetDirection( t, fOffset ) }; // nowy wektor kierunku
parallel2 = glm::normalize( glm::vec3{ -dir.z, 0.f, dir.x } ); // wektor poprzeczny
if( trapez ) {
for( int j = 0; j < iNumShapePoints; ++j ) {
pt = parallel1 * ( jmm1 * ( ShapePoints[ j ].x - fOffsetX ) + m1 * ShapePoints[ j + iNumShapePoints ].x ) + pos1;
pt.y += jmm1 * ShapePoints[ j ].y + m1 * ShapePoints[ j + iNumShapePoints ].y;
pt -= Origin;
norm = ( jmm1 * ShapePoints[ j ].n.x + m1 * ShapePoints[ j + iNumShapePoints ].n.x ) * parallel1;
norm.y += jmm1 * ShapePoints[ j ].n.y + m1 * ShapePoints[ j + iNumShapePoints ].n.y;
pt = parallel1 * ( jmm1 * ( ShapePoints[ j ].position.x - fOffsetX ) + m1 * ShapePoints[ j + iNumShapePoints ].position.x ) + pos1;
pt.y += jmm1 * ShapePoints[ j ].position.y + m1 * ShapePoints[ j + iNumShapePoints ].position.y;
// pt -= Origin;
norm = ( jmm1 * ShapePoints[ j ].normal.x + m1 * ShapePoints[ j + iNumShapePoints ].normal.x ) * parallel1;
norm.y += jmm1 * ShapePoints[ j ].normal.y + m1 * ShapePoints[ j + iNumShapePoints ].normal.y;
if( bRender ) {
// skrzyżowania podczas łączenia siatek mogą nie renderować poboczy, ale potrzebować punktów
Output.emplace_back(
glm::vec3 { pt.x, pt.y, pt.z },
glm::vec3 { norm.x, norm.y, norm.z },
glm::vec2 { ( jmm1 * ShapePoints[ j ].z + m1 * ShapePoints[ j + iNumShapePoints ].z ) / Texturescale, tv1 } );
pt,
glm::normalize( norm ),
glm::vec2 { ( jmm1 * ShapePoints[ j ].texture.x + m1 * ShapePoints[ j + iNumShapePoints ].texture.x ) / texturescale, tv1 } );
}
if( p ) // jeśli jest wskaźnik do tablicy
if( *p )
@@ -435,17 +435,17 @@ bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin,
( *p )++;
} // zapamiętanie brzegu jezdni
// dla trapezu drugi koniec ma inne współrzędne
pt = parallel2 * ( jmm2 * ( ShapePoints[ j ].x - fOffsetX ) + m2 * ShapePoints[ j + iNumShapePoints ].x ) + pos2;
pt.y += jmm2 * ShapePoints[ j ].y + m2 * ShapePoints[ j + iNumShapePoints ].y;
pt -= Origin;
norm = ( jmm1 * ShapePoints[ j ].n.x + m1 * ShapePoints[ j + iNumShapePoints ].n.x ) * parallel2;
norm.y += jmm1 * ShapePoints[ j ].n.y + m1 * ShapePoints[ j + iNumShapePoints ].n.y;
pt = parallel2 * ( jmm2 * ( ShapePoints[ j ].position.x - fOffsetX ) + m2 * ShapePoints[ j + iNumShapePoints ].position.x ) + pos2;
pt.y += jmm2 * ShapePoints[ j ].position.y + m2 * ShapePoints[ j + iNumShapePoints ].position.y;
// pt -= Origin;
norm = ( jmm1 * ShapePoints[ j ].normal.x + m1 * ShapePoints[ j + iNumShapePoints ].normal.x ) * parallel2;
norm.y += jmm1 * ShapePoints[ j ].normal.y + m1 * ShapePoints[ j + iNumShapePoints ].normal.y;
if( bRender ) {
// skrzyżowania podczas łączenia siatek mogą nie renderować poboczy, ale potrzebować punktów
Output.emplace_back(
glm::vec3 { pt.x, pt.y, pt.z },
glm::vec3 { norm.x, norm.y, norm.z },
glm::vec2 { ( jmm2 * ShapePoints[ j ].z + m2 * ShapePoints[ j + iNumShapePoints ].z ) / Texturescale, tv2 } );
pt,
glm::normalize( norm ),
glm::vec2 { ( jmm2 * ShapePoints[ j ].texture.x + m2 * ShapePoints[ j + iNumShapePoints ].texture.x ) / texturescale, tv2 } );
}
if( p ) // jeśli jest wskaźnik do tablicy
if( *p )
@@ -460,27 +460,27 @@ bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin,
if( bRender ) {
for( int j = 0; j < iNumShapePoints; ++j ) {
//łuk z jednym profilem
pt = parallel1 * ( ShapePoints[ j ].x - fOffsetX ) + pos1;
pt.y += ShapePoints[ j ].y;
pt -= Origin;
norm = ShapePoints[ j ].n.x * parallel1;
norm.y += ShapePoints[ j ].n.y;
pt = parallel1 * ( ShapePoints[ j ].position.x - fOffsetX ) + pos1;
pt.y += ShapePoints[ j ].position.y;
// pt -= Origin;
norm = ShapePoints[ j ].normal.x * parallel1;
norm.y += ShapePoints[ j ].normal.y;
Output.emplace_back(
glm::vec3 { pt.x, pt.y, pt.z },
glm::vec3 { norm.x, norm.y, norm.z },
glm::vec2 { ShapePoints[ j ].z / Texturescale, tv1 } );
pt,
glm::normalize( norm ),
glm::vec2 { ShapePoints[ j ].texture.x / texturescale, tv1 } );
pt = parallel2 * ShapePoints[ j ].x + pos2;
pt.y += ShapePoints[ j ].y;
pt -= Origin;
norm = ShapePoints[ j ].n.x * parallel2;
norm.y += ShapePoints[ j ].n.y;
pt = parallel2 * ShapePoints[ j ].position.x + pos2;
pt.y += ShapePoints[ j ].position.y;
// pt -= Origin;
norm = ShapePoints[ j ].normal.x * parallel2;
norm.y += ShapePoints[ j ].normal.y;
Output.emplace_back(
glm::vec3 { pt.x, pt.y, pt.z },
glm::vec3 { norm.x, norm.y, norm.z },
glm::vec2 { ShapePoints[ j ].z / Texturescale, tv2 } );
pt,
glm::normalize( norm ),
glm::vec2 { ShapePoints[ j ].texture.x / texturescale, tv2 } );
}
}
}

View File

@@ -15,7 +15,7 @@ http://mozilla.org/MPL/2.0/.
#include "usefull.h"
// 110405 Ra: klasa punktów przekroju z normalnymi
/*
class vector6 : public Math3D::vector3
{ // punkt przekroju wraz z wektorem normalnym
public:
@@ -26,7 +26,6 @@ class vector6 : public Math3D::vector3
n.y = 1.0;
};
vector6(double a, double b, double c, double d, double e, double f)
//{x=a; y=b; z=c; n.x=d; n.y=e; n.z=f;};
{
x = a;
y = b;
@@ -45,13 +44,14 @@ class vector6 : public Math3D::vector3
n.z = 0.0;
};
};
*/
class TSegment
{ // aproksymacja toru (zwrotnica ma dwa takie, jeden z nich jest aktywny)
private:
Math3D::vector3 Point1, CPointOut, CPointIn, Point2;
double fRoll1 = 0.0,
fRoll2 = 0.0; // przechyłka na końcach
float
fRoll1{ 0.f },
fRoll2{ 0.f }; // przechyłka na końcach
double fLength = 0.0; // długość policzona
double *fTsBuffer = nullptr; // wartości parametru krzywej dla równych odcinków
double fStep = 0.0;
@@ -118,18 +118,18 @@ public:
FastGetPoint_1() const {
return Point2; };
inline
double
float
GetRoll(double const Distance) const {
return interpolate( fRoll1, fRoll2, Distance / fLength ); }
return interpolate( fRoll1, fRoll2, static_cast<float>(Distance / fLength) ); }
inline
void
GetRolls(double &r1, double &r2) const {
GetRolls(float &r1, float &r2) const {
// pobranie przechyłek (do generowania trójkątów)
r1 = fRoll1;
r2 = fRoll2; }
bool
RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin, vector6 const *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, double fOffsetX = 0.0, Math3D::vector3 **p = nullptr, bool bRender = true);
RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin, basic_vertex const *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, float fOffsetX = 0.f, glm::vec3 **p = nullptr, bool bRender = true);
void
Render();
inline

1062
Track.cpp

File diff suppressed because it is too large Load Diff

49
Track.h
View File

@@ -10,23 +10,23 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include <string>
#include "GL/glew.h"
#include "ResourceManager.h"
#include <vector>
#include <deque>
#include "Segment.h"
#include "material.h"
typedef enum
{
enum TTrackType {
tt_Unknown,
tt_Normal,
tt_Switch,
tt_Table,
tt_Cross,
tt_Tributary
} TTrackType;
};
// McZapkie-100502
typedef enum
{
enum TEnvironmentType {
e_unknown = -1,
e_flat = 0,
e_mountains,
@@ -34,7 +34,7 @@ typedef enum
e_tunnel,
e_bridge,
e_bank
} TEnvironmentType;
};
// Ra: opracować alternatywny system cieni/świateł z definiowaniem koloru oświetlenia w halach
class TEvent;
@@ -49,23 +49,22 @@ class TSwitchExtension
TSwitchExtension(TTrack *owner, int const what);
~TSwitchExtension();
std::shared_ptr<TSegment> Segments[6]; // dwa tory od punktu 1, pozosta³e dwa od 2? Ra 140101: 6 po³¹czeñ dla skrzy¿owañ
// TTrack *trNear[4]; //tory do³¹czone do punktów 1, 2, 3 i 4
// dotychczasowe [2]+[2] wskaŸniki zamieniæ na nowe [4]
TTrack *pNexts[2]; // tory do³¹czone do punktów 2 i 4
TTrack *pPrevs[2]; // tory do³¹czone do punktów 1 i 3
int iNextDirection[2]; // to te¿ z [2]+[2] przerobiæ na [4]
int iPrevDirection[2];
int CurrentIndex = 0; // dla zwrotnicy
double fOffset = 0.0,
fDesiredOffset = 0.0; // aktualne i docelowe położenie napędu iglic
double fOffsetSpeed = 0.1; // prędkość liniowa ruchu iglic
double fOffsetDelay = 0.05; // opóźnienie ruchu drugiej iglicy względem pierwszej // dodatkowy ruch drugiej iglicy po zablokowaniu pierwszej na opornicy
float
fOffset{ 0.f },
fDesiredOffset{ 0.f }; // aktualne i docelowe położenie napędu iglic
float fOffsetSpeed = 0.1f; // prędkość liniowa ruchu iglic
float fOffsetDelay = 0.05f; // opóźnienie ruchu drugiej iglicy względem pierwszej // dodatkowy ruch drugiej iglicy po zablokowaniu pierwszej na opornicy
union
{
struct
{ // zmienne potrzebne tylko dla zwrotnicy
double fOffset1,
fOffset2; // przesunięcia iglic - 0=na wprost
float fOffset1,
fOffset2; // przesunięcia iglic - 0=na wprost
bool RightSwitch; // czy zwrotnica w prawo
};
struct
@@ -77,21 +76,17 @@ class TSwitchExtension
struct
{ // zmienne dla skrzyżowania
int iRoads; // ile dróg się spotyka?
Math3D::vector3 *vPoints; // tablica wierzchołków nawierzchni, generowana przez pobocze
// int iPoints; // liczba faktycznie użytych wierzchołków nawierzchni
glm::vec3 *vPoints; // tablica wierzchołków nawierzchni, generowana przez pobocze
bool bPoints; // czy utworzone?
};
};
bool bMovement = false; // czy w trakcie animacji
int iLeftVBO = 0,
iRightVBO = 0; // indeksy iglic w VBO
TSubRect *pOwner = nullptr; // sektor, któremu trzeba zgłosić animację
TTrack *pNextAnim = nullptr; // następny tor do animowania
TEvent *evPlus = nullptr,
*evMinus = nullptr; // zdarzenia sygnalizacji rozprucia
float fVelocity = -1.0; // maksymalne ograniczenie prędkości (ustawianej eventem)
Math3D::vector3 vTrans; // docelowa translacja przesuwnicy
private:
};
class TIsolated
@@ -106,7 +101,6 @@ class TIsolated
TMemCell *pMemCell = nullptr; // automatyczna komórka pamięci, która współpracuje z odcinkiem izolowanym
TIsolated();
TIsolated(const std::string &n, TIsolated *i);
~TIsolated();
static TIsolated * Find(const std::string &n); // znalezienie obiektu albo utworzenie nowego
void Modify(int i, TDynamicObject *o); // dodanie lub odjęcie osi
bool Busy() {
@@ -118,7 +112,7 @@ class TIsolated
};
// trajektoria ruchu - opakowanie
class TTrack /*: public Resource*/ {
class TTrack {
friend class opengl_renderer;
@@ -207,7 +201,7 @@ public:
return trPrev; };
TTrack *Connected(int s, double &d) const;
bool SetConnections(int i);
bool Switch(int i, double t = -1.0, double d = -1.0);
bool Switch(int i, float const t = -1.f, float const d = -1.f);
bool SwitchForced(int i, TDynamicObject *o);
int CrossSegment(int from, int into);
inline int GetSwitchState() {
@@ -241,17 +235,12 @@ public:
std::string IsolatedName();
bool IsolatedEventsAssign(TEvent *busy, TEvent *free);
double WidthTotal();
GLuint TextureGet(int i) {
return (
i ?
m_material1 :
m_material2 ); };
bool IsGroupable();
int TestPoint( Math3D::vector3 *Point);
void MovedUp1(float const dh);
std::string NameGet();
void VelocitySet(float v);
float VelocityGet();
double VelocityGet();
void ConnectionsLog();
private: