~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/bullet/Demos/ConvexHullDistance/ConvexHullDistanceDemo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
///
18
 
/// Convex Hull Distance Demo shows distance calculation between two convex hulls of points.
19
 
/// GJK with the VoronoiSimplexSolver is used.
20
 
///
21
 
 
22
 
#include "GL_Simplex1to4.h"
23
 
#include "SimdQuaternion.h"
24
 
#include "SimdTransform.h"
25
 
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
26
 
#include "CollisionShapes/ConvexHullShape.h"
27
 
 
28
 
#include "NarrowPhaseCollision/GjkPairDetector.h"
29
 
#include "NarrowPhaseCollision/PointCollector.h"
30
 
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
31
 
#include "NarrowPhaseCollision/ConvexPenetrationDepthSolver.h"
32
 
 
33
 
#include "GL_ShapeDrawer.h"
34
 
#ifdef WIN32 //needed for glut.h
35
 
#include <windows.h>
36
 
#endif
37
 
#include <GL/glut.h>
38
 
#include "GlutStuff.h"
39
 
 
40
 
 
41
 
float yaw=0.f,pitch=0.f,roll=0.f;
42
 
const int maxNumObjects = 4;
43
 
const int numObjects = 2;
44
 
 
45
 
GL_Simplex1to4 simplex;
46
 
 
47
 
PolyhedralConvexShape*  shapePtr[maxNumObjects];
48
 
 
49
 
SimdTransform tr[numObjects];
50
 
int screenWidth = 640.f;
51
 
int screenHeight = 480.f;
52
 
 
53
 
 
54
 
int main(int argc,char** argv)
55
 
{
56
 
        clientResetScene();
57
 
 
58
 
        SimdMatrix3x3 basisA;
59
 
        basisA.setIdentity();
60
 
 
61
 
        SimdMatrix3x3 basisB;
62
 
        basisB.setIdentity();
63
 
 
64
 
        tr[0].setBasis(basisA);
65
 
        tr[1].setBasis(basisB);
66
 
 
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)};
69
 
        
70
 
        ConvexHullShape hullA(points0,3);
71
 
        ConvexHullShape hullB(points1,5);
72
 
 
73
 
        shapePtr[0] = &hullA;
74
 
        shapePtr[1] = &hullB;
75
 
        
76
 
 
77
 
        SimdTransform tr;
78
 
        tr.setIdentity();
79
 
 
80
 
 
81
 
        return glutmain(argc, argv,screenWidth,screenHeight,"Convex Hull Distance Demo");
82
 
}
83
 
 
84
 
//to be implemented by the demo
85
 
 
86
 
void clientMoveAndDisplay()
87
 
{
88
 
        
89
 
        clientDisplay();
90
 
}
91
 
 
92
 
 
93
 
static VoronoiSimplexSolver sGjkSimplexSolver;
94
 
SimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
95
 
 
96
 
 
97
 
 
98
 
void clientDisplay(void) {
99
 
 
100
 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
101
 
        glDisable(GL_LIGHTING);
102
 
 
103
 
        //GL_ShapeDrawer::DrawCoordSystem();
104
 
 
105
 
        float m[16];
106
 
        int i;
107
 
 
108
 
        GjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
109
 
 
110
 
        SimdVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f);
111
 
        convexConvex.SetCachedSeperatingAxis(seperatingAxis);
112
 
 
113
 
        PointCollector gjkOutput;
114
 
        GjkPairDetector::ClosestPointInput input;
115
 
        input.m_transformA = tr[0];
116
 
        input.m_transformB = tr[1];
117
 
 
118
 
        convexConvex.GetClosestPoints(input ,gjkOutput,0);
119
 
 
120
 
        if (gjkOutput.m_hasResult)
121
 
        {
122
 
                SimdVector3 endPt = gjkOutput.m_pointInWorld +
123
 
                        gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
124
 
 
125
 
                 glBegin(GL_LINES);
126
 
                glColor3f(1, 0, 0);
127
 
                glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z());
128
 
                glVertex3d(endPt.x(),endPt.y(),endPt.z());
129
 
                glEnd();
130
 
 
131
 
        }
132
 
 
133
 
        for (i=0;i<numObjects;i++)
134
 
        {
135
 
                
136
 
                tr[i].getOpenGLMatrix( m );
137
 
 
138
 
                GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
139
 
 
140
 
 
141
 
        }
142
 
 
143
 
        simplex.SetSimplexSolver(&sGjkSimplexSolver);
144
 
        SimdPoint3 ybuf[4],pbuf[4],qbuf[4];
145
 
        int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
146
 
        simplex.Reset();
147
 
        
148
 
        for (i=0;i<numpoints;i++)
149
 
                simplex.AddVertex(ybuf[i]);
150
 
 
151
 
        SimdTransform ident;
152
 
        ident.setIdentity();
153
 
        ident.getOpenGLMatrix(m);
154
 
        GL_ShapeDrawer::DrawOpenGL(m,&simplex,SimdVector3(1,1,1),getDebugMode());
155
 
 
156
 
 
157
 
        SimdQuaternion orn;
158
 
        orn.setEuler(yaw,pitch,roll);
159
 
        tr[0].setRotation(orn);
160
 
        tr[1].setRotation(orn);
161
 
 
162
 
        pitch += 0.005f;
163
 
        yaw += 0.01f;
164
 
 
165
 
        glFlush();
166
 
    glutSwapBuffers();
167
 
}
168
 
 
169
 
void clientResetScene()
170
 
{
171
 
        tr[0].setOrigin(SimdVector3(0.0f,3.f,7.f));
172
 
        tr[1].setOrigin(SimdVector3(0.0f,9.f,2.f));
173
 
}
174
 
 
175
 
void clientKeyboard(unsigned char key, int x, int y)
176
 
{
177
 
        defaultKeyboard(key, x, y);
178
 
}
179
 
 
180
 
 
181
 
void clientMouseFunc(int button, int state, int x, int y)
182
 
{
183
 
 
184
 
}
185
 
 
186
 
void    clientMotionFunc(int x,int y)
187
 
{
188
 
}
 
 
b'\\ No newline at end of file'