Make runway lighting LOD work correctly.
This commit is contained in:
parent
15b6f15d36
commit
86d586e592
2 changed files with 129 additions and 54 deletions
|
@ -1403,19 +1403,16 @@ bool fgBinObjLoad( const string& path, const bool is_base,
|
|||
if ( pt_materials[i].substr(0, 3) == "RWY" ) {
|
||||
sgVec3 up;
|
||||
sgSetVec3( up, center->x(), center->y(), center->z() );
|
||||
// returns a transform -> lod -> leaf structure
|
||||
ssgBranch *branch = gen_directional_lights( nodes, normals,
|
||||
pts_v[i], pts_n[i],
|
||||
pt_materials[i],
|
||||
up );
|
||||
float ranges[] = { 0, 12000 };
|
||||
// branches don't honor callbacks as far as I know so I'm
|
||||
// commenting this out to avoid a plib runtime warning.
|
||||
// branch->setCallback( SSG_CALLBACK_PREDRAW,
|
||||
// runway_lights_predraw );
|
||||
ssgRangeSelector *lod = new ssgRangeSelector;
|
||||
lod->setRanges( ranges, 2 );
|
||||
lod->addKid( branch );
|
||||
rwy_lights->addKid( lod );
|
||||
rwy_lights->addKid( branch );
|
||||
} else {
|
||||
material = pt_materials[i];
|
||||
tex_index.clear();
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
|
||||
#include "pt_lights.hxx"
|
||||
|
||||
SG_USING_STD(cout);
|
||||
SG_USING_STD(endl);
|
||||
|
||||
|
||||
// strobe pre-draw (we want a larger point size)
|
||||
static int StrobePreDraw( ssgEntity *e ) {
|
||||
|
@ -133,25 +130,59 @@ ssgLeaf *gen_directional_light( sgVec3 pt, sgVec3 dir, sgVec3 up,
|
|||
}
|
||||
|
||||
|
||||
ssgLeaf *gen_dir_light_group( const point_list &nodes,
|
||||
const point_list &normals,
|
||||
const int_list &pnt_i,
|
||||
const int_list &nml_i,
|
||||
const string &material,
|
||||
sgVec3 up )
|
||||
static void calc_center_point( const point_list &nodes,
|
||||
const int_list &pnt_i,
|
||||
sgVec3 result ) {
|
||||
sgVec3 pt;
|
||||
sgSetVec3( pt, nodes[pnt_i[0]][0], nodes[pnt_i[0]][1], nodes[pnt_i[0]][2] );
|
||||
|
||||
double minx = pt[0];
|
||||
double maxx = pt[0];
|
||||
double miny = pt[1];
|
||||
double maxy = pt[1];
|
||||
double minz = pt[2];
|
||||
double maxz = pt[2];
|
||||
|
||||
for ( unsigned int i = 0; i < pnt_i.size(); ++i ) {
|
||||
sgSetVec3( pt, nodes[pnt_i[i]][0], nodes[pnt_i[i]][1],
|
||||
nodes[pnt_i[i]][2] );
|
||||
if ( pt[0] < minx ) { minx = pt[0]; }
|
||||
if ( pt[0] > maxx ) { minx = pt[0]; }
|
||||
if ( pt[1] < miny ) { miny = pt[1]; }
|
||||
if ( pt[1] > maxy ) { miny = pt[1]; }
|
||||
if ( pt[2] < minz ) { minz = pt[2]; }
|
||||
if ( pt[2] > maxz ) { minz = pt[2]; }
|
||||
}
|
||||
|
||||
sgSetVec3( result, (minx + maxx) / 2.0, (miny + maxy) / 2.0,
|
||||
(minz + maxz) / 2.0 );
|
||||
}
|
||||
|
||||
|
||||
ssgTransform *gen_dir_light_group( const point_list &nodes,
|
||||
const point_list &normals,
|
||||
const int_list &pnt_i,
|
||||
const int_list &nml_i,
|
||||
const string &material,
|
||||
sgVec3 up )
|
||||
{
|
||||
sgVec3 center;
|
||||
calc_center_point( nodes, pnt_i, center );
|
||||
// cout << center[0] << "," << center[1] << "," << center[2] << endl;
|
||||
|
||||
sgVec3 nup;
|
||||
sgNormalizeVec3( nup, up );
|
||||
|
||||
ssgVertexArray *vl = new ssgVertexArray( 3 * pnt_i.size() );
|
||||
ssgNormalArray *nl = new ssgNormalArray( 3 * pnt_i.size() );
|
||||
ssgColourArray *cl = new ssgColourArray( 3 * pnt_i.size() );
|
||||
ssgVertexArray *vl = new ssgVertexArray( 3 * pnt_i.size() );
|
||||
ssgNormalArray *nl = new ssgNormalArray( 3 * pnt_i.size() );
|
||||
ssgColourArray *cl = new ssgColourArray( 3 * pnt_i.size() );
|
||||
|
||||
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] );
|
||||
sgSubVec3( pt, center );
|
||||
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
|
||||
normals[nml_i[i]][2] );
|
||||
|
||||
|
@ -159,7 +190,7 @@ ssgLeaf *gen_dir_light_group( const point_list &nodes,
|
|||
sgVec3 perp;
|
||||
sgVectorProductVec3( perp, normal, nup );
|
||||
|
||||
// front face
|
||||
// front face
|
||||
sgVec3 tmp3;
|
||||
sgCopyVec3( tmp3, pt );
|
||||
vl->add( tmp3 );
|
||||
|
@ -196,17 +227,34 @@ ssgLeaf *gen_dir_light_group( const point_list &nodes,
|
|||
<< material );
|
||||
}
|
||||
|
||||
return leaf;
|
||||
// put an LOD on each lighting component
|
||||
ssgRangeSelector *lod = new ssgRangeSelector;
|
||||
lod->setRange( 0, SG_ZERO );
|
||||
lod->setRange( 1, 12000 );
|
||||
lod->addKid( leaf );
|
||||
|
||||
// create the transformation.
|
||||
sgCoord coord;
|
||||
sgSetCoord( &coord, center[0], center[1], center[2], 0.0, 0.0, 0.0 );
|
||||
ssgTransform *trans = new ssgTransform;
|
||||
trans->setTransform( &coord );
|
||||
trans->addKid( lod );
|
||||
|
||||
return trans;
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
ssgTransform *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 center;
|
||||
calc_center_point( nodes, pnt_i, center );
|
||||
// cout << center[0] << "," << center[1] << "," << center[2] << endl;
|
||||
|
||||
sgVec3 nup;
|
||||
sgNormalizeVec3( nup, up );
|
||||
|
||||
|
@ -219,6 +267,7 @@ ssgTimedSelector *gen_reil_lights( const point_list &nodes,
|
|||
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] );
|
||||
sgSubVec3( pt, center );
|
||||
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
|
||||
normals[nml_i[i]][2] );
|
||||
|
||||
|
@ -277,17 +326,34 @@ ssgTimedSelector *gen_reil_lights( const point_list &nodes,
|
|||
reil->setMode( SSG_ANIM_SHUTTLE );
|
||||
reil->control( SSG_ANIM_START );
|
||||
|
||||
return reil;
|
||||
// put an LOD on each lighting component
|
||||
ssgRangeSelector *lod = new ssgRangeSelector;
|
||||
lod->setRange( 0, SG_ZERO );
|
||||
lod->setRange( 1, 12000 );
|
||||
lod->addKid( reil );
|
||||
|
||||
// create the transformation.
|
||||
sgCoord coord;
|
||||
sgSetCoord( &coord, center[0], center[1], center[2], 0.0, 0.0, 0.0 );
|
||||
ssgTransform *trans = new ssgTransform;
|
||||
trans->setTransform( &coord );
|
||||
trans->addKid( lod );
|
||||
|
||||
return trans;
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
ssgTransform *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 )
|
||||
{
|
||||
sgVec3 center;
|
||||
calc_center_point( nodes, pnt_i, center );
|
||||
// cout << center[0] << "," << center[1] << "," << center[2] << endl;
|
||||
|
||||
sgVec3 nup;
|
||||
sgNormalizeVec3( nup, up );
|
||||
|
||||
|
@ -296,13 +362,13 @@ ssgTimedSelector *gen_rabbit_lights( const point_list &nodes,
|
|||
int i;
|
||||
sgVec3 pt, normal;
|
||||
for ( i = (int)pnt_i.size() - 1; i >= 0; --i ) {
|
||||
ssgVertexArray *vl = new ssgVertexArray( 3 * pnt_i.size() );
|
||||
ssgNormalArray *nl = new ssgNormalArray( 3 * pnt_i.size() );
|
||||
ssgColourArray *cl = new ssgColourArray( 3 * pnt_i.size() );
|
||||
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] );
|
||||
cout << "nml_i[" << i << "] = " << nml_i[i] << endl;
|
||||
sgSubVec3( pt, center );
|
||||
|
||||
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
|
||||
normals[nml_i[i]][2] );
|
||||
|
@ -358,16 +424,28 @@ ssgTimedSelector *gen_rabbit_lights( const point_list &nodes,
|
|||
rabbit->setMode( SSG_ANIM_SHUTTLE );
|
||||
rabbit->control( SSG_ANIM_START );
|
||||
|
||||
return rabbit;
|
||||
// put an LOD on each lighting component
|
||||
ssgRangeSelector *lod = new ssgRangeSelector;
|
||||
lod->setRange( 0, SG_ZERO );
|
||||
lod->setRange( 1, 12000 );
|
||||
lod->addKid( rabbit );
|
||||
|
||||
// create the transformation.
|
||||
sgCoord coord;
|
||||
sgSetCoord( &coord, center[0], center[1], center[2], 0.0, 0.0, 0.0 );
|
||||
ssgTransform *trans = new ssgTransform;
|
||||
trans->setTransform( &coord );
|
||||
trans->addKid( lod );
|
||||
|
||||
return trans;
|
||||
}
|
||||
|
||||
|
||||
// Generate a directional light
|
||||
ssgLeaf *gen_normal_line( sgVec3 pt, sgVec3 dir, sgVec3 up ) {
|
||||
|
||||
ssgVertexArray *vl = new ssgVertexArray( 3 );
|
||||
ssgNormalArray *nl = new ssgNormalArray( 3 );
|
||||
ssgColourArray *cl = new ssgColourArray( 3 );
|
||||
ssgVertexArray *vl = new ssgVertexArray( 3 );
|
||||
ssgColourArray *cl = new ssgColourArray( 3 );
|
||||
|
||||
sgVec3 tmp3;
|
||||
sgCopyVec3( tmp3, pt );
|
||||
|
@ -397,27 +475,27 @@ ssgBranch *gen_directional_lights( const point_list &nodes,
|
|||
const string &material,
|
||||
sgVec3 up )
|
||||
{
|
||||
ssgBranch *result = new ssgBranch;
|
||||
ssgBranch *result;
|
||||
|
||||
sgVec3 nup;
|
||||
sgNormalizeVec3( nup, up );
|
||||
|
||||
if ( material == "RWY_REIL_LIGHTS" ) {
|
||||
cout << "found a reil" << endl;
|
||||
ssgTimedSelector *reil = gen_reil_lights( nodes, normals, pnt_i, nml_i,
|
||||
material, up );
|
||||
result->addKid( reil );
|
||||
// cout << "found a reil" << endl;
|
||||
ssgTransform *reil = gen_reil_lights( nodes, normals, pnt_i, nml_i,
|
||||
material, up );
|
||||
return 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 );
|
||||
// cout << "found a rabbit" << endl;
|
||||
ssgTransform *rabbit = gen_rabbit_lights( nodes, normals,
|
||||
pnt_i, nml_i,
|
||||
material, up );
|
||||
return rabbit;
|
||||
} else {
|
||||
ssgLeaf *light_group = gen_dir_light_group( nodes, normals, pnt_i,
|
||||
nml_i, material, up );
|
||||
result->addKid( light_group );
|
||||
ssgTransform *light_group = gen_dir_light_group( nodes, normals, pnt_i,
|
||||
nml_i, material, up );
|
||||
return light_group;
|
||||
}
|
||||
|
||||
return result;
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue