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