Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Demos / OpenGL / GL_Simplex1to4.cpp
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 #include "GL_Simplex1to4.h"
16 #include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
17 #include "GL_ShapeDrawer.h"
18 #ifdef _WIN32
19 #include <windows.h>
20 #endif
21
22 //think different
23 #if defined(__APPLE__) && !defined (VMDMESA)
24 #include <OpenGL/gl.h>
25 #include <OpenGL/glu.h>
26 #else
27 #include <GL/gl.h>
28 #endif
29 #include "GlutStuff.h"
30 #include "LinearMath/btTransform.h"
31
32 GL_Simplex1to4::GL_Simplex1to4()
33 :m_simplexSolver(0)
34 {
35 }
36
37 ///
38 /// Debugging method calcClosest calculates the closest point to the origin, using m_simplexSolver
39 ///
40 void    GL_Simplex1to4::calcClosest(btScalar* m)
41 {
42         btTransform tr;
43         tr.setFromOpenGLMatrix(m);
44         
45
46
47                         GL_ShapeDrawer::drawCoordSystem();
48                         
49                         if (m_simplexSolver)
50                         {
51                                 m_simplexSolver->reset();
52                                 bool res;
53
54                                 btVector3 v;
55
56                                 for (int i=0;i<m_numVertices;i++)
57                                 {
58                                         v =  tr(m_vertices[i]);
59                                         m_simplexSolver->addVertex(v,v,btVector3(0.f,0.f,0.f));
60                                         res = m_simplexSolver->closest(v);
61                                 }
62
63                                 //draw v?
64                                 glDisable(GL_LIGHTING);
65                                 glBegin(GL_LINES);
66                                 btglColor3(1.f, 0.f, 0.f);
67                                 btglVertex3(0.f, 0.f, 0.f);
68                                 btglVertex3(v.x(),v.y(),v.z());
69                                 glEnd();
70                                 
71                                 glEnable(GL_LIGHTING);
72
73
74                         }
75
76 }