vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ClothDrawable.h
Go to the documentation of this file.
1 #ifndef ClothDrawable_h
2 #define ClothDrawable_h
3 
4 #include <gl/glut.h>
5 #include <osg/Drawable>
6 #include <osg/Vec3>
7 #include "NxPhysics.h"
8 #include "Cloth.h"
9 #include "Helper.h"
10 #include <cloth/NxCloth.h>
11 
12 
13 using namespace vrecko;
14 
15 namespace PhysXPlugin
16 {
17  class ClothDrawable : public osg::Drawable
18  {
19  friend class Cloth;
20  private:
21 
22  NxCloth* _pCloth;
23  NxMeshData _meshData;
24 
25 
26  protected:
27 
28 
29 
30  void PCloth(NxCloth* val) { _pCloth = val; }
31 
32  ClothDrawable& operator = (const ClothDrawable&) { return *this;}
33 
34 
35 
36 
37  public:
39  {
40  this->setSupportsDisplayList(false);
41  }
42 
43  ClothDrawable (NxCloth* pCloth)
44  {
45  glEnableClientState(GL_VERTEX_ARRAY);
46  glEnableClientState(GL_NORMAL_ARRAY);
47  _pCloth = pCloth;
48  _meshData = _pCloth->getMeshData();
49  this->setSupportsDisplayList(false);
50  dirtyBound();
51  }
52 
53  virtual ~ClothDrawable(){}
54 
55 
56  ClothDrawable(const ClothDrawable& drawable,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
57  Drawable(drawable,copyop)
58  {}
59 
60  virtual osg::Object* cloneType() const { return new ClothDrawable(); }
61 
62  virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new ClothDrawable(*this,copyop); }
63 
64 
65  // test purpose only. Predelat na dynamicky VBO
66  virtual void drawImplementation(osg::RenderInfo& renderInfo) const
67  {
68 
69  glVertexPointer(3, GL_FLOAT, 0, _meshData.verticesPosBegin);
70  glNormalPointer(GL_FLOAT, 0, _meshData.verticesNormalBegin);
71 
72  glDrawElements(GL_TRIANGLES, *_meshData.numIndicesPtr, GL_UNSIGNED_INT, _meshData.indicesBegin);
73  }
74 
75  virtual void Update()
76  {
77  dirtyBound();
78  }
79 
80 
81 
82 
83 
84  virtual bool isSameKindAs(const osg::Object* obj)const {return dynamic_cast<const ClothDrawable*>(obj)!=NULL;}
85  virtual const char* libaryName() const {return "PhysX";} //pak zmenit
86  virtual const char* className() const {return "ClothDrawable";}
87 
88 
89 
90  virtual osg::BoundingBox computeBound() const
91  {
92  NxBounds3 Nxbbox;
93  _pCloth->getWorldBounds(Nxbbox);
94 
95  osg::BoundingBox bbox;
96  bbox.expandBy(ToosgVec3(Nxbbox.min));
97  bbox.expandBy(ToosgVec3(Nxbbox.max));
98 
99  return bbox;
100  }
101 
102  };
103 }
104 
105 #endif