#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 ) {
}
-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] );
sgVec3 perp;
sgVectorProductVec3( perp, normal, nup );
- // front face
+ // front face
sgVec3 tmp3;
sgCopyVec3( tmp3, pt );
vl->add( tmp3 );
<< 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 );
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] );
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 );
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] );
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 );
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;
}