demo cleanup part 3 (fixed memory leaks in raytracer demo and linear convex cast demo)
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
* Permission to use, copy, modify, distribute and sell this software
|
* Permission to use, copy, modify, distribute and sell this software
|
||||||
* and its documentation for any purpose is hereby granted without fee,
|
* and its documentation for any purpose is hereby granted without fee,
|
||||||
* provided that the above copyright notice appear in all copies.
|
* provided that the above copyright notice appear in all copies.
|
||||||
* Erwin Coumans makes no representations about the suitability
|
* Erwin Coumans makes no representations about the suitability
|
||||||
* of this software for any purpose.
|
* of this software for any purpose.
|
||||||
* It is provided "as is" without express or implied warranty.
|
* It is provided "as is" without express or implied warranty.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
LinearConvexCastDemo implements an efficient continuous collision detection algorithm.
|
LinearConvexCastDemo implements an efficient continuous collision detection algorithm.
|
||||||
Both linear and angular velocities are supported. Gjk or Simplex based methods.
|
Both linear and angular velocities are supported. Gjk or Simplex based methods.
|
||||||
Motion using Exponential Map.
|
Motion using Exponential Map.
|
||||||
Comparison with Screwing Motion.
|
Comparison with Screwing Motion.
|
||||||
Also comparision with Algebraic CCD and Interval Arithmetic methods (Stephane Redon)
|
Also comparision with Algebraic CCD and Interval Arithmetic methods (Stephane Redon)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -23,201 +23,136 @@
|
|||||||
///Low level demo, doesn't include btBulletCollisionCommon.h
|
///Low level demo, doesn't include btBulletCollisionCommon.h
|
||||||
#include "LinearMath/btQuaternion.h"
|
#include "LinearMath/btQuaternion.h"
|
||||||
#include "LinearMath/btTransform.h"
|
#include "LinearMath/btTransform.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
|
||||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||||
|
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
|
#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
|
||||||
|
|
||||||
|
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
|
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
|
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
|
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
||||||
|
|
||||||
#ifdef USE_ALGEBRAIC_CCD
|
|
||||||
#include "NarrowPhaseCollision/BU_CollisionPair.h"
|
|
||||||
#endif //USE_ALGEBRAIC_CCD
|
|
||||||
|
|
||||||
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
|
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
|
||||||
|
|
||||||
|
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||||
|
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "GL_ShapeDrawer.h"
|
#include "GL_ShapeDrawer.h"
|
||||||
#include "LinearConvexCastDemo.h"
|
#include "LinearConvexCastDemo.h"
|
||||||
#include "GlutStuff.h"
|
#include "GlutStuff.h"
|
||||||
|
|
||||||
|
static btVoronoiSimplexSolver sVoronoiSimplexSolver;
|
||||||
|
btSimplexSolverInterface& gGjkSimplexSolver = sVoronoiSimplexSolver;
|
||||||
|
|
||||||
static float yaw=0.f,pitch=0.f,roll=0.f;
|
static float yaw=0.f,pitch=0.f,roll=0.f;
|
||||||
static const int maxNumObjects = 4;
|
static const int maxNumObjects = 4;
|
||||||
static const int numObjects = 2;
|
static const int numObjects = 2;
|
||||||
|
|
||||||
|
|
||||||
static btPolyhedralConvexShape* shapePtr[maxNumObjects];
|
static btPolyhedralConvexShape* shapePtr[maxNumObjects];
|
||||||
|
|
||||||
static btTransform tr[numObjects];
|
static btTransform tr[numObjects];
|
||||||
void DrawRasterizerLine(float const* , float const*, int)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LinearConvexCastDemo::initPhysics()
|
void LinearConvexCastDemo::initPhysics()
|
||||||
{
|
{
|
||||||
|
|
||||||
setCameraDistance(50.f);
|
setCameraDistance(10.f);
|
||||||
tr[0].setOrigin(btVector3(0,0,0));
|
|
||||||
tr[1].setOrigin(btVector3(0,10,0));
|
|
||||||
|
|
||||||
btMatrix3x3 basisA;
|
tr[0].setIdentity();
|
||||||
basisA.setValue(0.99999958f,0.00022980258f,0.00090992288f,
|
tr[0].setOrigin( btVector3( 0.0f, 5.5f, 0.0f ) );
|
||||||
-0.00029313788f,0.99753088f,0.070228584f,
|
|
||||||
-0.00089153741f,-0.070228823f,0.99753052f);
|
|
||||||
|
|
||||||
btMatrix3x3 basisB;
|
tr[1].setIdentity();
|
||||||
basisB.setValue(1.0000000f,4.4865553e-018f,-4.4410586e-017f,
|
tr[1].setOrigin( btVector3( 0.0f, 0.0f, 0.0f ) );
|
||||||
4.4865495e-018f,0.97979438f,0.20000751f,
|
|
||||||
4.4410586e-017f,-0.20000751f,0.97979438f);
|
|
||||||
|
|
||||||
tr[0].setBasis(basisA);
|
// Pyramide
|
||||||
tr[1].setBasis(basisB);
|
float r = 1.0f;
|
||||||
|
float h = 2.0f;
|
||||||
|
|
||||||
|
btConvexHullShape* shapeA = new btConvexHullShape;
|
||||||
|
shapeA->addPoint( btVector3( 0.0f, 0.75f * h, 0.0f ) );
|
||||||
|
shapeA->addPoint( btVector3( -r, -0.25f * h, r ) );
|
||||||
|
shapeA->addPoint( btVector3( r, -0.25f * h, r ) );
|
||||||
|
shapeA->addPoint( btVector3( r, -0.25f * h, -r ) );
|
||||||
|
shapeA->addPoint( btVector3( -r, -0.25f * h, -r ) );
|
||||||
|
|
||||||
|
|
||||||
|
// Triangle
|
||||||
|
btConvexHullShape* shapeB = new btConvexHullShape;
|
||||||
|
shapeB->addPoint( btVector3( 0.0f, 1.0f, 0.0f ) );
|
||||||
|
shapeB->addPoint( btVector3( 1.0f, -1.0f, 0.0f ) );
|
||||||
|
shapeB->addPoint( btVector3( -1.0f, -1.0f, 0.0f ) );
|
||||||
|
|
||||||
btVector3 boxHalfExtentsA(0.2,4,4);
|
shapePtr[0] = shapeA;
|
||||||
btVector3 boxHalfExtentsB(6,6,6);
|
shapePtr[1] = shapeB;
|
||||||
|
|
||||||
btBoxShape* boxA = new btBoxShape(boxHalfExtentsA);
|
shapePtr[0]->setMargin( 0.01f );
|
||||||
/* btBU_Simplex1to4 boxB;
|
shapePtr[1]->setMargin( 0.01f );
|
||||||
boxB.addVertex(btPoint3(-5,0,-5));
|
|
||||||
boxB.addVertex(btPoint3(5,0,-5));
|
|
||||||
boxB.addVertex(btPoint3(0,0,5));
|
|
||||||
boxB.addVertex(btPoint3(0,5,0));
|
|
||||||
*/
|
|
||||||
|
|
||||||
btBoxShape* boxB = new btBoxShape(boxHalfExtentsB);
|
|
||||||
shapePtr[0] = boxA;
|
|
||||||
shapePtr[1] = boxB;
|
|
||||||
|
|
||||||
shapePtr[0]->setMargin(0.01f);
|
|
||||||
shapePtr[1]->setMargin(0.01f);
|
|
||||||
|
|
||||||
btTransform tr;
|
|
||||||
tr.setIdentity();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//to be implemented by the demo
|
//to be implemented by the demo
|
||||||
|
|
||||||
void LinearConvexCastDemo::clientMoveAndDisplay()
|
void LinearConvexCastDemo::clientMoveAndDisplay()
|
||||||
{
|
{
|
||||||
|
|
||||||
displayCallback();
|
displayCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
LinearConvexCastDemo::~LinearConvexCastDemo()
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
|
{
|
||||||
|
delete shapePtr[0];
|
||||||
|
delete shapePtr[1];
|
||||||
|
}
|
||||||
|
|
||||||
static btVoronoiSimplexSolver sVoronoiSimplexSolver;
|
void LinearConvexCastDemo::displayCallback(void)
|
||||||
|
|
||||||
btSimplexSolverInterface& gGjkSimplexSolver = sVoronoiSimplexSolver;
|
|
||||||
|
|
||||||
bool drawLine= false;
|
|
||||||
|
|
||||||
void LinearConvexCastDemo::displayCallback(void)
|
|
||||||
{
|
{
|
||||||
updateCamera();
|
updateCamera();
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
//GL_ShapeDrawer::drawCoordSystem();
|
GL_ShapeDrawer::drawCoordSystem();
|
||||||
|
|
||||||
btScalar m[16];
|
btTransform toA, toB;
|
||||||
int i;
|
toA.setIdentity();
|
||||||
|
toA.setOrigin( btVector3( 0.0f, 1.5f, 0.0f ) );
|
||||||
for (i=0;i<numObjects;i++)
|
toB.setIdentity();
|
||||||
{
|
toB.setOrigin( btVector3( 0.0f, 4.0f, 0.0f ) );
|
||||||
tr[i].getOpenGLMatrix( m );
|
|
||||||
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int shapeIndex = 1;
|
|
||||||
|
|
||||||
btQuaternion orn;
|
|
||||||
orn.setEuler(yaw,pitch,roll);
|
|
||||||
tr[shapeIndex].setRotation(orn);
|
|
||||||
|
|
||||||
|
|
||||||
if (m_stepping || m_singleStep)
|
|
||||||
{
|
|
||||||
m_singleStep = false;
|
|
||||||
pitch += 0.005f;
|
|
||||||
yaw += 0.01f;
|
|
||||||
}
|
|
||||||
|
|
||||||
btVector3 fromA(-25,11,0);
|
|
||||||
btVector3 toA(15,11,0);
|
|
||||||
|
|
||||||
btQuaternion ornFromA(0.f,0.f,0.f,1.f);
|
|
||||||
btQuaternion ornToA(0.f,0.f,0.f,1.f);
|
|
||||||
|
|
||||||
btTransform rayFromWorld(ornFromA,fromA);
|
|
||||||
btTransform rayToWorld(ornToA,toA);
|
|
||||||
|
|
||||||
tr[0] = rayFromWorld;
|
|
||||||
|
|
||||||
if (drawLine)
|
|
||||||
{
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glColor3f(0, 0, 1);
|
|
||||||
glVertex3d(rayFromWorld.getOrigin().x(), rayFromWorld.getOrigin().y(),rayFromWorld.getOrigin().z());
|
|
||||||
glVertex3d(rayToWorld.getOrigin().x(),rayToWorld.getOrigin().y(),rayToWorld.getOrigin().z());
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
//now perform a raycast on the shapes, in local (shape) space
|
|
||||||
|
|
||||||
//choose one of the following lines
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (i=1;i<numObjects;i++)
|
|
||||||
{
|
|
||||||
btContinuousConvexCollision convexCaster0(shapePtr[0],shapePtr[i],&gGjkSimplexSolver,0);
|
|
||||||
btGjkConvexCast convexCaster1(shapePtr[0],shapePtr[i],&gGjkSimplexSolver);
|
|
||||||
|
|
||||||
//BU_CollisionPair (algebraic version) is currently broken, will look into this
|
|
||||||
//BU_CollisionPair convexCaster2(shapePtr[0],shapePtr[i]);
|
|
||||||
btSubsimplexConvexCast convexCaster3(shapePtr[0],shapePtr[i],&gGjkSimplexSolver);
|
|
||||||
|
|
||||||
gGjkSimplexSolver.reset();
|
|
||||||
|
|
||||||
btConvexCast::CastResult rayResult;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (convexCaster3.calcTimeOfImpact(rayFromWorld,rayToWorld,tr[i],tr[i],rayResult))
|
|
||||||
{
|
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
btVector3 hitPoint;
|
|
||||||
hitPoint.setInterpolate3(rayFromWorld.getOrigin(),rayToWorld.getOrigin(),rayResult.m_fraction);
|
|
||||||
|
|
||||||
//draw the raycast result
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glColor3f(1, 1, 1);
|
|
||||||
glVertex3d(rayFromWorld.getOrigin().x(), rayFromWorld.getOrigin().y(),rayFromWorld.getOrigin().z());
|
|
||||||
glVertex3d(hitPoint.x(),hitPoint.y(),hitPoint.z());
|
|
||||||
glEnd();
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
btTransform toTransWorld;
|
|
||||||
toTransWorld = tr[0];
|
|
||||||
toTransWorld.setOrigin(hitPoint);
|
|
||||||
|
|
||||||
toTransWorld.getOpenGLMatrix( m );
|
|
||||||
GL_ShapeDrawer::drawOpenGL(m,shapePtr[0],btVector3(0,1,1),getDebugMode());
|
|
||||||
|
|
||||||
|
|
||||||
}
|
gGjkSimplexSolver.reset();
|
||||||
}
|
btSubsimplexConvexCast convexCaster( shapePtr[ 0 ], shapePtr[ 1 ], &gGjkSimplexSolver );
|
||||||
|
|
||||||
|
btConvexCast::CastResult result;
|
||||||
|
convexCaster.calcTimeOfImpact( tr[ 0 ], toA, tr[ 1 ], toB, result );
|
||||||
|
|
||||||
|
btScalar m1[16], m2[16];
|
||||||
|
tr[ 0 ].getOpenGLMatrix( m1 );
|
||||||
|
tr[ 1 ].getOpenGLMatrix( m2 );
|
||||||
|
|
||||||
|
GL_ShapeDrawer::drawOpenGL( m1, shapePtr[ 0 ], btVector3( 1, 0, 0 ), getDebugMode() );
|
||||||
|
GL_ShapeDrawer::drawOpenGL( m2, shapePtr[ 1 ], btVector3( 1, 0, 0 ), getDebugMode() );
|
||||||
|
|
||||||
|
btVector3 originA, originB;
|
||||||
|
originA.setInterpolate3( tr[ 0 ].getOrigin(), toA.getOrigin(), result.m_fraction );
|
||||||
|
originB.setInterpolate3( tr[ 1 ].getOrigin(), toB.getOrigin(), result.m_fraction );
|
||||||
|
|
||||||
|
btTransform A = tr[ 0 ];
|
||||||
|
A.setOrigin( originA );
|
||||||
|
|
||||||
|
btTransform B = tr[ 1 ];
|
||||||
|
B.setOrigin( originB );
|
||||||
|
|
||||||
|
A.getOpenGLMatrix( m1 );
|
||||||
|
B.getOpenGLMatrix( m2 );
|
||||||
|
|
||||||
|
GL_ShapeDrawer::drawOpenGL( m1, shapePtr[ 0 ], btVector3( 1, 1, 0 ), getDebugMode() );
|
||||||
|
GL_ShapeDrawer::drawOpenGL( m2, shapePtr[ 1 ], btVector3( 1, 1, 0 ), getDebugMode() );
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ class LinearConvexCastDemo : public DemoApplication
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual ~LinearConvexCastDemo();
|
||||||
|
|
||||||
void initPhysics();
|
void initPhysics();
|
||||||
|
|
||||||
virtual void clientMoveAndDisplay();
|
virtual void clientMoveAndDisplay();
|
||||||
|
|||||||
@@ -11,48 +11,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define IN_TO_M_CONSTANT (0.0254f)
|
|
||||||
#define M_TO_IN_CONSTANT (39.3700787f)
|
|
||||||
#define CM_TO_IN_CONSTANT (0.393700787f)
|
|
||||||
#define LBS_TO_KG_CONSTANT (0.45359237f)
|
|
||||||
|
|
||||||
#define FEET_TO_IN(x) (12.0f * (float)(x))
|
|
||||||
#define IN_TO_FT(x) ((float)(x)/12.0f)
|
|
||||||
#define IN_TO_M(x) ((float)(x) * IN_TO_M_CONSTANT)
|
|
||||||
#define M_TO_IN(x) ((float)(x) * M_TO_IN_CONSTANT)
|
|
||||||
#define CM_TO_IN(x) ((float)(x) * CM_TO_IN_CONSTANT)
|
|
||||||
#define FT_TO_M(x) (IN_TO_M(FEET_TO_IN(x)))
|
|
||||||
#define LBS_TO_KG(x) ((float)(x) * LBS_TO_KG_CONSTANT)
|
|
||||||
|
|
||||||
#define PIN_HEIGHT IN_TO_M(15.0f)
|
|
||||||
#define PIN_DIAMETER IN_TO_M(4.76f)
|
|
||||||
#define PIN_MASS LBS_TO_KG(3.5f)
|
|
||||||
#define PIN_FRICTION (BALL_FRICTION) // a guess
|
|
||||||
//#define PIN_COR (0.67f) // was 0.67
|
|
||||||
#define PIN_COR (0.2f)
|
|
||||||
|
|
||||||
#define BALL_DIAMETER IN_TO_M(8.55f)
|
|
||||||
#define BALL_MASS LBS_TO_KG(16.0f)
|
|
||||||
#define BALL_FRICTION (0.3f) // max is 0.32
|
|
||||||
#define BALL_COR (0.7)
|
|
||||||
#define BALL_MAX_FRICTION (0.32f)
|
|
||||||
#define BALL_MAX_MASS (16.0f) // lbs
|
|
||||||
#define BALL_MIN_MASS (8.0f) // lbs
|
|
||||||
|
|
||||||
#define LANE_DECK_FUDGE (IN_TO_M(6.0f))
|
|
||||||
|
|
||||||
#define LANE_WIDTH IN_TO_M(42.0f)
|
|
||||||
#define LANE_TOTAL_WIDTH IN_TO_M(62.88f)
|
|
||||||
#define LANE_LENGTH FT_TO_M(60.0f-LANE_DECK_FUDGE)
|
|
||||||
|
|
||||||
#define GRAVITY_VECTOR (btVector3(0.0f,-9.81f,0.0f))
|
|
||||||
|
|
||||||
#define PIN_Z_DIST IN_TO_M(10.3923048f)
|
|
||||||
#define PIN_Y_DIST IN_TO_M(12.0f)
|
|
||||||
|
|
||||||
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Raytracer uses the Convex rayCast to visualize the Collision Shapes/Minkowski Sum.
|
Raytracer uses the Convex rayCast to visualize the Collision Shapes/Minkowski Sum.
|
||||||
Very basic raytracer, rendering into a texture.
|
Very basic raytracer, rendering into a texture.
|
||||||
@@ -60,7 +20,6 @@ Very basic raytracer, rendering into a texture.
|
|||||||
|
|
||||||
///Low level demo, doesn't include btBulletCollisionCommon.h
|
///Low level demo, doesn't include btBulletCollisionCommon.h
|
||||||
|
|
||||||
#include "GL_Simplex1to4.h"
|
|
||||||
#include "LinearMath/btQuaternion.h"
|
#include "LinearMath/btQuaternion.h"
|
||||||
#include "LinearMath/btTransform.h"
|
#include "LinearMath/btTransform.h"
|
||||||
#include "GL_ShapeDrawer.h"
|
#include "GL_ShapeDrawer.h"
|
||||||
@@ -74,10 +33,6 @@ Very basic raytracer, rendering into a texture.
|
|||||||
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
|
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
|
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
|
||||||
#ifdef USE_ALGEBRAIC_CCD
|
|
||||||
#include "NarrowPhaseCollision/BU_CollisionPair.h"
|
|
||||||
#endif //USE_ALGEBRAIC_CCD
|
|
||||||
|
|
||||||
|
|
||||||
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
||||||
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
|
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
|
||||||
@@ -105,8 +60,6 @@ static float yaw=0.f,pitch=0.f,roll=0.f;
|
|||||||
static const int maxNumObjects = 4;
|
static const int maxNumObjects = 4;
|
||||||
static const int numObjects = 1;
|
static const int numObjects = 1;
|
||||||
|
|
||||||
/// simplex contains the vertices, and some extra code to draw and debug
|
|
||||||
static GL_Simplex1to4 simplex;
|
|
||||||
|
|
||||||
static btConvexShape* shapePtr[maxNumObjects];
|
static btConvexShape* shapePtr[maxNumObjects];
|
||||||
static btTransform transforms[maxNumObjects];
|
static btTransform transforms[maxNumObjects];
|
||||||
@@ -119,14 +72,7 @@ static int screenWidth = 128;
|
|||||||
static int screenHeight = 128;//screenWidth * aspectRatio;
|
static int screenHeight = 128;//screenWidth * aspectRatio;
|
||||||
GLuint glTextureId;
|
GLuint glTextureId;
|
||||||
|
|
||||||
btSphereShape mySphere(1);
|
|
||||||
btBoxShape myBox(btVector3(0.4f,0.4f,0.4f));
|
|
||||||
btCylinderShape myCylinder(btVector3(0.3f,0.3f,0.3f));
|
|
||||||
btConeShape myCone(1,1);
|
btConeShape myCone(1,1);
|
||||||
btCompoundShape compound;
|
|
||||||
|
|
||||||
|
|
||||||
btMinkowskiSumShape myMink(&myCylinder,&myBox);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -139,15 +85,8 @@ void Raytracer::initPhysics()
|
|||||||
{
|
{
|
||||||
raytracePicture = new renderTexture(screenWidth,screenHeight);
|
raytracePicture = new renderTexture(screenWidth,screenHeight);
|
||||||
|
|
||||||
myBox.setMargin(0.02f);
|
|
||||||
myCone.setMargin(0.2f);
|
myCone.setMargin(0.2f);
|
||||||
|
|
||||||
simplex.setSimplexSolver(&simplexSolver);
|
|
||||||
simplex.addVertex(btPoint3(-1,0,-1));
|
|
||||||
simplex.addVertex(btPoint3(1,0,-1));
|
|
||||||
simplex.addVertex(btPoint3(0,0,1));
|
|
||||||
simplex.addVertex(btPoint3(0,1,0));
|
|
||||||
|
|
||||||
|
|
||||||
/// convex hull of 5 spheres
|
/// convex hull of 5 spheres
|
||||||
#define NUM_SPHERES 5
|
#define NUM_SPHERES 5
|
||||||
@@ -160,57 +99,24 @@ void Raytracer::initPhysics()
|
|||||||
btVector3(0.f, 0.f, 0.f)
|
btVector3(0.f, 0.f, 0.f)
|
||||||
};
|
};
|
||||||
|
|
||||||
//btMultiSphereShape* multiSphereShape = new btMultiSphereShape(inertiaHalfExtents,positions,radi,NUM_SPHERES);
|
|
||||||
|
|
||||||
btVector3 sphereOffset1(0,0,0);
|
btVector3 sphereOffset1(0,0,0);
|
||||||
btScalar sphereRadius = 2.f;
|
btScalar sphereRadius = 2.f;
|
||||||
btVector3 nonUniformScaling(0.5,2,0.5);
|
btVector3 nonUniformScaling(0.5,2,0.5);
|
||||||
btMultiSphereShape* nonuniformScaledSphere = new btMultiSphereShape(inertiaHalfExtents,&sphereOffset1,&sphereRadius,1);
|
|
||||||
nonuniformScaledSphere->setLocalScaling(nonUniformScaling);
|
|
||||||
nonuniformScaledSphere->setMargin(0.04);
|
|
||||||
btConvexHullShape* convexHullShape = new btConvexHullShape(&positions[0].getX(),3);
|
|
||||||
|
|
||||||
//attempt to approximate a bowling pin
|
|
||||||
//choose shape
|
//choose shape
|
||||||
shapePtr[0] = &myCone;//&compound;//&myCone;//&myBox;//nonuniformScaledSphere;//&myCone;
|
shapePtr[0] = &myCone;
|
||||||
// shapePtr[0] = &myCone;//&myBox;//nonuniformScaledSphere;//&myCone;
|
|
||||||
|
|
||||||
shapePtr[1] =&simplex;
|
|
||||||
shapePtr[2] =convexHullShape;
|
|
||||||
shapePtr[3] =&myMink;//myBox;//multiSphereShape
|
|
||||||
|
|
||||||
btVector3 sphereOffset(0,PIN_HEIGHT/4.0f,0);
|
|
||||||
|
|
||||||
// create pin collision shape
|
|
||||||
btCollisionShape* cyl = new btCylinderShape(btVector3(PIN_DIAMETER/4.0f, PIN_HEIGHT/4.0f, PIN_DIAMETER/4.0f));
|
|
||||||
cyl->setMargin(IN_TO_M(0.000025f));
|
|
||||||
btVector3 spherepositions[3] = {btVector3(0,-PIN_HEIGHT/2.f +(PIN_DIAMETER/2.0f)+IN_TO_M(1.25f),0),
|
|
||||||
btVector3(0,-PIN_HEIGHT/2.f +(PIN_DIAMETER/2.0f)+IN_TO_M(1.25f),0)+sphereOffset,
|
|
||||||
btVector3(0,-PIN_HEIGHT/2.f +(PIN_DIAMETER/2.0f)+IN_TO_M(1.25f),0)-sphereOffset};
|
|
||||||
btScalar radii[3] = {(PIN_DIAMETER/2.0f),(PIN_DIAMETER/4.0f),(PIN_DIAMETER/4.0f)};
|
|
||||||
btCollisionShape* sph = new btMultiSphereShape(inertiaHalfExtents,spherepositions,radii,3);
|
|
||||||
|
|
||||||
btTransform ident;
|
|
||||||
ident.setIdentity();
|
|
||||||
ident.setOrigin(btVector3(0.f,-PIN_HEIGHT/4.f,0.f));
|
|
||||||
compound.addChildShape(ident,cyl);
|
|
||||||
ident.setIdentity();
|
|
||||||
//ident.setOrigin(btVector3(0.0f, -PIN_HEIGHT/2.0f + PIN_DIAMETER/2.0f + IN_TO_M(3.5f), 0.0f));
|
|
||||||
compound.addChildShape(ident,sph);
|
|
||||||
|
|
||||||
btVector3 spherepositions2[2] = {btVector3(0,+PIN_HEIGHT/2.f -(PIN_DIAMETER/4.0f),0),
|
|
||||||
btVector3(0,0,0)};
|
|
||||||
btScalar radii2[2] = {(PIN_DIAMETER/4.0f),(PIN_DIAMETER/6.0f)};
|
|
||||||
|
|
||||||
btCollisionShape* sph2 = new btMultiSphereShape(inertiaHalfExtents,spherepositions2,radii2,2);
|
|
||||||
compound.addChildShape(ident,sph2);
|
|
||||||
|
|
||||||
compound.setMargin(0.001);
|
|
||||||
simplex.setMargin(0.3f);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Raytracer::~Raytracer()
|
||||||
|
{
|
||||||
|
|
||||||
|
delete raytracePicture;
|
||||||
|
raytracePicture=0;
|
||||||
|
}
|
||||||
|
|
||||||
//to be implemented by the demo
|
//to be implemented by the demo
|
||||||
|
|
||||||
void Raytracer::clientMoveAndDisplay()
|
void Raytracer::clientMoveAndDisplay()
|
||||||
@@ -242,7 +148,6 @@ void Raytracer::displayCallback()
|
|||||||
//transforms[i].setRotation(orn);
|
//transforms[i].setRotation(orn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
myMink.setTransformA(btTransform(transforms[0].getRotation()));
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
@@ -512,23 +417,6 @@ void Raytracer::displayCallback()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
/// normal opengl rendering
|
|
||||||
float m[16];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0;i<numObjects;i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
transA.getOpenGLMatrix( m );
|
|
||||||
/// draw the simplex
|
|
||||||
GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(1,1,1));
|
|
||||||
/// calculate closest point from simplex to the origin, and draw this vector
|
|
||||||
simplex.calcClosest(m);
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class Raytracer : public DemoApplication
|
|||||||
|
|
||||||
void initPhysics();
|
void initPhysics();
|
||||||
|
|
||||||
|
virtual ~Raytracer();
|
||||||
|
|
||||||
virtual void clientMoveAndDisplay();
|
virtual void clientMoveAndDisplay();
|
||||||
|
|
||||||
virtual void displayCallback();
|
virtual void displayCallback();
|
||||||
|
|||||||
Reference in New Issue
Block a user