From: curt Date: Mon, 4 Dec 2000 05:23:06 +0000 (+0000) Subject: Added a hardcoded "LIGHTING" material entry in the matlib. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bb108c7917e8b65ecf626cbf0440944cf2e4ee90;p=flightgear.git Added a hardcoded "LIGHTING" material entry in the matlib. Fixed a typo in creating textured ssg simple states. Start looking at a faster method for generating surface lighting based on the scenery triangles. --- diff --git a/src/Objects/matlib.cxx b/src/Objects/matlib.cxx index d8d95b4ef..ffb5422ce 100644 --- a/src/Objects/matlib.cxx +++ b/src/Objects/matlib.cxx @@ -161,6 +161,23 @@ bool FGMaterialLib::load( const string& mpath ) { } } + // hard coded light state + ssgSimpleState *lights = new ssgSimpleState; + lights->ref(); + lights->disable( GL_TEXTURE_2D ); + lights->enable( GL_CULL_FACE ); + lights->enable( GL_COLOR_MATERIAL ); + lights->setColourMaterial( GL_AMBIENT_AND_DIFFUSE ); + lights->setMaterial( GL_EMISSION, 0, 0, 0, 1 ); + lights->setMaterial( GL_SPECULAR, 0, 0, 0, 1 ); + lights->disable( GL_BLEND ); + lights->disable( GL_ALPHA_TEST ); + lights->disable( GL_LIGHTING ); + + FGNewMat m; + m.set_ssg_state( lights ); + matlib["LIGHTS"] = m; + return true; } @@ -257,3 +274,13 @@ void FGMaterialLib::set_step ( int step ) slot.get_state()->selectStep(step); } } + + + + + + + + + + diff --git a/src/Objects/newmat.cxx b/src/Objects/newmat.cxx index c16f8527c..696de0c30 100644 --- a/src/Objects/newmat.cxx +++ b/src/Objects/newmat.cxx @@ -85,6 +85,7 @@ void FGNewMat::build_ssg_state( const string& path, // Set up the textured state textured->setShadeModel( shade_model ); + textured->enable( GL_LIGHTING ); textured->enable ( GL_CULL_FACE ) ; textured->enable( GL_TEXTURE_2D ); textured->disable( GL_BLEND ); diff --git a/src/Objects/obj.cxx b/src/Objects/obj.cxx index efac3bbff..2350ab001 100644 --- a/src/Objects/obj.cxx +++ b/src/Objects/obj.cxx @@ -46,10 +46,10 @@ #include #include -#include #include #include #include +#include #include #include #include @@ -267,6 +267,37 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) { } +void gen_random_surface_points( ssgLeaf *leaf, ssgVertexArray *lights ) { + int num = leaf->getNumVertices(); + float *n1, *n2, *n3; + sgVec3 p1, p2, p3; + sgVec3 result; + float remainder = 1.0; + float weight; + + n1 = leaf->getVertex( 1 ); + n2 = leaf->getVertex( 2 ); + for ( int i = 3; i < num; ++i ) { + n3 = leaf->getVertex( i ); + weight = sg_random(); + remainder -= weight; + sgScaleVec3( p1, n1, weight ); + + weight = sg_random() * remainder; + remainder -= weight; + sgScaleVec3( p2, n2, weight ); + + sgScaleVec3( p3, n3, remainder ); + + sgAddVec3( result, p1, p2 ); + sgAddVec3( result, p3 ); + + sgScaleVec3( result, 1.0 / 3.0 ); + lights->add( result ); + } +} + + // Load a .obj file ssgBranch *fgObjLoad( const string& path, FGTileEntry *t, const bool is_base) { FGNewMat *newmat; @@ -667,6 +698,15 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t, const bool is_base) { leaf->setState( state ); tile->addKid( leaf ); + + /* + ssgVertexArray *lights = NULL; + if ( is_base ) { + // generate lighting + lights = new ssgVertexArray( size ); + gen_random_surface_points( leaf, lights ); + } + */ } else { FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in " << path << " = " << token );