diff --git a/Ground.cpp b/Ground.cpp index 9f66a6e3..91f84e87 100644 --- a/Ground.cpp +++ b/Ground.cpp @@ -49,14 +49,6 @@ extern "C" bool bCondition; // McZapkie: do testowania warunku na event multiple std::string LogComment; -// tests whether provided points form a degenerate triangle -bool -degenerate( glm::dvec3 const &Vertex1, glm::dvec3 const &Vertex2, glm::dvec3 const &Vertex3 ) { - -// degenerate( A, B, C, minarea ) = ( ( B - A ).cross( C - A ) ).lengthSquared() < ( 4.0f * minarea * minarea ); - return glm::length2( glm::cross( Vertex2 - Vertex1, Vertex3 - Vertex1 ) ) < std::numeric_limits::epsilon(); -} - //--------------------------------------------------------------------------- // Obiekt renderujący siatkę jest sztucznie tworzonym obiektem pomocniczym, // grupującym siatki obiektów dla danej tekstury. Obiektami składowymi mogą diff --git a/Model3d.cpp b/Model3d.cpp index 06a5f43c..e2168583 100644 --- a/Model3d.cpp +++ b/Model3d.cpp @@ -460,10 +460,8 @@ int TSubModel::Load( cParser &parser, TModel3d *Model, /*int Pos,*/ bool dynamic >> Vertices[i].texture.t; if (i % 3 == 2) { // jeżeli wczytano 3 punkty - if (Vertices[i ].position == Vertices[i - 1].position - || Vertices[i - 1].position == Vertices[i - 2].position - || Vertices[i - 2].position == Vertices[i ].position) - { // jeżeli punkty się nakładają na siebie + if( true == degenerate( Vertices[ i ].position, Vertices[ i - 1 ].position, Vertices[ i - 2 ].position ) ) { + // jeżeli punkty się nakładają na siebie --facecount; // o jeden trójkąt mniej iNumVerts -= 3; // czyli o 3 wierzchołki i -= 3; // wczytanie kolejnego w to miejsce diff --git a/renderer.cpp b/renderer.cpp index 4ddb6df5..07453165 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -1493,32 +1493,42 @@ opengl_renderer::Render( TSubModel *Submodel ) { // spotlights are only rendered in colour mode(s) case rendermode::color: { auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW ); - auto const lightcenter = modelview * glm::vec4( 0.0f, 0.0f, -0.05f, 1.0f ); // pozycja punktu świecącego względem kamery - Submodel->fCosViewAngle = glm::dot( glm::normalize( modelview * glm::vec4( 0.0f, 0.0f, -1.0f, 1.0f ) - lightcenter ), glm::normalize( -lightcenter ) ); + auto const lightcenter = + modelview + * interpolate( + glm::vec4( 0.f, 0.f, -0.05f, 1.f ), + glm::vec4( 0.f, 0.f, -0.25f, 1.f ), + static_cast( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery + Submodel->fCosViewAngle = glm::dot( glm::normalize( modelview * glm::vec4( 0.f, 0.f, -1.f, 1.f ) - lightcenter ), glm::normalize( -lightcenter ) ); - if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) // kąt większy niż maksymalny stożek swiatła - { - float lightlevel = 1.0f; // TODO, TBD: parameter to control light strength - // view angle attenuation + if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) { + // kąt większy niż maksymalny stożek swiatła + float lightlevel = 1.f; // TODO, TBD: parameter to control light strength + // view angle attenuation float const anglefactor = ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( 1.0f - Submodel->fCosFalloffAngle ); // distance attenuation. NOTE: since it's fixed pipeline with built-in gamma correction we're using linear attenuation // we're capping how much effect the distance attenuation can have, otherwise the lights get too tiny at regular distances float const distancefactor = static_cast( std::max( 0.5, ( Submodel->fSquareMaxDist - TSubModel::fSquareDist ) / ( Submodel->fSquareMaxDist * Global::fDistanceFactor ) ) ); - if( lightlevel > 0.0f ) { + if( lightlevel > 0.f ) { // material configuration: ::glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT ); Bind( 0 ); - ::glPointSize( std::max( 2.0f, 4.0f * distancefactor * anglefactor ) ); + ::glPointSize( std::max( 3.f, 5.f * distancefactor * anglefactor ) ); ::glColor4f( Submodel->f4Diffuse[ 0 ], Submodel->f4Diffuse[ 1 ], Submodel->f4Diffuse[ 2 ], lightlevel * anglefactor ); ::glDisable( GL_LIGHTING ); ::glEnable( GL_BLEND ); + ::glPushMatrix(); + ::glLoadIdentity(); + ::glTranslatef( lightcenter.x, lightcenter.y, lightcenter.z ); // początek układu zostaje bez zmian + // main draw call m_geometry.draw( Submodel->m_geometry ); // post-draw reset + ::glPopMatrix(); ::glPopAttrib(); } } @@ -2031,8 +2041,13 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) { // NOTE: we're forced here to redo view angle calculations etc, because this data isn't instanced but stored along with the single mesh // TODO: separate instance data from reusable geometry auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW ); - auto const lightcenter = modelview * glm::vec4( 0.0f, 0.0f, -0.05f, 1.0f ); // pozycja punktu świecącego względem kamery - Submodel->fCosViewAngle = glm::dot( glm::normalize( modelview * glm::vec4( 0.0f, 0.0f, -1.0f, 1.0f ) - lightcenter ), glm::normalize( -lightcenter ) ); + auto const lightcenter = + modelview + * interpolate( + glm::vec4( 0.f, 0.f, -0.05f, 1.f ), + glm::vec4( 0.f, 0.f, -0.10f, 1.f ), + static_cast( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery + Submodel->fCosViewAngle = glm::dot( glm::normalize( modelview * glm::vec4( 0.f, 0.f, -1.f, 1.f ) - lightcenter ), glm::normalize( -lightcenter ) ); float glarelevel = 0.6f; // luminosity at night is at level of ~0.1, so the overall resulting transparency is ~0.5 at full 'brightness' if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) { diff --git a/usefull.h b/usefull.h index cd747876..6474da98 100644 --- a/usefull.h +++ b/usefull.h @@ -71,4 +71,13 @@ interpolate( Type_ const &First, Type_ const &Second, double const Factor ) { return ( First * ( 1.0 - Factor ) ) + ( Second * Factor ); } +// tests whether provided points form a degenerate triangle +template +bool +degenerate( VecType_ const &Vertex1, VecType_ const &Vertex2, VecType_ const &Vertex3 ) { + + // degenerate( A, B, C, minarea ) = ( ( B - A ).cross( C - A ) ).lengthSquared() < ( 4.0f * minarea * minarea ); + return glm::length2( glm::cross( Vertex2 - Vertex1, Vertex3 - Vertex1 ) ) < std::numeric_limits::epsilon(); +} + //--------------------------------------------------------------------------- diff --git a/version.h b/version.h index dedc7d9c..a54feaa0 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #pragma once #define VERSION_MAJOR 17 -#define VERSION_MINOR 717 +#define VERSION_MINOR 721 #define VERSION_REVISION 0