This commit is contained in:
Robert Osfield
2014-05-14 10:19:43 +00:00
parent 12a737ae02
commit 4174d72a52
37 changed files with 244 additions and 397 deletions

View File

@@ -812,9 +812,9 @@ class ShaderGeometry : public osg::Drawable
}
}
virtual osg::BoundingBox computeBound() const
virtual osg::BoundingBox computeBoundingBox() const
{
osg::BoundingBox geom_box = _geometry->getBound();
osg::BoundingBox geom_box = _geometry->getBoundingBox();
osg::BoundingBox bb;
for(PositionSizeList::const_iterator itr = _trees.begin();
itr != _trees.end();

View File

@@ -44,12 +44,12 @@ class CreateModelToSaveVisitor : public osg::NodeVisitor
public:
CreateModelToSaveVisitor():
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
_group = new osg::Group;
_addToModel = false;
}
virtual void apply(osg::Node& node)
{
osgFX::Scribe* scribe = dynamic_cast<osgFX::Scribe*>(&node);
@@ -65,7 +65,7 @@ public:
traverse(node);
}
}
osg::ref_ptr<osg::Group> _group;
bool _addToModel;
};
@@ -75,10 +75,10 @@ class DeleteSelectedNodesVisitor : public osg::NodeVisitor
public:
DeleteSelectedNodesVisitor():
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
}
virtual void apply(osg::Node& node)
{
osgFX::Scribe* scribe = dynamic_cast<osgFX::Scribe*>(&node);
@@ -91,7 +91,7 @@ public:
traverse(node);
}
}
void pruneSelectedNodes()
{
for(SelectedNodes::iterator itr = _selectedNodes.begin();
@@ -104,21 +104,21 @@ public:
pitr != parents.end();
++pitr)
{
osg::Group* parent = *pitr;
osg::Node* parent = *pitr;
parent->removeChild(node);
}
}
}
typedef std::vector< osg::ref_ptr<osgFX::Scribe> > SelectedNodes;
SelectedNodes _selectedNodes;
};
// class to handle events with a pick
class PickHandler : public osgGA::GUIEventHandler
class PickHandler : public osgGA::GUIEventHandler
{
public:
public:
PickHandler():
_mx(0.0),_my(0.0),
@@ -139,7 +139,7 @@ public:
if (ea.getKey()=='s')
{
saveSelectedModel(viewer->getSceneData());
}
}
else if (ea.getKey()=='o')
{
osg::notify(osg::NOTICE)<<"Saved model to file 'saved_model.osgt'"<<std::endl;
@@ -189,7 +189,7 @@ public:
pick(ea,viewer);
}
return true;
}
}
default:
return false;
@@ -248,7 +248,7 @@ public:
node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
parent = (nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0;
if (node) std::cout<<" Hits "<<node->className()<<" nodePath size "<<nodePath.size()<<std::endl;
if (node) std::cout<<" Hits "<<node->className()<<" nodePath size "<<nodePath.size()<<std::endl;
toggleScribe(parent, node);
}
@@ -284,7 +284,7 @@ public:
if (node) std::cout<<" Hits "<<node->className()<<" nodePath size"<<nodePath.size()<<std::endl;
toggleScribe(parent, node);
}
}
}
// now we try to decorate the hit node by the osgFX::Scribe to show that its been "picked"
}
@@ -319,10 +319,10 @@ public:
void saveSelectedModel(osg::Node* scene)
{
if (!scene) return;
CreateModelToSaveVisitor cmtsv;
scene->accept(cmtsv);
if (cmtsv._group->getNumChildren()>0)
{
std::cout<<"Writing selected compoents to 'selected_model.osgt'"<<std::endl;
@@ -340,19 +340,19 @@ protected:
int main( int argc, char **argv )
{
osg::ref_ptr<osg::Node> loadedModel;
// load the scene.
if (argc>1) loadedModel = osgDB::readNodeFile(argv[1]);
// if not loaded assume no arguments passed in, try use default mode instead.
if (!loadedModel) loadedModel = osgDB::readNodeFile("dumptruck.osgt");
if (!loadedModel)
if (!loadedModel)
{
std::cout << argv[0] <<": No data loaded." << std::endl;
return 1;
}
// create the window to draw to.
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 200;
@@ -376,7 +376,7 @@ int main( int argc, char **argv )
viewer.getCamera()->setGraphicsContext(gc.get());
viewer.getCamera()->setViewport(0,0,800,600);
viewer.setSceneData(loadedModel.get());
// create a tracball manipulator to move the camera around in response to keyboard/mouse events
viewer.setCameraManipulator( new osgGA::TrackballManipulator );

View File

@@ -81,7 +81,7 @@ public:
// an attempt to return a reasonable bounding box. Still does not prevent clipping of the heat map.
virtual const osg::BoundingBox& getBoundingBox() const {return m_bounds;}
virtual osg::BoundingBox computeBound() const {return m_bounds;}
virtual osg::BoundingBox computeBoundingBox() const {return m_bounds;}
virtual const osg::BoundingSphere& getBound() const {return m_bsphere;}
protected:

View File

@@ -42,33 +42,33 @@
// for the grid data..
#include "../osghangglide/terrain_coords.h"
osg::Vec3 wind(1.0f,0.0f,0.0f);
osg::Vec3 wind(1.0f,0.0f,0.0f);
osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime)
{
// set up the animation path
// set up the animation path
osg::AnimationPath* animationPath = new osg::AnimationPath;
animationPath->setLoopMode(osg::AnimationPath::LOOP);
int numSamples = 40;
float yaw = 0.0f;
float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f);
float roll = osg::inDegrees(30.0f);
double time=0.0f;
double time_delta = looptime/(double)numSamples;
for(int i=0;i<numSamples;++i)
{
osg::Vec3 position(center+osg::Vec3(sinf(yaw)*radius,cosf(yaw)*radius,0.0f));
osg::Quat rotation(osg::Quat(roll,osg::Vec3(0.0,1.0,0.0))*osg::Quat(-(yaw+osg::inDegrees(90.0f)),osg::Vec3(0.0,0.0,1.0)));
animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
yaw += yaw_delta;
time += time_delta;
}
return animationPath;
return animationPath;
}
osg::Node* createMovingModel(const osg::Vec3& center, float radius)
@@ -90,9 +90,9 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
positioned->setMatrix(osg::Matrix::translate(-bs.center())*
osg::Matrix::scale(size,size,size)*
osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,0.0f,1.0f));
positioned->addChild(glider);
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform;
xform->setDataVariance(osg::Object::DYNAMIC);
xform->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
@@ -101,7 +101,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
model->addChild(xform);
}
osg::Node* cessna = osgDB::readNodeFile("cessna.osgt");
if (cessna)
{
@@ -114,10 +114,10 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
positioned->setMatrix(osg::Matrix::translate(-bs.center())*
osg::Matrix::scale(size,size,size)*
osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,1.0f));
//positioned->addChild(cessna);
positioned->addChild(cessna);
osg::MatrixTransform* xform = new osg::MatrixTransform;
xform->setDataVariance(osg::Object::DYNAMIC);
xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,1.0));
@@ -125,7 +125,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius)
model->addChild(xform);
}
return model;
}
@@ -135,8 +135,8 @@ osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y)
const osg::BoundingSphere& bs = subgraph->getBound();
float zMax = bs.center().z()+bs.radius();
float zMin = bs.center().z()-bs.radius();
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
new osgUtil::LineSegmentIntersector(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax));
osgUtil::IntersectionVisitor iv(intersector.get());
@@ -190,13 +190,13 @@ void build_world(osg::Group *root)
}
}
terrainGeode->addDrawable(new osg::ShapeDrawable(grid));
root->addChild(terrainGeode);
}
}
// create particle effects
{
{
osg::Vec3 position = computeTerrainIntersection(terrainGeode,100.0f,100.0f);
osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 10.0f);
@@ -214,9 +214,9 @@ void build_world(osg::Group *root)
root->addChild(smoke);
root->addChild(fire);
}
// create particle effects
{
{
osg::Vec3 position = computeTerrainIntersection(terrainGeode,200.0f,100.0f);
osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 1.0f);
@@ -244,10 +244,10 @@ void build_world(osg::Group *root)
// class to handle events with a pick
class PickHandler : public osgGA::GUIEventHandler {
public:
public:
PickHandler() {}
PickHandler() {}
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
switch(ea.getEventType())
@@ -266,9 +266,9 @@ public:
void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter& ea)
{
osg::Group* root = dynamic_cast<osg::Group*>(viewer->getSceneData());
osg::Group* root = dynamic_cast<osg::Group*>(viewer->getSceneData());
if (!root) return;
osgUtil::LineSegmentIntersector::Intersections intersections;
if (viewer->computeIntersections(ea,intersections))
{
@@ -286,7 +286,7 @@ public:
if (transform->getDataVariance()==osg::Object::DYNAMIC) handleMovingModels=true;
}
}
osg::Vec3 position = handleMovingModels ? hit.getLocalIntersectPoint() : hit.getWorldIntersectPoint();
float scale = 10.0f * ((float)rand() / (float)RAND_MAX);
float intensity = 1.0f;
@@ -299,7 +299,7 @@ public:
smoke = new osgParticle::SmokeTrailEffect(position, scale, intensity);
else
smoke = new osgParticle::SmokeEffect(position, scale, intensity);
explosion->setWind(wind);
explosionDebri->setWind(wind);
smoke->setWind(wind);
@@ -310,17 +310,17 @@ public:
effectsGroup->addChild(explosionDebri);
effectsGroup->addChild(smoke);
effectsGroup->addChild(fire);
if (handleMovingModels)
{
// insert particle effects alongside the hit node, therefore able to track that nodes movement,
// however, this does require us to insert the ParticleSystem itself into the root of the scene graph
// separately from the the main particle effects group which contains the emitters and programs.
// the follow code block implements this, note the path for handling particle effects which arn't attached to
// the follow code block implements this, note the path for handling particle effects which arn't attached to
// moving models is easy - just a single line of code!
// tell the effects not to attach to the particle system locally for rendering, as we'll handle add it into the
// tell the effects not to attach to the particle system locally for rendering, as we'll handle add it into the
// scene graph ourselves.
explosion->setUseLocalParticleSystem(false);
explosionDebri->setUseLocalParticleSystem(false);
@@ -333,8 +333,8 @@ public:
// is found then this needs to be inserted above the hit node, and then the
// particle effect can be inserted into this.
osg::ref_ptr<osg::Node> hitNode = hit.nodePath.back();
osg::Node::ParentList parents = hitNode->getParents();
osg::Group* insertGroup = 0;
osg::Node::ParentList parents = hitNode->getParents();
osg::Node* insertGroup = 0;
unsigned int numGroupsFound = 0;
for(osg::Node::ParentList::iterator itr=parents.begin();
itr!=parents.end();
@@ -345,7 +345,7 @@ public:
++numGroupsFound;
insertGroup = *itr;
}
}
}
if (numGroupsFound==parents.size() && numGroupsFound==1 && insertGroup)
{
osg::notify(osg::INFO)<<"PickHandler::pick(,) hit node's parent is a single osg::Group so we can simple the insert the particle effects group here."<<std::endl;
@@ -354,7 +354,7 @@ public:
insertGroup->addChild(effectsGroup);
}
else
{
{
osg::notify(osg::INFO)<<"PickHandler::pick(,) hit node doesn't have an appropriate osg::Group node to insert particle effects into, inserting a new osg::Group."<<std::endl;
insertGroup = new osg::Group;
for(osg::Node::ParentList::iterator itr=parents.begin();
@@ -374,7 +374,7 @@ public:
geode->addDrawable(explosionDebri->getParticleSystem());
geode->addDrawable(smoke->getParticleSystem());
geode->addDrawable(fire->getParticleSystem());
root->addChild(geode);
}
@@ -385,15 +385,15 @@ public:
root->addChild(effectsGroup);
}
#if 0
#if 0
osg::Geode* geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(position,scale)));
group->addChild(geode);
#endif
}
}
protected:
virtual ~PickHandler() {}
};
@@ -403,7 +403,7 @@ void insertParticle(osg::Group* root, const osg::Vec3& center, float radius)
{
bool handleMovingModels = false;
osg::Vec3 position = center +
osg::Vec3 position = center +
osg::Vec3( radius * (((float)rand() / (float)RAND_MAX)-0.5)*2.0,
radius * (((float)rand() / (float)RAND_MAX)-0.5)*2.0,
0.0f);
@@ -445,15 +445,15 @@ int main(int, char **)
// register the pick handler
viewer.addEventHandler(new PickHandler());
osg::Group *root = new osg::Group;
build_world(root);
osgUtil::Optimizer optimizer;
optimizer.optimize(root);
// add a viewport to the viewer and attach the scene graph.
viewer.setSceneData(root);
return viewer.run();
}

View File

@@ -238,19 +238,19 @@ class Teapot : public osg::Drawable
// teapot(..) doens't use vertex arrays at all so we don't need to toggle their state
// if we did we'd need to something like following call
// state.disableAllVertexArrays(), see src/osg/Geometry.cpp for the low down.
// just call the OpenGL code.
teapot(14,GL_FILL);
}
// we need to set up the bounding box of the data too, so that the scene graph knows where this
// objects is, for both positioning the camera at start up, and most importantly for culling.
virtual osg::BoundingBox computeBound() const
virtual osg::BoundingBox computeBoundingBox() const
{
osg::BoundingBox bbox;
// follow is some truely horrible code required to calculate the
// follow is some truely horrible code required to calculate the
// bounding box of the teapot. Have used the original code above to do
// help compute it.
float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];
@@ -259,13 +259,13 @@ class Teapot : public osg::Drawable
for (i = 0; i < 10; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 4; k++) {
for (l = 0; l < 3; l++) {
p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l];
q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l];
if (l == 1)
q[j][k][l] *= -1.0;
if (i < 6) {
r[j][k][l] =
cpdata[patchdata[i][j * 4 + (3 - k)]][l];
@@ -278,7 +278,7 @@ class Teapot : public osg::Drawable
s[j][k][l] *= -1.0;
}
}
bbox.expandBy(osg::Vec3(p[j][k][0],p[j][k][1],p[j][k][2]));
bbox.expandBy(osg::Vec3(q[j][k][0],q[j][k][1],q[j][k][2]));
@@ -287,8 +287,8 @@ class Teapot : public osg::Drawable
bbox.expandBy(osg::Vec3(r[j][k][0],r[j][k][1],r[j][k][2]));
bbox.expandBy(osg::Vec3(s[j][k][0],s[j][k][1],s[j][k][2]));
}
}
}
}
@@ -297,9 +297,9 @@ class Teapot : public osg::Drawable
}
protected:
virtual ~Teapot() {}
};
@@ -310,7 +310,7 @@ osg::Geode* createTeapot()
// add the teapot to the geode.
geode->addDrawable( new Teapot );
// add a reflection map to the teapot.
// add a reflection map to the teapot.
osg::Image* image = osgDB::readImageFile("Images/reflect.rgb");
if (image)
{
@@ -323,10 +323,10 @@ osg::Geode* createTeapot()
osg::StateSet* stateset = new osg::StateSet;
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(0,texgen,osg::StateAttribute::ON);
geode->setStateSet(stateset);
}
return geode;
}
@@ -335,8 +335,8 @@ int main(int , char **)
#if 1
// create viewer on heap as a test, this looks to be causing problems
// on init on some platforms, and seg fault on exit when multi-threading on linux.
// Normal stack based version below works fine though...
// on init on some platforms, and seg fault on exit when multi-threading on linux.
// Normal stack based version below works fine though...
// construct the viewer.
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
@@ -345,7 +345,7 @@ int main(int , char **)
viewer->setSceneData( createTeapot() );
return viewer->run();
#else
// construct the viewer.