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
/// Collision Demo shows a degenerate case, where the Simplex solver has to deal with near-affine dependent cases
19
/// See the define CATCH_DEGENERATE_TETRAHEDRON in Bullet's VoronoiSimplexSolver.cpp
22
#include "GL_Simplex1to4.h"
23
#include "SimdQuaternion.h"
24
#include "SimdTransform.h"
25
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
26
#include "CollisionShapes/BoxShape.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;
53
void DrawRasterizerLine(float const* , float const*, int)
58
int main(int argc,char** argv)
60
setCameraDistance(20.f);
62
tr[0].setOrigin(SimdVector3(0.0013328250f,8.1363249f,7.0390840f));
63
tr[1].setOrigin(SimdVector3(0.00000000f,9.1262732f,2.0343180f));
65
//tr[0].setOrigin(SimdVector3(0,0,0));
66
//tr[1].setOrigin(SimdVector3(0,10,0));
69
basisA.setValue(0.99999958f,0.00022980258f,0.00090992288f,
70
-0.00029313788f,0.99753088f,0.070228584f,
71
-0.00089153741f,-0.070228823f,0.99753052f);
74
basisB.setValue(1.0000000f,4.4865553e-018f,-4.4410586e-017f,
75
4.4865495e-018f,0.97979438f,0.20000751f,
76
4.4410586e-017f,-0.20000751f,0.97979438f);
78
tr[0].setBasis(basisA);
79
tr[1].setBasis(basisB);
83
SimdVector3 boxHalfExtentsA(1.0000004768371582f,1.0000004768371582f,1.0000001192092896f);
84
SimdVector3 boxHalfExtentsB(3.2836332321166992f,3.2836332321166992f,3.2836320400238037f);
86
BoxShape boxA(boxHalfExtentsA);
87
BoxShape boxB(boxHalfExtentsB);
96
return glutmain(argc, argv,screenWidth,screenHeight,"Collision Demo");
99
//to be implemented by the demo
101
void clientMoveAndDisplay()
108
static VoronoiSimplexSolver sGjkSimplexSolver;
109
SimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
113
void clientDisplay(void) {
115
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
116
glDisable(GL_LIGHTING);
118
//GL_ShapeDrawer::DrawCoordSystem();
123
GjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
125
SimdVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f);
126
convexConvex.SetCachedSeperatingAxis(seperatingAxis);
128
PointCollector gjkOutput;
129
GjkPairDetector::ClosestPointInput input;
130
input.m_transformA = tr[0];
131
input.m_transformB = tr[1];
133
convexConvex.GetClosestPoints(input ,gjkOutput,0);
135
if (gjkOutput.m_hasResult)
137
SimdVector3 endPt = gjkOutput.m_pointInWorld +
138
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
142
glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z());
143
glVertex3d(endPt.x(),endPt.y(),endPt.z());
144
//glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z());
145
//glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z());
150
for (i=0;i<numObjects;i++)
153
tr[i].getOpenGLMatrix( m );
155
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
160
simplex.SetSimplexSolver(&sGjkSimplexSolver);
161
SimdPoint3 ybuf[4],pbuf[4],qbuf[4];
162
int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
165
for (i=0;i<numpoints;i++)
166
simplex.AddVertex(ybuf[i]);
170
ident.getOpenGLMatrix(m);
171
GL_ShapeDrawer::DrawOpenGL(m,&simplex,SimdVector3(1,1,1),getDebugMode());
175
orn.setEuler(yaw,pitch,roll);
176
tr[0].setRotation(orn);
189
void clientResetScene()
193
void clientKeyboard(unsigned char key, int x, int y)
195
defaultKeyboard(key, x, y);
199
void clientMouseFunc(int button, int state, int x, int y)
203
void clientMotionFunc(int x,int y)
b'\\ No newline at end of file'