Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / OpenGL / DebugCastResult.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
16 #ifndef DEBUG_CAST_RESULT_H
17 #define DEBUG_CAST_RESULT_H
18
19 #include "BulletCollision/NarrowPhaseCollision/btConvexCast.h"
20 #include "LinearMath/btTransform.h"
21 #include "GL_ShapeDrawer.h"
22 #include "GlutStuff.h"
23 #ifdef WIN32
24 #include <windows.h>
25 #endif
26 //think different
27 #if defined(__APPLE__) && !defined (VMDMESA)
28 #include <OpenGL/gl.h>
29 #include <OpenGL/glu.h>
30 #else
31 #include <GL/gl.h>
32 #endif
33 struct btDebugCastResult : public btConvexCast::CastResult
34 {
35
36         btTransform     m_fromTrans;
37         const btPolyhedralConvexShape* m_shape;
38         btVector3       m_linVel;
39         btVector3 m_angVel;
40         GL_ShapeDrawer* m_shapeDrawer;
41
42         btDebugCastResult(const btTransform& fromTrans,const btPolyhedralConvexShape* shape,
43                                         const btVector3& linVel,const btVector3& angVel,GL_ShapeDrawer* drawer)
44         :m_fromTrans(fromTrans),
45         m_shape(shape),
46         m_linVel(linVel),
47         m_angVel(angVel),
48         m_shapeDrawer(drawer)
49         {
50         }
51
52         virtual void drawCoordSystem(const btTransform& tr)  
53         {
54                 btScalar m[16];
55                 tr.getOpenGLMatrix(m);
56                 glPushMatrix();
57                 btglLoadMatrix(m);
58                 glBegin(GL_LINES);
59                 btglColor3(1, 0, 0);
60                 btglVertex3(0, 0, 0);
61                 btglVertex3(1, 0, 0);
62                 btglColor3(0, 1, 0);
63                 btglVertex3(0, 0, 0);
64                 btglVertex3(0, 1, 0);
65                 btglColor3(0, 0, 1);
66                 btglVertex3(0, 0, 0);
67                 btglVertex3(0, 0, 1);
68                 glEnd();
69                 glPopMatrix();
70         }
71
72         virtual void    DebugDraw(btScalar      fraction)
73         {
74                 btVector3 worldBoundsMin(-1000,-1000,-1000);
75                 btVector3 worldBoundsMax(1000,1000,1000);
76
77         
78                 ATTRIBUTE_ALIGNED16(btScalar) m[16];
79                 btTransform hitTrans;
80                 btTransformUtil::integrateTransform(m_fromTrans,m_linVel,m_angVel,fraction,hitTrans);
81                 hitTrans.getOpenGLMatrix(m);
82                 if (m_shapeDrawer)
83                         m_shapeDrawer->drawOpenGL(m,m_shape,btVector3(1,0,0),btIDebugDraw::DBG_NoDebug,worldBoundsMin,worldBoundsMax);
84         }
85 };
86
87
88 #endif //DEBUG_CAST_RESULT_H