1
0
Fork 0

Some restructuring to optimize the light point portion of the scene graph.

There's no point in having a separate leaf for each light.
This commit is contained in:
curt 2002-10-17 23:17:16 +00:00
parent 7df3da668c
commit bbdca39e3b

View file

@ -113,18 +113,140 @@ ssgLeaf *gen_directional_light( sgVec3 pt, sgVec3 dir, sgVec3 up,
} }
// Generate a REIL light ssgLeaf *gen_dir_light_group( const point_list &nodes,
ssgBranch *gen_reil_light( sgVec3 pt, sgVec3 dir, sgVec3 up, const point_list &normals,
const string &material ) { const int_list &pnt_i,
const int_list &nml_i,
const string &material,
sgVec3 up )
{
sgVec3 nup;
sgNormalizeVec3( nup, up );
ssgVertexArray *vl = new ssgVertexArray( 3 );
ssgNormalArray *nl = new ssgNormalArray( 3 );
ssgColourArray *cl = new ssgColourArray( 3 );
unsigned int i;
sgVec3 pt, normal;
for ( i = 0; i < pnt_i.size(); ++i ) {
sgSetVec3( pt, nodes[pnt_i[i]][0], nodes[pnt_i[i]][1],
nodes[pnt_i[i]][2] );
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
normals[nml_i[i]][2] );
// calculate a vector perpendicular to dir and up
sgVec3 perp;
sgVectorProductVec3( perp, normal, nup );
// front face
sgVec3 tmp3;
sgCopyVec3( tmp3, pt );
vl->add( tmp3 );
sgAddVec3( tmp3, nup );
vl->add( tmp3 );
sgAddVec3( tmp3, perp );
vl->add( tmp3 );
// sgSubVec3( tmp3, nup );
// vl->add( tmp3 );
nl->add( normal );
nl->add( normal );
nl->add( normal );
// nl->add( normal );
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
sgSetVec4( color, 1.0, 1.0, 1.0, 0.0 );
cl->add( color );
cl->add( color );
// cl->add( color );
}
ssgLeaf *leaf =
new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
FGNewMat *newmat = material_lib.find( material );
if ( newmat != NULL ) {
leaf->setState( newmat->get_state() );
} else {
SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
<< material );
}
return leaf;
}
ssgTimedSelector *gen_reil_lights( const point_list &nodes,
const point_list &normals,
const int_list &pnt_i,
const int_list &nml_i,
const string &material,
sgVec3 up )
{
sgVec3 nup;
sgNormalizeVec3( nup, up );
ssgVertexArray *vl = new ssgVertexArray( 6 );
ssgNormalArray *nl = new ssgNormalArray( 6 );
ssgColourArray *cl = new ssgColourArray( 6 );
unsigned int i;
sgVec3 pt, normal;
for ( i = 0; i < pnt_i.size(); ++i ) {
sgSetVec3( pt, nodes[pnt_i[i]][0], nodes[pnt_i[i]][1],
nodes[pnt_i[i]][2] );
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
normals[nml_i[i]][2] );
// calculate a vector perpendicular to dir and up
sgVec3 perp;
sgVectorProductVec3( perp, normal, nup );
// front face
sgVec3 tmp3;
sgCopyVec3( tmp3, pt );
vl->add( tmp3 );
sgAddVec3( tmp3, nup );
vl->add( tmp3 );
sgAddVec3( tmp3, perp );
vl->add( tmp3 );
// sgSubVec3( tmp3, nup );
// vl->add( tmp3 );
nl->add( normal );
nl->add( normal );
nl->add( normal );
// nl->add( normal );
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
sgSetVec4( color, 1.0, 1.0, 1.0, 0.0 );
cl->add( color );
cl->add( color );
// cl->add( color );
}
ssgLeaf *leaf =
new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
FGNewMat *newmat = material_lib.find( "RWY_WHITE_LIGHTS" );
if ( newmat != NULL ) {
leaf->setState( newmat->get_state() );
} else {
SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
<< material );
}
ssgTimedSelector *reil = new ssgTimedSelector; ssgTimedSelector *reil = new ssgTimedSelector;
ssgLeaf *leaf; // need to add this twice to work around an ssg bug
leaf = gen_directional_light( pt, dir, up, "RWY_WHITE_LIGHTS" );
reil->addKid( leaf ); reil->addKid( leaf );
leaf = gen_directional_light( pt, dir, up, "RWY_WHITE_LIGHTS" );
reil->addKid( leaf ); reil->addKid( leaf );
reil->setDuration( 60 ); reil->setDuration( 60 );
@ -136,6 +258,89 @@ ssgBranch *gen_reil_light( sgVec3 pt, sgVec3 dir, sgVec3 up,
} }
ssgTimedSelector *gen_rabbit_lights( const point_list &nodes,
const point_list &normals,
const int_list &pnt_i,
const int_list &nml_i,
const string &material,
sgVec3 up )
{
bool first = true;
sgVec3 nup;
sgNormalizeVec3( nup, up );
ssgTimedSelector *rabbit = new ssgTimedSelector;
unsigned int i;
sgVec3 pt, normal;
for ( i = 0; i < pnt_i.size(); ++i ) {
ssgVertexArray *vl = new ssgVertexArray( 3 );
ssgNormalArray *nl = new ssgNormalArray( 3 );
ssgColourArray *cl = new ssgColourArray( 3 );
sgSetVec3( pt, nodes[pnt_i[i]][0], nodes[pnt_i[i]][1],
nodes[pnt_i[i]][2] );
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
normals[nml_i[i]][2] );
// calculate a vector perpendicular to dir and up
sgVec3 perp;
sgVectorProductVec3( perp, normal, nup );
// front face
sgVec3 tmp3;
sgCopyVec3( tmp3, pt );
vl->add( tmp3 );
sgAddVec3( tmp3, nup );
vl->add( tmp3 );
sgAddVec3( tmp3, perp );
vl->add( tmp3 );
// sgSubVec3( tmp3, nup );
// vl->add( tmp3 );
nl->add( normal );
nl->add( normal );
nl->add( normal );
// nl->add( normal );
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
sgSetVec4( color, 1.0, 1.0, 1.0, 0.0 );
cl->add( color );
cl->add( color );
// cl->add( color );
ssgLeaf *leaf =
new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
FGNewMat *newmat = material_lib.find( "RWY_WHITE_LIGHTS" );
if ( newmat != NULL ) {
leaf->setState( newmat->get_state() );
} else {
SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
<< material );
}
rabbit->addKid( leaf );
if ( first ) {
// ssg bug where first entry in animation is ignored.
rabbit->addKid( leaf );
}
}
rabbit->setDuration( 5 );
rabbit->setLimits( 0, pnt_i.size() );
rabbit->setMode( SSG_ANIM_SHUTTLE );
rabbit->control( SSG_ANIM_START );
return rabbit;
}
// Generate a directional light // Generate a directional light
ssgLeaf *gen_normal_line( sgVec3 pt, sgVec3 dir, sgVec3 up ) { ssgLeaf *gen_normal_line( sgVec3 pt, sgVec3 dir, sgVec3 up ) {
@ -176,24 +381,21 @@ ssgBranch *gen_directional_lights( const point_list &nodes,
sgVec3 nup; sgVec3 nup;
sgNormalizeVec3( nup, up ); sgNormalizeVec3( nup, up );
unsigned int i;
sgVec3 pt, normal;
for ( i = 0; i < pnt_i.size(); ++i ) {
sgSetVec3( pt, nodes[pnt_i[i]][0], nodes[pnt_i[i]][1],
nodes[pnt_i[i]][2] );
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
normals[nml_i[i]][2] );
if ( material == "RWY_REIL_LIGHTS" ) { if ( material == "RWY_REIL_LIGHTS" ) {
cout << "found a reil" << endl; cout << "found a reil" << endl;
ssgBranch *light = gen_reil_light( pt, normal, nup, material ); ssgTimedSelector *reil = gen_reil_lights( nodes, normals, pnt_i, nml_i,
result->addKid( light ); material, up );
result->addKid( reil );
} else if ( material == "RWY_SEQUENCED_LIGHTS" ) {
cout << "found a rabbit" << endl;
ssgTimedSelector *rabbit = gen_rabbit_lights( nodes, normals,
pnt_i, nml_i,
material, up );
result->addKid( rabbit );
} else { } else {
// standard directional lights ssgLeaf *light_group = gen_dir_light_group( nodes, normals, pnt_i,
ssgLeaf *light = gen_directional_light( pt, normal, nup, material ); nml_i, material, up );
result->addKid( light ); result->addKid( light_group );
}
// light = gen_normal_line( pt, normal, nup );
// result->addKid( light );
} }
return result; return result;