vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PhysXObject.h
Go to the documentation of this file.
1 #ifndef PhysXObject_h
2 #define PhysXObject_h
3 
4 #include <osg/ShadeModel>
5 #include <osg/CullFace>
6 #include <osg/ShapeDrawable>
7 #include <osg/Geode>
8 
9 #include <NxPhysics.h>
10 #include <vrecko/Ability.h>
12 
13 using namespace vrecko;
14 
15 namespace PhysXPlugin
16 {
17  class PhysXObject: public Ability
18  {
19  PhysXObject() : Ability("PhysXObject_Generic") {}
20  public:
21  PhysXObject(const char* abName):Ability(abName){}
22  virtual ~PhysXObject(){}
23 
24  // metoda musi byt volana po nacteni xml ve vsech zdedenych tridach
25  // pretezujte metodu BeforeInitialization
26  virtual void preInitialize()
27  {
28  BeforeInitialization();
29  //_pPO = NULL;
30  _pPhysicsSDK = NULL;
31  _pPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
32  }
33 
34  // metoda musi byt volana po nacteni xml ve vsech zdedenych tridach
35  // pretezujte metodu AfterInitialization
36  virtual void postInitialize()
37  {
38  AfterInitialization();
39  }
40 
41  virtual void BeforeInitialization(){}
42  virtual void AfterInitialization(){}
43 
44 
45 
46 
47 
48  protected:
49 
50  bool addUserDrawable(osg::Drawable *userDrawable)
51  {
52  osg::Geode* main_geode = new osg::Geode;
53  main_geode->setName("userDrawable: "+userDrawable->getName());
54 
55  // z EnvironmentObject nastaveni state a cull mode
56  osg::StateSet* stateset2 = new osg::StateSet;
57  osg::ShadeModel* shademodel = new osg::ShadeModel;
58  shademodel->setMode(osg::ShadeModel::SMOOTH);
59  stateset2->setAttributeAndModes(shademodel,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
60  osg::CullFace *modelCullFace = new osg::CullFace();
61  modelCullFace->setMode(osg::CullFace::BACK);
62  stateset2->setAttributeAndModes(modelCullFace, osg::StateAttribute::ON);
63  main_geode->setStateSet(stateset2);
64 
65  main_geode->addDrawable(userDrawable/*new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0, 0.0, 0.0), 1.0, 0.05, 1.0), 0)*/);
66 
68  return pEO->setGeometry(main_geode);
69  }
70 
71  NxPhysicsSDK * _pPhysicsSDK;
72  };
73 }
74 
75 #endif