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

« back to all changes in this revision

Viewing changes to extern/bullet/Demos/CollisionDemo/CollisionDemo.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
 
/// 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
20
 
///
21
 
 
22
 
#include "GL_Simplex1to4.h"
23
 
#include "SimdQuaternion.h"
24
 
#include "SimdTransform.h"
25
 
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
26
 
#include "CollisionShapes/BoxShape.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
 
void DrawRasterizerLine(float const* , float const*, int)
54
 
{
55
 
 
56
 
}
57
 
 
58
 
int main(int argc,char** argv)
59
 
{
60
 
        setCameraDistance(20.f);
61
 
 
62
 
        tr[0].setOrigin(SimdVector3(0.0013328250f,8.1363249f,7.0390840f));
63
 
        tr[1].setOrigin(SimdVector3(0.00000000f,9.1262732f,2.0343180f));
64
 
 
65
 
        //tr[0].setOrigin(SimdVector3(0,0,0));
66
 
        //tr[1].setOrigin(SimdVector3(0,10,0));
67
 
 
68
 
        SimdMatrix3x3 basisA;
69
 
        basisA.setValue(0.99999958f,0.00022980258f,0.00090992288f,
70
 
                -0.00029313788f,0.99753088f,0.070228584f,
71
 
                -0.00089153741f,-0.070228823f,0.99753052f);
72
 
 
73
 
        SimdMatrix3x3 basisB;
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);
77
 
 
78
 
        tr[0].setBasis(basisA);
79
 
        tr[1].setBasis(basisB);
80
 
 
81
 
 
82
 
 
83
 
        SimdVector3 boxHalfExtentsA(1.0000004768371582f,1.0000004768371582f,1.0000001192092896f);
84
 
        SimdVector3 boxHalfExtentsB(3.2836332321166992f,3.2836332321166992f,3.2836320400238037f);
85
 
 
86
 
        BoxShape        boxA(boxHalfExtentsA);
87
 
        BoxShape        boxB(boxHalfExtentsB);
88
 
        shapePtr[0] = &boxA;
89
 
        shapePtr[1] = &boxB;
90
 
        
91
 
 
92
 
        SimdTransform tr;
93
 
        tr.setIdentity();
94
 
 
95
 
 
96
 
        return glutmain(argc, argv,screenWidth,screenHeight,"Collision Demo");
97
 
}
98
 
 
99
 
//to be implemented by the demo
100
 
 
101
 
void clientMoveAndDisplay()
102
 
{
103
 
        
104
 
        clientDisplay();
105
 
}
106
 
 
107
 
 
108
 
static VoronoiSimplexSolver sGjkSimplexSolver;
109
 
SimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
110
 
 
111
 
 
112
 
 
113
 
void clientDisplay(void) {
114
 
 
115
 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
116
 
        glDisable(GL_LIGHTING);
117
 
 
118
 
        //GL_ShapeDrawer::DrawCoordSystem();
119
 
 
120
 
        float m[16];
121
 
        int i;
122
 
 
123
 
        GjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
124
 
 
125
 
        SimdVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f);
126
 
        convexConvex.SetCachedSeperatingAxis(seperatingAxis);
127
 
 
128
 
        PointCollector gjkOutput;
129
 
        GjkPairDetector::ClosestPointInput input;
130
 
        input.m_transformA = tr[0];
131
 
        input.m_transformB = tr[1];
132
 
 
133
 
        convexConvex.GetClosestPoints(input ,gjkOutput,0);
134
 
 
135
 
        if (gjkOutput.m_hasResult)
136
 
        {
137
 
                SimdVector3 endPt = gjkOutput.m_pointInWorld +
138
 
                        gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
139
 
 
140
 
                 glBegin(GL_LINES);
141
 
                glColor3f(1, 0, 0);
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());
146
 
                glEnd();
147
 
 
148
 
        }
149
 
 
150
 
        for (i=0;i<numObjects;i++)
151
 
        {
152
 
                
153
 
                tr[i].getOpenGLMatrix( m );
154
 
 
155
 
                GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
156
 
 
157
 
 
158
 
        }
159
 
 
160
 
        simplex.SetSimplexSolver(&sGjkSimplexSolver);
161
 
        SimdPoint3 ybuf[4],pbuf[4],qbuf[4];
162
 
        int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
163
 
        simplex.Reset();
164
 
        
165
 
        for (i=0;i<numpoints;i++)
166
 
                simplex.AddVertex(ybuf[i]);
167
 
 
168
 
        SimdTransform ident;
169
 
        ident.setIdentity();
170
 
        ident.getOpenGLMatrix(m);
171
 
        GL_ShapeDrawer::DrawOpenGL(m,&simplex,SimdVector3(1,1,1),getDebugMode());
172
 
 
173
 
 
174
 
        SimdQuaternion orn;
175
 
        orn.setEuler(yaw,pitch,roll);
176
 
        tr[0].setRotation(orn);
177
 
 
178
 
//      pitch += 0.005f;
179
 
//      yaw += 0.01f;
180
 
 
181
 
        glFlush();
182
 
    glutSwapBuffers();
183
 
}
184
 
 
185
 
 
186
 
 
187
 
 
188
 
 
189
 
void clientResetScene()
190
 
{
191
 
 
192
 
}
193
 
void clientKeyboard(unsigned char key, int x, int y)
194
 
{
195
 
        defaultKeyboard(key, x, y);
196
 
}
197
 
 
198
 
 
199
 
void clientMouseFunc(int button, int state, int x, int y)
200
 
{
201
 
 
202
 
}
203
 
void    clientMotionFunc(int x,int y)
204
 
{
205
 
}
 
 
b'\\ No newline at end of file'