2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
18
/// Convex Hull Distance Demo shows distance calculation between two convex hulls of points.
19
/// GJK with the VoronoiSimplexSolver is used.
22
#include "GL_Simplex1to4.h"
23
#include "SimdQuaternion.h"
24
#include "SimdTransform.h"
25
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
26
#include "CollisionShapes/ConvexHullShape.h"
28
#include "NarrowPhaseCollision/GjkPairDetector.h"
29
#include "NarrowPhaseCollision/PointCollector.h"
30
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
31
#include "NarrowPhaseCollision/ConvexPenetrationDepthSolver.h"
33
#include "GL_ShapeDrawer.h"
34
#ifdef WIN32 //needed for glut.h
38
#include "GlutStuff.h"
41
float yaw=0.f,pitch=0.f,roll=0.f;
42
const int maxNumObjects = 4;
43
const int numObjects = 2;
45
GL_Simplex1to4 simplex;
47
PolyhedralConvexShape* shapePtr[maxNumObjects];
49
SimdTransform tr[numObjects];
50
int screenWidth = 640.f;
51
int screenHeight = 480.f;
54
int main(int argc,char** argv)
64
tr[0].setBasis(basisA);
65
tr[1].setBasis(basisB);
67
SimdPoint3 points0[3]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1)};
68
SimdPoint3 points1[5]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1),SimdPoint3(0,0,-1),SimdPoint3(-1,-1,0)};
70
ConvexHullShape hullA(points0,3);
71
ConvexHullShape hullB(points1,5);
81
return glutmain(argc, argv,screenWidth,screenHeight,"Convex Hull Distance Demo");
84
//to be implemented by the demo
86
void clientMoveAndDisplay()
93
static VoronoiSimplexSolver sGjkSimplexSolver;
94
SimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
98
void clientDisplay(void) {
100
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
101
glDisable(GL_LIGHTING);
103
//GL_ShapeDrawer::DrawCoordSystem();
108
GjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
110
SimdVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f);
111
convexConvex.SetCachedSeperatingAxis(seperatingAxis);
113
PointCollector gjkOutput;
114
GjkPairDetector::ClosestPointInput input;
115
input.m_transformA = tr[0];
116
input.m_transformB = tr[1];
118
convexConvex.GetClosestPoints(input ,gjkOutput,0);
120
if (gjkOutput.m_hasResult)
122
SimdVector3 endPt = gjkOutput.m_pointInWorld +
123
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
127
glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z());
128
glVertex3d(endPt.x(),endPt.y(),endPt.z());
133
for (i=0;i<numObjects;i++)
136
tr[i].getOpenGLMatrix( m );
138
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
143
simplex.SetSimplexSolver(&sGjkSimplexSolver);
144
SimdPoint3 ybuf[4],pbuf[4],qbuf[4];
145
int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
148
for (i=0;i<numpoints;i++)
149
simplex.AddVertex(ybuf[i]);
153
ident.getOpenGLMatrix(m);
154
GL_ShapeDrawer::DrawOpenGL(m,&simplex,SimdVector3(1,1,1),getDebugMode());
158
orn.setEuler(yaw,pitch,roll);
159
tr[0].setRotation(orn);
160
tr[1].setRotation(orn);
169
void clientResetScene()
171
tr[0].setOrigin(SimdVector3(0.0f,3.f,7.f));
172
tr[1].setOrigin(SimdVector3(0.0f,9.f,2.f));
175
void clientKeyboard(unsigned char key, int x, int y)
177
defaultKeyboard(key, x, y);
181
void clientMouseFunc(int button, int state, int x, int y)
186
void clientMotionFunc(int x,int y)
b'\\ No newline at end of file'