mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
conversion of legacy model-based terrain to camera-centric render system
This commit is contained in:
76
Model3d.cpp
76
Model3d.cpp
@@ -19,6 +19,7 @@ Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
|
||||
#include "logs.h"
|
||||
#include "mczapkie/mctools.h"
|
||||
#include "Usefull.h"
|
||||
#include "ground.h"
|
||||
#include "renderer.h"
|
||||
#include "Timer.h"
|
||||
#include "mtable.h"
|
||||
@@ -1037,7 +1038,7 @@ void TSubModel::RaAnimation(TAnimType a)
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void TSubModel::serialize_geometry( std::ostream &Output ) {
|
||||
void TSubModel::serialize_geometry( std::ostream &Output ) const {
|
||||
|
||||
if( Child ) {
|
||||
Child->serialize_geometry( Output );
|
||||
@@ -1076,6 +1077,65 @@ TSubModel::create_geometry( std::size_t &Dataoffset, geometrybank_handle const &
|
||||
Next->create_geometry( Dataoffset, Bank );
|
||||
}
|
||||
|
||||
// places contained geometry in provided ground node
|
||||
void
|
||||
TSubModel::convert( TGroundNode &Groundnode ) const {
|
||||
|
||||
Groundnode.asName = pName;
|
||||
Groundnode.Ambient = f4Ambient;
|
||||
Groundnode.Diffuse = f4Diffuse;
|
||||
Groundnode.Specular = f4Specular;
|
||||
Groundnode.TextureID = TextureID;
|
||||
Groundnode.iFlags = (
|
||||
( true == GfxRenderer.Texture( TextureID ).has_alpha ) ?
|
||||
0x20 :
|
||||
0x10 );
|
||||
|
||||
if( m_geometry == NULL ) { return; }
|
||||
|
||||
std::size_t vertexcount { 0 };
|
||||
std::vector<TGroundVertex> importedvertices;
|
||||
TGroundVertex vertex, vertex1, vertex2;
|
||||
for( auto const &sourcevertex : GfxRenderer.Vertices( m_geometry ) ) {
|
||||
vertex.position = sourcevertex.position;
|
||||
vertex.normal = sourcevertex.normal;
|
||||
vertex.texture = sourcevertex.texture;
|
||||
if( vertexcount == 0 ) { vertex1 = vertex; }
|
||||
else if( vertexcount == 1 ) { vertex2 = vertex; }
|
||||
else if( vertexcount >= 2 ) {
|
||||
if( false == degenerate( vertex1.position, vertex2.position, vertex.position ) ) {
|
||||
importedvertices.emplace_back( vertex1 );
|
||||
importedvertices.emplace_back( vertex2 );
|
||||
importedvertices.emplace_back( vertex );
|
||||
}
|
||||
}
|
||||
++vertexcount;
|
||||
if( vertexcount > 2 ) { vertexcount = 0; } // start new triangle if needed
|
||||
}
|
||||
if( Groundnode.Piece == nullptr ) {
|
||||
Groundnode.Piece = new piece_node();
|
||||
}
|
||||
Groundnode.iNumVerts = importedvertices.size();
|
||||
if( Groundnode.iNumVerts > 0 ) {
|
||||
|
||||
Groundnode.Piece->vertices.swap( importedvertices );
|
||||
|
||||
for( auto const &vertex : Groundnode.Piece->vertices ) {
|
||||
Groundnode.pCenter += vertex.position;
|
||||
}
|
||||
Groundnode.pCenter /= Groundnode.iNumVerts;
|
||||
|
||||
double r { 0.0 };
|
||||
double tf;
|
||||
for( auto const &vertex : Groundnode.Piece->vertices ) {
|
||||
tf = glm::length2( vertex.position - glm::dvec3{ Groundnode.pCenter } );
|
||||
if( tf > r )
|
||||
r = tf;
|
||||
}
|
||||
Groundnode.fSquareRadius += r;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: leftover from static distance factor adjustment.
|
||||
// TODO: get rid of it, once we have the dynamic adjustment code in place
|
||||
void TSubModel::AdjustDist()
|
||||
@@ -1861,17 +1921,3 @@ TSubModel *TModel3d::TerrainSquare(int n)
|
||||
r->UnFlagNext(); // blokowanie wyświetlania po Next głównej listy
|
||||
return r;
|
||||
};
|
||||
#ifdef EU07_USE_OLD_RENDERCODE
|
||||
void TModel3d::TerrainRenderVBO(int n)
|
||||
{ // renderowanie terenu z VBO
|
||||
::glPushMatrix();
|
||||
::glTranslated( -Global::pCameraPosition.x, -Global::pCameraPosition.y, -Global::pCameraPosition.z );
|
||||
TSubModel *r = Root;
|
||||
while( r ) {
|
||||
if( r->iVisible == n ) // tylko jeśli ma być widoczny w danej ramce (problem dla 0==false)
|
||||
GfxRenderer.Render( r ); // sub kolejne (Next) się nie wyrenderują
|
||||
r = r->NextGet();
|
||||
}
|
||||
::glPopMatrix();
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user