Tizen 2.1 base
[platform/upstream/libbullet.git] / Demos / OpenGL / GL_ShapeDrawer.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose, 
8 including commercial applications, and to alter it and redistribute it freely, 
9 subject to the following restrictions:
10
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 #ifndef GL_SHAPE_DRAWER_H
16 #define GL_SHAPE_DRAWER_H
17
18 class btCollisionShape;
19 class btShapeHull;
20 #include "LinearMath/btAlignedObjectArray.h"
21 #include "LinearMath/btVector3.h"
22
23 #include "BulletCollision/CollisionShapes/btShapeHull.h"
24
25 /// OpenGL shape drawing
26 class GL_ShapeDrawer
27 {
28 protected:
29         struct ShapeCache
30         {
31         struct Edge { btVector3 n[2];int v[2]; };
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         
42
43         ShapeCache*                                                     cache(btConvexShape*);
44
45 public:
46                 GL_ShapeDrawer();
47
48                 virtual ~GL_ShapeDrawer();
49
50                 ///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
51                 virtual void            drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int       debugMode,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
52                 virtual void            drawShadow(btScalar* m, const btVector3& extrusion,const btCollisionShape* shape,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);
53                 
54                 bool            enableTexture(bool enable) { bool p=m_textureenabled;m_textureenabled=enable;return(p); }
55                 bool            hasTextureEnabled() const
56                 {
57                         return m_textureenabled;
58                 }
59                 
60                 static void             drawCylinder(float radius,float halfHeight, int upAxis);
61                 void                    drawSphere(btScalar r, int lats, int longs);
62                 static void             drawCoordSystem();
63                 
64 };
65
66 void OGL_displaylist_register_shape(btCollisionShape * shape);
67 void OGL_displaylist_clean();
68
69 #endif //GL_SHAPE_DRAWER_H
70