16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 17:29:18 +02:00

fixes for display list path camera-centric rendering, basic support for binary terrain object type, fix for assignment of 3d objects to terrain cells

This commit is contained in:
tmj-fstate
2017-05-26 21:22:13 +02:00
parent 2b6ea903bc
commit 3068cc669e
8 changed files with 150 additions and 112 deletions

View File

@@ -255,9 +255,9 @@ void TGroundNode::RaRenderVBO()
glDrawArrays(iType, iVboPtr, iNumVerts); // Narysuj naraz wszystkie trójkąty glDrawArrays(iType, iVboPtr, iNumVerts); // Narysuj naraz wszystkie trójkąty
} }
void TGroundNode::Compile(bool many) void TGroundNode::Compile( Math3D::vector3 const &Origin, bool const Multiple )
{ // tworzenie skompilowanej listy w wyświetlaniu DL { // tworzenie skompilowanej listy w wyświetlaniu DL
if (!many) if (false == Multiple)
{ // obsługa pojedynczej listy { // obsługa pojedynczej listy
if (DisplayListID) if (DisplayListID)
Release(); Release();
@@ -273,9 +273,9 @@ void TGroundNode::Compile(bool many)
glBegin(iType); glBegin(iType);
for (int i = 0; i < iNumPts; ++i) for (int i = 0; i < iNumPts; ++i)
glVertex3d( glVertex3d(
Points[i].x - m_rootposition.x, Points[i].x - Origin.x,
Points[i].y - m_rootposition.y, Points[i].y - Origin.y,
Points[i].z - m_rootposition.z ); Points[i].z - Origin.z );
glEnd(); glEnd();
} }
else if (iType == GL_TRIANGLE_STRIP || iType == GL_TRIANGLE_FAN || iType == GL_TRIANGLES) else if (iType == GL_TRIANGLE_STRIP || iType == GL_TRIANGLE_FAN || iType == GL_TRIANGLES)
@@ -293,9 +293,9 @@ void TGroundNode::Compile(bool many)
Vertices[i].tu, Vertices[i].tu,
Vertices[i].tv); Vertices[i].tv);
glVertex3d( glVertex3d(
Points[i].x - m_rootposition.x, Vertices[i].Point.x - Origin.x,
Points[i].y - m_rootposition.y, Vertices[i].Point.y - Origin.y,
Points[i].z - m_rootposition.z ); Vertices[i].Point.z - Origin.z );
} }
glEnd(); glEnd();
} }
@@ -318,7 +318,7 @@ void TGroundNode::Compile(bool many)
n = n->nNext3; // następny z listy n = n->nNext3; // następny z listy
} }
} }
if (!many) if (false == Multiple)
if (Global::bManageNodes) if (Global::bManageNodes)
glEndList(); glEndList();
}; };
@@ -392,6 +392,7 @@ void TSubRect::NodeAdd(TGroundNode *Node)
case TP_TRACK: // TODO: tory z cieniem (tunel, canyon) też dać bez łączenia? case TP_TRACK: // TODO: tory z cieniem (tunel, canyon) też dać bez łączenia?
++iTracks; // jeden tor więcej ++iTracks; // jeden tor więcej
Node->pTrack->RaOwnerSet(this); // do którego sektora ma zgłaszać animację Node->pTrack->RaOwnerSet(this); // do którego sektora ma zgłaszać animację
/*
if( ( true == Global::bUseVBO ) if( ( true == Global::bUseVBO )
|| ( false == Node->pTrack->IsGroupable() ) ) { || ( false == Node->pTrack->IsGroupable() ) ) {
// tory ruchome nie są grupowane przy Display Lists (wymagają odświeżania DL) // tory ruchome nie są grupowane przy Display Lists (wymagają odświeżania DL)
@@ -427,6 +428,11 @@ void TSubRect::NodeAdd(TGroundNode *Node)
nMeshed = Node; nMeshed = Node;
} // do podzielenia potem } // do podzielenia potem
} }
*/
// NOTE: track merge code temporarily disabled to simplify implementation of camera-centric rendering
// TODO: re-implement merge for both render paths down the road
RaNodeAdd( Node );
break; break;
case GL_TRIANGLE_STRIP: case GL_TRIANGLE_STRIP:
case GL_TRIANGLE_FAN: case GL_TRIANGLE_FAN:
@@ -940,8 +946,10 @@ TGroundRect::Init() {
- glm::vec3( 500.0f, 0.0f, 500.0f ) // 'upper left' corner of rectangle - glm::vec3( 500.0f, 0.0f, 500.0f ) // 'upper left' corner of rectangle
+ glm::vec3( subrectsize * 0.5f, 0.0f, subrectsize * 0.5f ) // center of sub-rectangle + glm::vec3( subrectsize * 0.5f, 0.0f, subrectsize * 0.5f ) // center of sub-rectangle
+ glm::vec3( subrectsize * column, 0.0f, subrectsize * row ); + glm::vec3( subrectsize * column, 0.0f, subrectsize * row );
/*
// NOTE: the actual coordinates get swapped, as they're swapped in rest of the code :x // NOTE: the actual coordinates get swapped, as they're swapped in rest of the code :x
area.center = glm::vec3( area.center.z, area.center.y, area.center.x ); area.center = glm::vec3( area.center.z, area.center.y, area.center.x );
*/
area.radius = subrectsize * M_SQRT2; area.radius = subrectsize * M_SQRT2;
} }
} }
@@ -962,16 +970,23 @@ void TGroundRect::RenderDL()
nRender->DisplayListID = glGenLists(1); nRender->DisplayListID = glGenLists(1);
glNewList(nRender->DisplayListID, GL_COMPILE); glNewList(nRender->DisplayListID, GL_COMPILE);
nRender->iVersion = Global::iReCompile; // aktualna wersja siatek nRender->iVersion = Global::iReCompile; // aktualna wersja siatek
auto const origin = Math3D::vector3( m_area.center.x, m_area.center.y, m_area.center.z );
for (TGroundNode *node = nRender; node; node = node->nNext3) // następny tej grupy for (TGroundNode *node = nRender; node; node = node->nNext3) // następny tej grupy
node->Compile(true); node->Compile(origin, true);
glEndList(); glEndList();
} }
GfxRenderer.Render( nRender ); // nieprzezroczyste trójkąty kwadratu kilometrowego GfxRenderer.Render( nRender ); // nieprzezroczyste trójkąty kwadratu kilometrowego
} }
if( nRootMesh ) // submodels geometry is world-centric, so at least for the time being we need to pop the stack early
::glPopMatrix();
if( nRootMesh ) {
GfxRenderer.Render( nRootMesh ); GfxRenderer.Render( nRootMesh );
}
iLastDisplay = iFrameNumber; // drugi raz nie potrzeba iLastDisplay = iFrameNumber; // drugi raz nie potrzeba
} }
else {
::glPopMatrix();
}
#else #else
if( iLastDisplay != iFrameNumber ) { // tylko jezeli dany kwadrat nie był jeszcze renderowany if( iLastDisplay != iFrameNumber ) { // tylko jezeli dany kwadrat nie był jeszcze renderowany
LoadNodes(); // ewentualne tworzenie siatek LoadNodes(); // ewentualne tworzenie siatek
@@ -1898,7 +1913,7 @@ TSubRect * TGround::FastGetSubRect(int iCol, int iRow)
sc = iCol - bc * iNumSubRects; sc = iCol - bc * iNumSubRects;
if ((br < 0) || (bc < 0) || (br >= iNumRects) || (bc >= iNumRects)) if ((br < 0) || (bc < 0) || (br >= iNumRects) || (bc >= iNumRects))
return NULL; return NULL;
return (Rects[br][bc].FastGetRect(sc, sr)); return (Rects[bc][br].FastGetRect(sc, sr));
} }
TSubRect * TGround::GetSubRect(int iCol, int iRow) TSubRect * TGround::GetSubRect(int iCol, int iRow)
@@ -1910,7 +1925,7 @@ TSubRect * TGround::GetSubRect(int iCol, int iRow)
sc = iCol - bc * iNumSubRects; sc = iCol - bc * iNumSubRects;
if ((br < 0) || (bc < 0) || (br >= iNumRects) || (bc >= iNumRects)) if ((br < 0) || (bc < 0) || (br >= iNumRects) || (bc >= iNumRects))
return NULL; // jeśli poza mapą return NULL; // jeśli poza mapą
return (Rects[br][bc].SafeGetRect(sc, sr)); // pobranie małego kwadratu return (Rects[bc][br].SafeGetRect(sc, sr)); // pobranie małego kwadratu
} }
TEvent * TGround::FindEvent(const std::string &asEventName) TEvent * TGround::FindEvent(const std::string &asEventName)

View File

@@ -166,7 +166,7 @@ public:
return NULL; return NULL;
}; };
void Compile(bool many = false); void Compile(Math3D::vector3 const &Origin, bool const Multiple = false);
void Release(); void Release();
void RenderHidden(); // obsługa dźwięków i wyzwalaczy zdarzeń void RenderHidden(); // obsługa dźwięków i wyzwalaczy zdarzeń
@@ -341,16 +341,15 @@ class TGround
{ {
return &Rects[GetColFromX(x) / iNumSubRects][GetRowFromZ(z) / iNumSubRects]; return &Rects[GetColFromX(x) / iNumSubRects][GetRowFromZ(z) / iNumSubRects];
}; };
TSubRect * GetSubRect( int iCol, int iRow );
TSubRect * GetSubRect(double x, double z) TSubRect * GetSubRect(double x, double z)
{ {
return GetSubRect(GetColFromX(x), GetRowFromZ(z)); return GetSubRect(GetColFromX(x), GetRowFromZ(z));
}; };
TSubRect * FastGetSubRect(double x, double z) TSubRect * FastGetSubRect( int iCol, int iRow );
{ TSubRect * FastGetSubRect( double x, double z ) {
return FastGetSubRect(GetColFromX(x), GetRowFromZ(z)); return FastGetSubRect( GetColFromX( x ), GetRowFromZ( z ) );
}; };
TSubRect * GetSubRect(int iCol, int iRow);
TSubRect * FastGetSubRect(int iCol, int iRow);
int GetRowFromZ(double z) int GetRowFromZ(double z)
{ {
return (int)(z / fSubRectSize + fHalfTotalNumSubRects); return (int)(z / fSubRectSize + fHalfTotalNumSubRects);

View File

@@ -1828,6 +1828,8 @@ TSubModel *TModel3d::TerrainSquare(int n)
void TModel3d::TerrainRenderVBO(int n) void TModel3d::TerrainRenderVBO(int n)
{ // renderowanie terenu z VBO { // renderowanie terenu z VBO
glPushMatrix(); glPushMatrix();
::glTranslated( -Global::pCameraPosition.x, -Global::pCameraPosition.y, -Global::pCameraPosition.z );
// glTranslated(vPosition->x,vPosition->y,vPosition->z); // glTranslated(vPosition->x,vPosition->y,vPosition->z);
// if (vAngle->y!=0.0) glRotated(vAngle->y,0.0,1.0,0.0); // if (vAngle->y!=0.0) glRotated(vAngle->y,0.0,1.0,0.0);
// if (vAngle->x!=0.0) glRotated(vAngle->x,1.0,0.0,0.0); // if (vAngle->x!=0.0) glRotated(vAngle->x,1.0,0.0,0.0);

View File

@@ -1447,19 +1447,19 @@ void TTrack::Compile(GLuint tex)
if( SwitchExtension->iRoads == 3 ) { if( SwitchExtension->iRoads == 3 ) {
// mogą być tylko 3 drogi zamiast 4 // mogą być tylko 3 drogi zamiast 4
SwitchExtension->iPoints = SwitchExtension->iPoints =
5 + SwitchExtension->Segments[ 0 ]->RaSegCount() + SwitchExtension->Segments[ 0 ]->RaSegCount()
SwitchExtension->Segments[ 1 ]->RaSegCount() + + SwitchExtension->Segments[ 1 ]->RaSegCount()
SwitchExtension->Segments[ 2 ]->RaSegCount(); + SwitchExtension->Segments[ 2 ]->RaSegCount();
} }
else { else {
SwitchExtension->iPoints = SwitchExtension->iPoints =
5 + SwitchExtension->Segments[ 2 ]->RaSegCount() + SwitchExtension->Segments[ 2 ]->RaSegCount()
SwitchExtension->Segments[ 3 ]->RaSegCount() + + SwitchExtension->Segments[ 3 ]->RaSegCount()
SwitchExtension->Segments[ 4 ]->RaSegCount() + + SwitchExtension->Segments[ 4 ]->RaSegCount()
SwitchExtension->Segments[ 5 ]->RaSegCount(); // mogą być tylko 3 drogi + SwitchExtension->Segments[ 5 ]->RaSegCount();
} }
// tablica utworzona z zapasem, ale nie wypełniona współrzędnymi // tablica utworzona z zapasem, ale nie wypełniona współrzędnymi
SwitchExtension->vPoints = new vector3[SwitchExtension->iPoints]; SwitchExtension->vPoints = new vector3[ SwitchExtension->iPoints + SwitchExtension->iRoads ];
} }
vector3 *b = vector3 *b =
SwitchExtension->bPoints ? SwitchExtension->bPoints ?
@@ -1573,39 +1573,43 @@ void TTrack::Compile(GLuint tex)
// renderowanie nawierzchni na końcu // renderowanie nawierzchni na końcu
double sina0 = sin(a[0]), cosa0 = cos(a[0]); double sina0 = sin(a[0]), cosa0 = cos(a[0]);
double u, v; double u, v;
if (!SwitchExtension->bPoints) // jeśli tablica nie wypełniona if( ( false == SwitchExtension->bPoints ) // jeśli tablica nie wypełniona
if (b) // ale jest wskaźnik do tablicy - może nie być? && ( b != nullptr ) ) {
{ // coś się gubi w obliczeniach na wskaźnikach SwitchExtension->bPoints = true; // tablica punktów została wypełniona
// ustalenie liczby punktów, bo mogło wyjść inaczej niż }
i = (int)(((size_t)(b)) - ((size_t)(SwitchExtension->vPoints))) / sizeof(vector3);
// policzone z góry
if (i > 0)
{ // jeśli zostało to właśnie utworzone
if (SwitchExtension->iPoints > i) // jeśli wyszło mniej niż było miejsca
SwitchExtension->iPoints = i; // domknięcie wachlarza
else {
// jak tutaj wejdzie, to błąd jest - zrobić miejsce na powtórzenie pierwszego punktu na końcu
--SwitchExtension->iPoints;
}
SwitchExtension->vPoints[SwitchExtension->iPoints++] = SwitchExtension->vPoints[0];
SwitchExtension->bPoints = true; // tablica punktów została wypełniona
}
}
if (TextureID1) // jeśli podana tekstura nawierzchni if (TextureID1) // jeśli podana tekstura nawierzchni
if ( (tex == TextureID1) || (tex == 0) ) // jeśli pasuje do grupy (tex) if ( (tex == TextureID1) || (tex == 0) ) // jeśli pasuje do grupy (tex)
{ {
if (!tex) if (!tex)
GfxRenderer.Bind( TextureID1 ); GfxRenderer.Bind( TextureID1 );
glBegin(GL_TRIANGLE_FAN); // takie kółeczko będzie glBegin(GL_TRIANGLE_FAN); // takie kółeczko będzie
// we start with a vertex in the middle...
glNormal3f(0, 1, 0); glNormal3f(0, 1, 0);
glTexCoord2f(0.5, 0.5); //środek tekstury na środku skrzyżowania glTexCoord2f(0.5, 0.5); //środek tekstury na środku skrzyżowania
glVertex3f(oxz.x, oxz.y, oxz.z); glVertex3f(
for (i = SwitchExtension->iPoints - 1; i >= 0; --i) oxz.x - origin.x,
oxz.y - origin.y,
oxz.z - origin.z );
// ...and add one extra vertex to close the fan...
glNormal3f( 0, 1, 0 );
// mapowanie we współrzędnych scenerii
u = ( SwitchExtension->vPoints[ 0 ].x - oxz.x + origin.x ) / fTexLength;
v = ( SwitchExtension->vPoints[ 0 ].z - oxz.z + origin.z ) / ( fTexRatio1 * fTexLength );
glTexCoord2f(
cosa0 * u + sina0 * v + 0.5,
-sina0 * u + cosa0 * v + 0.5 );
glVertex3f(
SwitchExtension->vPoints[ 0 ].x,
SwitchExtension->vPoints[ 0 ].y,
SwitchExtension->vPoints[ 0 ].z );
for ( i = SwitchExtension->iPoints + SwitchExtension->iRoads - 1; i >= 0; --i )
{ {
glNormal3f(0, 1, 0); glNormal3f(0, 1, 0);
// mapowanie we współrzędnych scenerii // mapowanie we współrzędnych scenerii
u = (SwitchExtension->vPoints[i].x - oxz.x) / fTexLength; u = (SwitchExtension->vPoints[i].x - oxz.x + origin.x) / fTexLength;
v = (SwitchExtension->vPoints[i].z - oxz.z) / (fTexRatio1 * fTexLength); v = (SwitchExtension->vPoints[i].z - oxz.z + origin.z) / (fTexRatio1 * fTexLength);
glTexCoord2f( glTexCoord2f(
cosa0 * u + sina0 * v + 0.5, cosa0 * u + sina0 * v + 0.5,
-sina0 * u + cosa0 * v + 0.5); -sina0 * u + cosa0 * v + 0.5);

View File

@@ -109,7 +109,7 @@ TTraction::~TTraction()
glDeleteLists(uiDisplayList, 1); glDeleteLists(uiDisplayList, 1);
} }
void TTraction::Optimize() void TTraction::Optimize( Math3D::vector3 const &Origin )
{ {
if (Global::bUseVBO) if (Global::bUseVBO)
return; return;
@@ -125,13 +125,13 @@ void TTraction::Optimize()
// Przewoz jezdny 1 'Marcin // Przewoz jezdny 1 'Marcin
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex3f( glVertex3f(
pPoint1.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint1.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset - Origin.x,
pPoint1.y, pPoint1.y - Origin.y,
pPoint1.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset); pPoint1.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset - Origin.z);
glVertex3f( glVertex3f(
pPoint2.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint2.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset - Origin.x,
pPoint2.y, pPoint2.y - Origin.y,
pPoint2.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset); pPoint2.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset - Origin.z );
glEnd(); glEnd();
// Nie wiem co 'Marcin // Nie wiem co 'Marcin
Math3D::vector3 pt1, pt2, pt3, pt4, v1, v2; Math3D::vector3 pt1, pt2, pt3, pt4, v1, v2;
@@ -147,29 +147,39 @@ void TTraction::Optimize()
if (Wires > 1) if (Wires > 1)
{ {
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex3f(pPoint3.x, pPoint3.y, pPoint3.z); glVertex3f(
pPoint3.x - Origin.x,
pPoint3.y - Origin.y,
pPoint3.z - Origin.z );
for (int i = 0; i < iNumSections - 1; ++i) for (int i = 0; i < iNumSections - 1; ++i)
{ {
pt3 = pPoint3 + v1 * f; pt3 = pPoint3 + v1 * f;
t = (1 - std::fabs(f - mid) * 2); t = (1 - std::fabs(f - mid) * 2);
if ((Wires < 4) || ((i != 0) && (i != iNumSections - 2))) if ((Wires < 4) || ((i != 0) && (i != iNumSections - 2)))
glVertex3f( glVertex3f(
pt3.x, pt3.x - Origin.x,
pt3.y - std::sqrt(t) * fHeightDifference, pt3.y - std::sqrt(t) * fHeightDifference - Origin.y,
pt3.z); pt3.z - Origin.z );
f += step; f += step;
} }
glVertex3f(pPoint4.x, pPoint4.y, pPoint4.z); glVertex3f(
pPoint4.x - Origin.x,
pPoint4.y - Origin.y,
pPoint4.z - Origin.z );
glEnd(); glEnd();
} }
// Drugi przewod jezdny 'Winger // Drugi przewod jezdny 'Winger
if (Wires > 2) if (Wires > 2)
{ {
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex3f(pPoint1.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint1.y, glVertex3f(
pPoint1.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset); pPoint1.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset - Origin.x,
glVertex3f(pPoint2.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint2.y, pPoint1.y - Origin.y,
pPoint2.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset); pPoint1.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset - Origin.z );
glVertex3f(
pPoint2.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset - Origin.x,
pPoint2.y - Origin.y,
pPoint2.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset - Origin.z );
glEnd(); glEnd();
} }
@@ -178,22 +188,29 @@ void TTraction::Optimize()
if (Wires == 4) if (Wires == 4)
{ {
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex3f(pPoint3.x, pPoint3.y - 0.65f * fHeightDifference, pPoint3.z); glVertex3f(
pPoint3.x - Origin.x,
pPoint3.y - 0.65f * fHeightDifference - Origin.y,
pPoint3.z - Origin.z );
for (int i = 0; i < iNumSections - 1; ++i) for (int i = 0; i < iNumSections - 1; ++i)
{ {
pt3 = pPoint3 + v1 * f; pt3 = pPoint3 + v1 * f;
t = (1 - std::fabs(f - mid) * 2); t = (1 - std::fabs(f - mid) * 2);
glVertex3f( glVertex3f(
pt3.x, pt3.x - Origin.x,
pt3.y - std::sqrt( t ) * fHeightDifference - ( pt3.y - std::sqrt( t ) * fHeightDifference - (
( ( i == 0 ) ( ( i == 0 )
|| ( i == iNumSections - 2 ) ) ? || ( i == iNumSections - 2 ) ) ?
0.25f * fHeightDifference : 0.25f * fHeightDifference :
0.05 ), 0.05 )
pt3.z); - Origin.y,
pt3.z - Origin.z );
f += step; f += step;
} }
glVertex3f(pPoint4.x, pPoint4.y - 0.65f * fHeightDifference, pPoint4.z); glVertex3f(
pPoint4.x - Origin.x,
pPoint4.y - 0.65f * fHeightDifference - Origin.y,
pPoint4.z - Origin.z );
glEnd(); glEnd();
} }
@@ -214,35 +231,35 @@ void TTraction::Optimize()
if ((i % 2) == 0) if ((i % 2) == 0)
{ {
glVertex3f( glVertex3f(
pt3.x, pt3.x - Origin.x,
pt3.y - std::sqrt(t) * fHeightDifference - ((i == 0) || (i == iNumSections - 2) ? flo : flo1), pt3.y - std::sqrt(t) * fHeightDifference - ((i == 0) || (i == iNumSections - 2) ? flo : flo1) - Origin.y,
pt3.z); pt3.z - Origin.z );
glVertex3f( glVertex3f(
pt4.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pt4.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset - Origin.x,
pt4.y, pt4.y - Origin.y,
pt4.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset); pt4.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset - Origin.z );
} }
else else
{ {
glVertex3f( glVertex3f(
pt3.x, pt3.x - Origin.x,
pt3.y - std::sqrt(t) * fHeightDifference - ((i == 0) || (i == iNumSections - 2) ? flo : flo1), pt3.y - std::sqrt(t) * fHeightDifference - ((i == 0) || (i == iNumSections - 2) ? flo : flo1) - Origin.y,
pt3.z); pt3.z - Origin.z );
glVertex3f( glVertex3f(
pt4.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pt4.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset - Origin.x,
pt4.y, pt4.y - Origin.y,
pt4.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset); pt4.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset - Origin.z );
} }
if ((Wires == 4) && ((i == 1) || (i == iNumSections - 3))) if ((Wires == 4) && ((i == 1) || (i == iNumSections - 3)))
{ {
glVertex3f( glVertex3f(
pt3.x, pt3.x - Origin.x,
pt3.y - std::sqrt(t) * fHeightDifference - 0.05, pt3.y - std::sqrt(t) * fHeightDifference - 0.05 - Origin.y,
pt3.z); pt3.z - Origin.z );
glVertex3f( glVertex3f(
pt3.x, pt3.x - Origin.x,
pt3.y - std::sqrt(t) * fHeightDifference, pt3.y - std::sqrt(t) * fHeightDifference - Origin.y,
pt3.z); pt3.z - Origin.z );
} }
f += step; f += step;
} }
@@ -258,7 +275,7 @@ void TTraction::InitCenter(vector3 Angles, vector3 pOrigin)
fSquaredRadius= SquareMagnitude((pPoint2-pPoint1)*0.5f); fSquaredRadius= SquareMagnitude((pPoint2-pPoint1)*0.5f);
} */ } */
void TTraction::RenderDL(float mgn) // McZapkie: mgn to odleglosc od obserwatora void TTraction::RenderDL(float mgn, Math3D::vector3 const &Origin ) // McZapkie: mgn to odleglosc od obserwatora
{ {
// McZapkie: ustalanie przezroczystosci i koloru linii: // McZapkie: ustalanie przezroczystosci i koloru linii:
if( Wires != 0 && !TestFlag( DamageFlag, 128 ) ) // rysuj jesli sa druty i nie zerwana if( Wires != 0 && !TestFlag( DamageFlag, 128 ) ) // rysuj jesli sa druty i nie zerwana
@@ -281,7 +298,7 @@ void TTraction::RenderDL(float mgn) // McZapkie: mgn to odleglosc od obserwatora
::glColor4f( red, green, blue, linealpha ); ::glColor4f( red, green, blue, linealpha );
// draw code // draw code
if (!uiDisplayList) if (!uiDisplayList)
Optimize(); // generowanie DL w miarę potrzeby Optimize( Origin ); // generowanie DL w miarę potrzeby
::glCallList(uiDisplayList); ::glCallList(uiDisplayList);
// cleanup // cleanup
::glLineWidth(1.0); ::glLineWidth(1.0);

View File

@@ -56,7 +56,7 @@ class TTraction
int iTries = 0; int iTries = 0;
int PowerState{ 0 }; // type of incoming power, if any int PowerState{ 0 }; // type of incoming power, if any
void Optimize(); void Optimize( Math3D::vector3 const &Origin );
TTraction(); TTraction();
~TTraction(); ~TTraction();
@@ -66,7 +66,7 @@ class TTraction
// { return TNode::Hit(x,z,hitPoint,hitDirection); }; // { return TNode::Hit(x,z,hitPoint,hitDirection); };
// virtual bool Move(double dx, double dy, double dz) { return false; }; // virtual bool Move(double dx, double dy, double dz) { return false; };
// virtual void SelectedRender(); // virtual void SelectedRender();
void RenderDL(float mgn); void RenderDL(float mgn, Math3D::vector3 const &Origin );
int RaArrayPrepare(); int RaArrayPrepare();
int RaArrayFill( CVertNormTex *Vert, Math3D::vector3 const &Origin ); int RaArrayFill( CVertNormTex *Vert, Math3D::vector3 const &Origin );
void RenderVBO(float mgn, int iPtr); void RenderVBO(float mgn, int iPtr);

View File

@@ -395,12 +395,12 @@ opengl_renderer::Render( TGround *Ground ) {
if( Global::bUseVBO ) { if( Global::bUseVBO ) {
// vbo render path // vbo render path
Ground->Rects[ ( i + c ) / iNumSubRects ][ ( j + r ) / iNumSubRects ].RenderVBO(); Ground->Rects[ ( i + c ) / iNumSubRects ][ ( j + r ) / iNumSubRects ].RenderVBO();
::glPopMatrix();
} }
else { else {
// display list render path // display list render path
Ground->Rects[ ( i + c ) / iNumSubRects ][ ( j + r ) / iNumSubRects ].RenderDL(); Ground->Rects[ ( i + c ) / iNumSubRects ][ ( j + r ) / iNumSubRects ].RenderDL();
} }
::glPopMatrix();
if( ( tmp = Ground->FastGetSubRect( i + c, j + r ) ) != nullptr ) { if( ( tmp = Ground->FastGetSubRect( i + c, j + r ) ) != nullptr ) {
if( tmp->iNodeCount ) { if( tmp->iNodeCount ) {
@@ -440,8 +440,12 @@ opengl_renderer::Render( TGroundNode *Node ) {
switch (Node->iType) switch (Node->iType)
{ // obiekty renderowane niezależnie od odległości { // obiekty renderowane niezależnie od odległości
case TP_SUBMODEL: case TP_SUBMODEL:
::glPushMatrix();
auto const originoffset = Node->pCenter - Global::pCameraPosition;
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
TSubModel::fSquareDist = 0; TSubModel::fSquareDist = 0;
Render( Node->smTerrain ); Render( Node->smTerrain );
::glPopMatrix();
return true; return true;
} }
@@ -494,7 +498,7 @@ opengl_renderer::Render( TGroundNode *Node ) {
// additional setup for display lists // additional setup for display lists
if( ( Node->DisplayListID == 0 ) if( ( Node->DisplayListID == 0 )
|| ( Node->iVersion != Global::iReCompile ) ) { // Ra: wymuszenie rekompilacji || ( Node->iVersion != Global::iReCompile ) ) { // Ra: wymuszenie rekompilacji
Node->Compile(); Node->Compile(Node->m_rootposition);
if( Global::bManageNodes ) if( Global::bManageNodes )
ResourceManager::Register( Node ); ResourceManager::Register( Node );
}; };
@@ -506,9 +510,6 @@ opengl_renderer::Render( TGroundNode *Node ) {
// wszelkie linie są rysowane na samym końcu // wszelkie linie są rysowane na samym końcu
if( Node->iNumPts ) { if( Node->iNumPts ) {
// setup // setup
::glPushMatrix();
auto const originoffset = Node->m_rootposition - Global::pCameraPosition;
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
// w zaleznosci od koloru swiatla // w zaleznosci od koloru swiatla
::glColor4ub( ::glColor4ub(
static_cast<GLubyte>( std::floor( Node->Diffuse[ 0 ] * Global::DayLight.ambient[ 0 ] ) ), static_cast<GLubyte>( std::floor( Node->Diffuse[ 0 ] * Global::DayLight.ambient[ 0 ] ) ),
@@ -521,14 +522,16 @@ opengl_renderer::Render( TGroundNode *Node ) {
// render // render
// TODO: unify the render code after generic buffers are in place // TODO: unify the render code after generic buffers are in place
if( Global::bUseVBO ) { if( Global::bUseVBO ) {
::glPushMatrix();
auto const originoffset = Node->m_rootposition - Global::pCameraPosition;
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
::glDrawArrays( Node->iType, Node->iVboPtr, Node->iNumPts ); ::glDrawArrays( Node->iType, Node->iVboPtr, Node->iNumPts );
::glPopMatrix();
} }
else { else {
::glCallList( Node->DisplayListID ); ::glCallList( Node->DisplayListID );
} }
// post-render cleanup // post-render cleanup
::glPopMatrix();
return true; return true;
} }
else { else {
@@ -542,12 +545,7 @@ opengl_renderer::Render( TGroundNode *Node ) {
Node->DisplayListID == 0 ) ) { Node->DisplayListID == 0 ) ) {
return false; return false;
} }
// setup // setup
::glPushMatrix();
auto const originoffset = Node->m_rootposition - Global::pCameraPosition;
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
::glColor3ub( ::glColor3ub(
static_cast<GLubyte>( Node->Diffuse[ 0 ] ), static_cast<GLubyte>( Node->Diffuse[ 0 ] ),
static_cast<GLubyte>( Node->Diffuse[ 1 ] ), static_cast<GLubyte>( Node->Diffuse[ 1 ] ),
@@ -559,16 +557,17 @@ opengl_renderer::Render( TGroundNode *Node ) {
// TODO: unify the render code after generic buffers are in place // TODO: unify the render code after generic buffers are in place
if( Global::bUseVBO ) { if( Global::bUseVBO ) {
// vbo render path // vbo render path
::glPushMatrix();
auto const originoffset = Node->m_rootposition - Global::pCameraPosition;
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
::glDrawArrays( Node->iType, Node->iVboPtr, Node->iNumVerts ); ::glDrawArrays( Node->iType, Node->iVboPtr, Node->iNumVerts );
::glPopMatrix();
} }
else { else {
// display list render path // display list render path
::glCallList( Node->DisplayListID ); ::glCallList( Node->DisplayListID );
} }
// post-render cleanup // post-render cleanup
::glPopMatrix();
return true; return true;
} }
} }
@@ -703,7 +702,8 @@ opengl_renderer::Render( TModel3d *Model, material_data const *Material, Math3D:
if( Angle.z != 0.0 ) if( Angle.z != 0.0 )
::glRotated( Angle.z, 0.0, 0.0, 1.0 ); ::glRotated( Angle.z, 0.0, 0.0, 1.0 );
auto const result = Render( Model, Material, SquareMagnitude( Position / Global::ZoomFactor ) ); // position is effectively camera offset // auto const result = Render( Model, Material, SquareMagnitude( Position / Global::ZoomFactor ) ); // position is effectively camera offset
auto const result = Render( Model, Material, SquareMagnitude( Position ) ); // position is effectively camera offset
::glPopMatrix(); ::glPopMatrix();
@@ -978,7 +978,7 @@ opengl_renderer::Render_Alpha( TGroundNode *Node ) {
Node->hvTraction->RenderVBO( distancesquared, Node->iVboPtr ); Node->hvTraction->RenderVBO( distancesquared, Node->iVboPtr );
} }
else { else {
Node->hvTraction->RenderDL( distancesquared ); Node->hvTraction->RenderDL( distancesquared, Node->m_rootposition );
} }
// post-render cleanup // post-render cleanup
::glPopMatrix(); ::glPopMatrix();
@@ -1010,7 +1010,7 @@ opengl_renderer::Render_Alpha( TGroundNode *Node ) {
// additional setup for display lists // additional setup for display lists
if( ( Node->DisplayListID == 0 ) if( ( Node->DisplayListID == 0 )
|| ( Node->iVersion != Global::iReCompile ) ) { // Ra: wymuszenie rekompilacji || ( Node->iVersion != Global::iReCompile ) ) { // Ra: wymuszenie rekompilacji
Node->Compile(); Node->Compile(Node->m_rootposition);
if( Global::bManageNodes ) if( Global::bManageNodes )
ResourceManager::Register( Node ); ResourceManager::Register( Node );
}; };
@@ -1218,7 +1218,8 @@ opengl_renderer::Render_Alpha( TModel3d *Model, material_data const *Material, M
if( Angle.z != 0.0 ) if( Angle.z != 0.0 )
::glRotated( Angle.z, 0.0, 0.0, 1.0 ); ::glRotated( Angle.z, 0.0, 0.0, 1.0 );
auto const result = Render_Alpha( Model, Material, SquareMagnitude( Position / Global::ZoomFactor ) ); // position is effectively camera offset // auto const result = Render_Alpha( Model, Material, SquareMagnitude( Position / Global::ZoomFactor ) ); // position is effectively camera offset
auto const result = Render_Alpha( Model, Material, SquareMagnitude( Position ) ); // position is effectively camera offset
::glPopMatrix(); ::glPopMatrix();

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 17 #define VERSION_MAJOR 17
#define VERSION_MINOR 524 #define VERSION_MINOR 525
#define VERSION_REVISION 0 #define VERSION_REVISION 0