GL_ShapeDrawer.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef GL_SHAPE_DRAWER_H
  14. #define GL_SHAPE_DRAWER_H
  15. class btCollisionShape;
  16. class btShapeHull;
  17. class btDiscreteDynamicsWorld;
  18. #include "LinearMath/btAlignedObjectArray.h"
  19. #include "LinearMath/btVector3.h"
  20. #include "BulletCollision/CollisionShapes/btShapeHull.h"
  21. /// OpenGL shape drawing
  22. class GL_ShapeDrawer
  23. {
  24. protected:
  25. struct ShapeCache
  26. {
  27. struct Edge { btVector3 n[2];int v[2]; };
  28. ShapeCache(btConvexShape* s) : m_shapehull(s) {}
  29. btShapeHull m_shapehull;
  30. btAlignedObjectArray<Edge> m_edges;
  31. };
  32. //clean-up memory of dynamically created shape hulls
  33. btAlignedObjectArray<ShapeCache*> m_shapecaches;
  34. unsigned int m_texturehandle;
  35. bool m_textureenabled;
  36. bool m_textureinitialized;
  37. ShapeCache* cache(btConvexShape*);
  38. virtual void drawSceneInternal(const btDiscreteDynamicsWorld* world, int pass);
  39. public:
  40. GL_ShapeDrawer();
  41. virtual ~GL_ShapeDrawer();
  42. virtual void drawScene(const btDiscreteDynamicsWorld* world, bool useShadows);
  43. ///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
  44. virtual void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
  45. virtual void drawShadow(btScalar* m, const btVector3& extrusion,const btCollisionShape* shape,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
  46. bool enableTexture(bool enable) { bool p=m_textureenabled;m_textureenabled=enable;return(p); }
  47. bool hasTextureEnabled() const
  48. {
  49. return m_textureenabled;
  50. }
  51. void drawSphere(btScalar r, int lats, int longs);
  52. static void drawCoordSystem();
  53. };
  54. void OGL_displaylist_register_shape(btCollisionShape * shape);
  55. void OGL_displaylist_clean();
  56. #endif //GL_SHAPE_DRAWER_H