]> git.mxchange.org Git - flightgear.git/commitdiff
Added a hardcoded "LIGHTING" material entry in the matlib.
authorcurt <curt>
Mon, 4 Dec 2000 05:23:06 +0000 (05:23 +0000)
committercurt <curt>
Mon, 4 Dec 2000 05:23:06 +0000 (05:23 +0000)
Fixed a typo in creating textured ssg simple states.
Start looking at a faster method for generating surface lighting based on the
scenery triangles.

src/Objects/matlib.cxx
src/Objects/newmat.cxx
src/Objects/obj.cxx

index d8d95b4ef596cb080d740b8da9709cb6772d6a5b..ffb5422ceaa24fb428a77502760a92e856205264 100644 (file)
@@ -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);
     }
 }
+
+
+
+
+
+
+
+
+
+
index c16f8527c57ef5f6dbdf1f8cc291d3fe10de99b3..696de0c30421dae58968a23bccd0e2eae7b67cc5 100644 (file)
@@ -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 );
index efac3bbff6102bf935edbfb00834f13daa60738b..2350ab001cd83e6d8fd0d730537f8ff3dcfeb590 100644 (file)
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
-#include <simgear/math/fg_random.h>
 #include <simgear/math/point3d.hxx>
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/sg_geodesy.hxx>
+#include <simgear/math/sg_random.h>
 #include <simgear/misc/fgstream.hxx>
 #include <simgear/misc/stopwatch.hxx>
 #include <simgear/misc/texcoord.hxx>
@@ -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 );