From Tom Jolly, Fixes to osgSim::BlinkSequence to enable proper saving and
loading.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <osgSim/LightPointNode>
|
||||
|
||||
|
||||
|
||||
#define INTERPOLATE(member) lp.member = start.member*rstart + end.member*rend;
|
||||
|
||||
void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,osgSim::LightPoint& end,unsigned int noSteps)
|
||||
@@ -52,10 +53,10 @@ osg::Node* createLightPointsDatabase()
|
||||
osgSim::LightPoint start;
|
||||
osgSim::LightPoint end;
|
||||
|
||||
start._position.set(0.0f,0.0f,0.0f);
|
||||
start._position.set(-500.0f,-500.0f,0.0f);
|
||||
start._color.set(1.0f,0.0f,0.0f,1.0f);
|
||||
|
||||
end._position.set(1000.0f,0.0f,0.0f);
|
||||
end._position.set(500.0f,-500.0f,0.0f);
|
||||
end._color.set(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
osg::Transform* transform = new osg::Transform;
|
||||
@@ -107,6 +108,56 @@ osg::Node* createLightPointsDatabase()
|
||||
return group;
|
||||
}
|
||||
|
||||
static osg::Node* CreateBlinkSequenceLightNode()
|
||||
{
|
||||
osgSim::LightPointNode* lightPointNode = new osgSim::LightPointNode;;
|
||||
|
||||
osgSim::LightPointNode::LightPointList lpList;
|
||||
|
||||
osg::ref_ptr<osgSim::SequenceGroup> seq_0;
|
||||
seq_0 = new osgSim::SequenceGroup;
|
||||
seq_0->_baseTime = 0.0;
|
||||
|
||||
osg::ref_ptr<osgSim::SequenceGroup> seq_1;
|
||||
seq_1 = new osgSim::SequenceGroup;
|
||||
seq_1->_baseTime = 0.5;
|
||||
|
||||
const int max_points = 32;
|
||||
for( int i = 0; i < max_points; ++i )
|
||||
{
|
||||
osgSim::LightPoint lp;
|
||||
double x = cos( (2.0*osg::PI*i)/max_points );
|
||||
double z = sin( (2.0*osg::PI*i)/max_points );
|
||||
lp._position.set( x, 0.0f, z + 100.0f );
|
||||
lp._blinkSequence = new osgSim::BlinkSequence;
|
||||
for( int j = 10; j > 0; --j )
|
||||
{
|
||||
float intensity = j/10.0f;
|
||||
lp._blinkSequence->addPulse( 1.0/max_points,
|
||||
osg::Vec4( intensity, intensity, intensity, intensity ) );
|
||||
}
|
||||
if( max_points > 10 )
|
||||
{
|
||||
lp._blinkSequence->addPulse( 1.0 - 10.0/max_points,
|
||||
osg::Vec4( 0.0f, 0.0f, 0.0f, 0.0f ) );
|
||||
}
|
||||
|
||||
if( i & 1 )
|
||||
{
|
||||
lp._blinkSequence->setSequenceGroup( seq_1.get() );
|
||||
}
|
||||
else
|
||||
{
|
||||
lp._blinkSequence->setSequenceGroup( seq_0.get() );
|
||||
}
|
||||
lp._blinkSequence->setPhaseShift( i/(static_cast<double>(max_points)) );
|
||||
lpList.push_back( lp );
|
||||
}
|
||||
|
||||
lightPointNode->setLightPointList( lpList );
|
||||
|
||||
return lightPointNode;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
@@ -150,7 +201,7 @@ int main( int argc, char **argv )
|
||||
// load the nodes from the commandline arguments.
|
||||
rootnode->addChild(osgDB::readNodeFiles(arguments));
|
||||
rootnode->addChild(createLightPointsDatabase());
|
||||
|
||||
rootnode->addChild(CreateBlinkSequenceLightNode());
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
|
||||
@@ -26,24 +26,23 @@
|
||||
|
||||
namespace osgSim {
|
||||
|
||||
class OSGSIM_EXPORT BlinkSequence : public osg::Object
|
||||
/** sequence group which can be used to synchronize related blink sequences.*/
|
||||
class OSGSIM_EXPORT SequenceGroup : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
/** sequence group which can be used to synchronize related blink sequences.*/
|
||||
class OSGSIM_EXPORT SequenceGroup : public osg::Object
|
||||
{
|
||||
public:
|
||||
SequenceGroup();
|
||||
SequenceGroup(const SequenceGroup& bs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
SequenceGroup(double baseTime);
|
||||
|
||||
SequenceGroup();
|
||||
SequenceGroup(const SequenceGroup& bs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
SequenceGroup(double baseTime);
|
||||
META_Object(osgSim,SequenceGroup);
|
||||
|
||||
META_Object(osgSim,SequenceGroup);
|
||||
|
||||
double _baseTime;
|
||||
};
|
||||
double _baseTime;
|
||||
};
|
||||
|
||||
class OSGSIM_EXPORT BlinkSequence : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
BlinkSequence();
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ void BlinkSequence::read(DataInputStream* in){
|
||||
// Read in phase shift.
|
||||
setPhaseShift(in->readDouble());
|
||||
// Read in SequenceGroup
|
||||
setSequenceGroup(new SequenceGroup(in->readDouble()));
|
||||
setSequenceGroup(new osgSim::SequenceGroup(in->readDouble()));
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -51,8 +51,8 @@ bool BlinkSequence_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
BlinkSequence::SequenceGroup * sg = static_cast<BlinkSequence::SequenceGroup *>
|
||||
(fr.readObjectOfType(osgDB::type_wrapper<BlinkSequence::SequenceGroup>()));
|
||||
SequenceGroup * sg = static_cast<SequenceGroup *>
|
||||
(fr.readObjectOfType(osgDB::type_wrapper<SequenceGroup>()));
|
||||
|
||||
if (sg) {
|
||||
seq.setSequenceGroup(sg);
|
||||
@@ -88,9 +88,9 @@ bool BlinkSequence_SequenceGroup_writeLocalData(const osg::Object &obj, osgDB::O
|
||||
|
||||
osgDB::RegisterDotOsgWrapperProxy BlinkSequence_SequenceGroup_Proxy
|
||||
(
|
||||
new BlinkSequence::SequenceGroup,
|
||||
"BlinkSequence::SequenceGroup",
|
||||
"Object BlinkSequence::SequenceGroup",
|
||||
new SequenceGroup,
|
||||
"SequenceGroup",
|
||||
"Object SequenceGroup",
|
||||
&BlinkSequence_SequenceGroup_readLocalData,
|
||||
&BlinkSequence_SequenceGroup_writeLocalData,
|
||||
osgDB::DotOsgWrapper::READ_AND_WRITE
|
||||
@@ -99,7 +99,7 @@ osgDB::RegisterDotOsgWrapperProxy BlinkSequence_SequenceGroup_Proxy
|
||||
bool BlinkSequence_SequenceGroup_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
BlinkSequence::SequenceGroup &sg = static_cast<BlinkSequence::SequenceGroup &>(obj);
|
||||
SequenceGroup &sg = static_cast<SequenceGroup &>(obj);
|
||||
|
||||
if (fr.matchSequence("baseTime %f"))
|
||||
{
|
||||
@@ -113,7 +113,7 @@ bool BlinkSequence_SequenceGroup_readLocalData(osg::Object &obj, osgDB::Input &f
|
||||
|
||||
bool BlinkSequence_SequenceGroup_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const BlinkSequence::SequenceGroup &sg = static_cast<const BlinkSequence::SequenceGroup &>(obj);
|
||||
const SequenceGroup &sg = static_cast<const SequenceGroup &>(obj);
|
||||
|
||||
fw.indent()<<"baseTime "<< sg._baseTime << std::endl;
|
||||
return true;
|
||||
|
||||
@@ -35,19 +35,19 @@ BlinkSequence::BlinkSequence(const BlinkSequence& bs, const osg::CopyOp& copyop)
|
||||
}
|
||||
|
||||
|
||||
BlinkSequence::SequenceGroup::SequenceGroup()
|
||||
SequenceGroup::SequenceGroup()
|
||||
{
|
||||
// set a random base time between 0 and 1000.0
|
||||
_baseTime = ((double)rand()/(double)RAND_MAX)*1000.0;
|
||||
}
|
||||
|
||||
BlinkSequence::SequenceGroup::SequenceGroup(const BlinkSequence::SequenceGroup& sg, const osg::CopyOp& copyop):
|
||||
SequenceGroup::SequenceGroup(const SequenceGroup& sg, const osg::CopyOp& copyop):
|
||||
osg::Object(sg, copyop),
|
||||
_baseTime(sg._baseTime)
|
||||
{
|
||||
}
|
||||
|
||||
BlinkSequence::SequenceGroup::SequenceGroup(double baseTime):
|
||||
SequenceGroup::SequenceGroup(double baseTime):
|
||||
_baseTime(baseTime)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user