Hi,
I am trying to make a scene with a Helicopter flying over a terrain and with 
the option to change its course or stop it in real time. I have been looking 
tutorial 8, and I have tried to do a modification to rotate tank instead the 
two DOF nodes. Here is the code, i have GTKviewer but it is possible to do with 
classic viewer.

Tuto_8.cpp

#include < osg/Group> 
#include < osg/Node>
#include < osgDB/ReadFile>
#include < osgViewer/Viewer>
#include < osgSim/DOFTransform>
#include < osgSim/MultiSwitch> 
#include < osgGA/TrackballManipulator>
 
#include "tankDataType.h"
#include "tankNodeCallback.h"
#include < gtk/gtk.h>
#include < ViewerGtk.h>

int main()
{

osg::Node* tankNode = NULL;
osg::Group* root = new osg::Group();
osgViewer::ViewerGtk viewer;
tankNode = osgDB::readNodeFile("./models/t72-tank_des.flt");
root->addChild(tankNode);

tankDataType* tankData = new tankDataType(tankNode);
tankNode->setUserData( tankData );
tankNode->setUpdateCallback(new tankNodeCallback);

osgGA::TrackballManipulator *Tman = new osgGA::TrackballManipulator();
viewer.setUpViewInWindow( 100, 100, 800, 650 );
viewer.setSceneData( root );
viewer.realize();
viewer.setCameraManipulator( Tman );

while( !viewer.done() )
{ 
viewer.frame();
}
}

tankDataType.cpp

#include "tankDataType.h"
      
tankDataType::tankDataType(osg::Node* n)
  {
     rotation    =  0;
  tank =  dynamic_cast< osgSim::DOFTransform*> (n);
}
 
void tankDataType::updateTurretRotation()
{
 rotation -= 0.01;
 tank->setCurrentHPR( osg::Vec3(rotation,0,0) );
}

tankDataType.h

#ifndef _TANKDATATYPE_H_
#include < osgSim/DOFTransform>
#include < osgSim/MultiSwitch> 

 class tankDataType : public osg::Referenced
 {
 public:
    tankDataType(osg::Node* n);
   
    void updateTurretRotation();

protected:
    osgSim::DOFTransform* tank;
    double rotation;

 };
 
 #endif

tankNodeCallBack.h

#ifndef _TANKNODECALLBACK_H_
 
 class tankNodeCallback : public osg::NodeCallback
 {
  public:
      virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
      {
          osg::ref_ptr<tankDataType> tankData = dynamic_cast<tankDataType*> 
(node->getUserData() );
 
         if(tankData != NULL)
         {
             tankData->updateTurretRotation(); 
         }
         traverse(node, nv);
     }
 };
 #endif



The code compiles but when run it gives the following error:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb5ae2a60 (LWP 502)]
tankDataType::updateTurretRotation (this=0x962b410) at 
/usr/local/include/osgSim/DOFTransform:48
48            void setCurrentHPR(const osg::Vec3& hpr) {_currentHPR = hpr; 
dirtyBound(); }

Any help is welcome!!!

Thank you!

Cheers,
Felipe

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=18779#18779





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to