GL_ShapeDrawer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
  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
  28. {
  29. btVector3 n[2];
  30. int v[2];
  31. };
  32. ShapeCache(btConvexShape* s) : m_shapehull(s) {}
  33. btShapeHull m_shapehull;
  34. btAlignedObjectArray<Edge> m_edges;
  35. };
  36. //clean-up memory of dynamically created shape hulls
  37. btAlignedObjectArray<ShapeCache*> m_shapecaches;
  38. unsigned int m_texturehandle;
  39. bool m_textureenabled;
  40. bool m_textureinitialized;
  41. ShapeCache* cache(btConvexShape*);
  42. virtual void drawSceneInternal(const btDiscreteDynamicsWorld* world, int pass, int cameraUpAxis);
  43. public:
  44. GL_ShapeDrawer();
  45. virtual ~GL_ShapeDrawer();
  46. virtual void drawScene(const btDiscreteDynamicsWorld* world, bool useShadows, int cameraUpAxis);
  47. ///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
  48. virtual void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color, int debugMode, const btVector3& worldBoundsMin, const btVector3& worldBoundsMax);
  49. virtual void drawShadow(btScalar* m, const btVector3& extrusion, const btCollisionShape* shape, const btVector3& worldBoundsMin, const btVector3& worldBoundsMax);
  50. bool enableTexture(bool enable)
  51. {
  52. bool p = m_textureenabled;
  53. m_textureenabled = enable;
  54. return (p);
  55. }
  56. bool hasTextureEnabled() const
  57. {
  58. return m_textureenabled;
  59. }
  60. void drawSphere(btScalar r, int lats, int longs);
  61. static void drawCoordSystem();
  62. };
  63. void OGL_displaylist_register_shape(btCollisionShape* shape);
  64. void OGL_displaylist_clean();
  65. #endif //GL_SHAPE_DRAWER_H