Update to bullet 2.67 beta1 (which fixed the problem of karts falling through the

track with optimised triangle meshes).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1497 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-02-15 03:53:41 +00:00
parent 35af794f33
commit 35514f15f8
54 changed files with 2839 additions and 312 deletions

View File

@ -37,9 +37,10 @@ struct btDebugCastResult : public btConvexCast::CastResult
const btPolyhedralConvexShape* m_shape;
btVector3 m_linVel;
btVector3 m_angVel;
GL_ShapeDrawer* m_shapeDrawer;
btDebugCastResult(const btTransform& fromTrans,const btPolyhedralConvexShape* shape,
const btVector3& linVel,const btVector3& angVel)
const btVector3& linVel,const btVector3& angVel,GL_ShapeDrawer* drawer)
:m_fromTrans(fromTrans),
m_shape(shape),
m_linVel(linVel),
@ -74,8 +75,7 @@ struct btDebugCastResult : public btConvexCast::CastResult
btTransform hitTrans;
btTransformUtil::integrateTransform(m_fromTrans,m_linVel,m_angVel,fraction,hitTrans);
hitTrans.getOpenGLMatrix(m);
GL_ShapeDrawer::drawOpenGL(m,m_shape,btVector3(1,0,0),btIDebugDraw::DBG_NoDebug);
m_shapeDrawer->drawOpenGL(m,m_shape,btVector3(1,0,0),btIDebugDraw::DBG_NoDebug);
}
};

View File

@ -72,15 +72,19 @@ m_shootBoxShape(0),
m_singleStep(false),
m_idle(false)
{
#ifndef BT_NO_PROFILE
m_profileIterator = CProfileManager::Get_Iterator();
#endif //BT_NO_PROFILE
}
DemoApplication::~DemoApplication()
{
#ifndef BT_NO_PROFILE
CProfileManager::Release_Iterator(m_profileIterator);
#endif //BT_NO_PROFILE
if (m_shootBoxShape)
delete m_shootBoxShape;
@ -177,10 +181,11 @@ void DemoApplication::updateCamera() {
m_cameraPosition[2] = eyePos.getZ();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0);
gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2],
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2],
m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2],
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
glMatrixMode(GL_MODELVIEW);
}
@ -242,6 +247,7 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
m_lastKey = 0;
#ifndef BT_NO_PROFILE
if (key >= 0x31 && key < 0x37)
{
int child = key-0x31;
@ -251,7 +257,7 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
{
m_profileIterator->Enter_Parent();
}
#endif //BT_NO_PROFILE
switch (key)
{
@ -736,12 +742,16 @@ btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform
#define USE_MOTIONSTATE 1
#ifdef USE_MOTIONSTATE
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody* body = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,shape,localInertia));
btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);
btRigidBody* body = new btRigidBody(cInfo);
#else
btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
body->setWorldTransform(startTransform);
#endif//
m_dynamicsWorld->addRigidBody(body);
return body;
@ -753,6 +763,7 @@ void DemoApplication::setOrthographicProjection()
// switch to projection mode
glMatrixMode(GL_PROJECTION);
// save previous matrix which contains the
//settings for the perspective projection
glPushMatrix();
@ -760,19 +771,24 @@ void DemoApplication::setOrthographicProjection()
glLoadIdentity();
// set a 2D orthographic projection
gluOrtho2D(0, m_glutScreenWidth, 0, m_glutScreenHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// invert the y axis, down is positive
glScalef(1, -1, 1);
// mover the origin from the bottom left corner
// to the upper left corner
glTranslatef(0, -m_glutScreenHeight, 0);
glMatrixMode(GL_MODELVIEW);
}
void DemoApplication::resetPerspectiveProjection()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
updateCamera();
}
@ -789,6 +805,7 @@ void DemoApplication::displayProfileString(int xOffset,int yStart,char* message)
void DemoApplication::showProfileInfo(float& xOffset,float& yStart, float yIncr)
{
#ifndef BT_NO_PROFILE
static double time_since_reset = 0.f;
if (!m_idle)
@ -851,6 +868,7 @@ void DemoApplication::showProfileInfo(float& xOffset,float& yStart, float yIncr)
yStart += yIncr;
}
#endif//BT_NO_PROFILE
@ -909,7 +927,7 @@ void DemoApplication::renderme()
}
}
GL_ShapeDrawer::drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
}
@ -1079,6 +1097,8 @@ void DemoApplication::renderme()
}
updateCamera();
}
void DemoApplication::clientResetScene()

View File

@ -18,6 +18,7 @@ subject to the following restrictions:
#include "GlutStuff.h"
#include "GL_ShapeDrawer.h"
#include <stdlib.h>
#include <stdio.h>
@ -37,15 +38,15 @@ class btTypedConstraint;
class DemoApplication
{
void displayProfileString(int xOffset,int yStart,char* message);
class CProfileIterator* m_profileIterator;
protected:
#ifdef USE_BT_CLOCK
btClock m_clock;
#endif //USE_BT_CLOCK
///this is the most important class
btDynamicsWorld* m_dynamicsWorld;
@ -80,6 +81,7 @@ class DemoApplication
void showProfileInfo(float& xOffset,float& yStart, float yIncr);
GL_ShapeDrawer m_shapeDrawer;
public:
@ -127,6 +129,16 @@ public:
return m_cameraTargetPosition;
}
btScalar getDeltaTimeMicroseconds()
{
#ifdef USE_BT_CLOCK
btScalar dt = m_clock.getTimeMicroseconds();
m_clock.reset();
return dt;
#else
return btScalar(16666.);
#endif
}
///glut callbacks

View File

@ -39,7 +39,11 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btUniformScalingShape.h"
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
///
#include "BulletCollision/CollisionShapes/btShapeHull.h"
#include "LinearMath/btTransformUtil.h"
#include "LinearMath/btIDebugDraw.h"
@ -302,12 +306,19 @@ void GL_ShapeDrawer::drawCylinder(float radius,float halfHeight, int upAxis)
gluQuadricDrawStyle(quadObj, (GLenum)GLU_FILL);
gluQuadricNormals(quadObj, (GLenum)GLU_SMOOTH);
gluDisk(quadObj,0,radius,15, 10);
gluCylinder(quadObj, radius, radius, 2.f*halfHeight, 15, 10);
glTranslatef(0.0, 0.0, 2.*halfHeight);
glRotatef(-180.0, 0.0, 1.0, 0.0);
gluDisk(quadObj,0,radius,15, 10);
glPopMatrix();
gluDeleteQuadric(quadObj);
}
void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode)
{
@ -358,6 +369,8 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
if (!(debugMode & btIDebugDraw::DBG_DrawWireframe))
{
///you can comment out any of the specific cases, and use the default
///the benefit of 'default' is that it approximates the actual collision shape including collision margin
switch (shape->getShapeType())
{
case BOX_SHAPE_PROXYTYPE:
@ -369,15 +382,8 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
useWireframeFallback = false;
break;
}
case TRIANGLE_SHAPE_PROXYTYPE:
case TETRAHEDRAL_SHAPE_PROXYTYPE:
{
//todo:
// useWireframeFallback = false;
break;
}
case CONVEX_HULL_SHAPE_PROXYTYPE:
break;
case SPHERE_SHAPE_PROXYTYPE:
{
const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
@ -386,29 +392,7 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
useWireframeFallback = false;
break;
}
case CAPSULE_SHAPE_PROXYTYPE:
{
const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);
float radius = capsuleShape->getRadius();
float halfHeight = capsuleShape->getHalfHeight();
int upAxis = 1;
drawCylinder(radius,halfHeight,upAxis);
glPushMatrix();
glTranslatef(0.0, -halfHeight,0.0);
glutSolidSphere(radius,10,10);
glTranslatef(0.0, 2*halfHeight,0.0);
glutSolidSphere(radius,10,10);
glPopMatrix();
useWireframeFallback = false;
break;
}
case MULTI_SPHERE_SHAPE_PROXYTYPE:
{
break;
}
case CONE_SHAPE_PROXYTYPE:
{
const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
@ -436,13 +420,33 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
break;
}
case CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE:
case STATIC_PLANE_PROXYTYPE:
{
useWireframeFallback = false;
const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
btScalar planeConst = staticPlaneShape->getPlaneConstant();
const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
btVector3 planeOrigin = planeNormal * planeConst;
btVector3 vec0,vec1;
btPlaneSpace1(planeNormal,vec0,vec1);
btScalar vecLen = 100.f;
btVector3 pt0 = planeOrigin + vec0*vecLen;
btVector3 pt1 = planeOrigin - vec0*vecLen;
btVector3 pt2 = planeOrigin + vec1*vecLen;
btVector3 pt3 = planeOrigin - vec1*vecLen;
glBegin(GL_LINES);
glVertex3f(pt0.getX(),pt0.getY(),pt0.getZ());
glVertex3f(pt1.getX(),pt1.getY(),pt1.getZ());
glVertex3f(pt2.getX(),pt2.getY(),pt2.getZ());
glVertex3f(pt3.getX(),pt3.getY(),pt3.getZ());
glEnd();
break;
}
case CONVEX_SHAPE_PROXYTYPE:
case CYLINDER_SHAPE_PROXYTYPE:
{
const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
@ -456,75 +460,134 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
break;
}
default:
{
}
if (shape->isConvex())
{
btConvexShape* convexShape = (btConvexShape*)shape;
if (!shape->getUserPointer())
{
//create a hull approximation
void* mem = btAlignedAlloc(sizeof(btShapeHull),16);
btShapeHull* hull = new(mem) btShapeHull(convexShape);
///cleanup memory
m_shapeHulls.push_back(hull);
};
btScalar margin = shape->getMargin();
hull->buildHull(margin);
convexShape->setUserPointer(hull);
// printf("numTriangles = %d\n", hull->numTriangles ());
// printf("numIndices = %d\n", hull->numIndices ());
// printf("numVertices = %d\n", hull->numVertices ());
}
if (shape->getUserPointer())
{
//glutSolidCube(1.0);
btShapeHull* hull = (btShapeHull*)shape->getUserPointer();
if (hull->numTriangles () > 0)
{
int index = 0;
const unsigned int* idx = hull->getIndexPointer();
const btVector3* vtx = hull->getVertexPointer();
glBegin (GL_TRIANGLES);
for (int i = 0; i < hull->numTriangles (); i++)
{
int i1 = index++;
int i2 = index++;
int i3 = index++;
btAssert(i1 < hull->numIndices () &&
i2 < hull->numIndices () &&
i3 < hull->numIndices ());
int index1 = idx[i1];
int index2 = idx[i2];
int index3 = idx[i3];
btAssert(index1 < hull->numVertices () &&
index2 < hull->numVertices () &&
index3 < hull->numVertices ());
btVector3 v1 = vtx[index1];
btVector3 v2 = vtx[index2];
btVector3 v3 = vtx[index3];
btVector3 normal = (v3-v1).cross(v2-v1);
normal.normalize ();
glNormal3f(normal.getX(),normal.getY(),normal.getZ());
glVertex3f (v1.x(), v1.y(), v1.z());
glVertex3f (v2.x(), v2.y(), v2.z());
glVertex3f (v3.x(), v3.y(), v3.z());
}
glEnd ();
}
} else
{
// printf("unhandled drawing\n");
}
}
}
}
}
if (useWireframeFallback)
/// for polyhedral shapes
if (debugMode==btIDebugDraw::DBG_DrawFeaturesText && (shape->isPolyhedral()))
{
/// for polyhedral shapes
if (shape->isPolyhedral())
btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
{
btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
glBegin(GL_LINES);
glRasterPos3f(0.0, 0.0, 0.0);
//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape->getExtraDebugInfo());
glColor3f(1.f, 1.f, 1.f);
int i;
for (i=0;i<polyshape->getNumEdges();i++)
for (i=0;i<polyshape->getNumVertices();i++)
{
btPoint3 a,b;
polyshape->getEdge(i,a,b);
glVertex3f(a.getX(),a.getY(),a.getZ());
glVertex3f(b.getX(),b.getY(),b.getZ());
}
glEnd();
if (debugMode==btIDebugDraw::DBG_DrawFeaturesText)
{
glRasterPos3f(0.0, 0.0, 0.0);
//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape->getExtraDebugInfo());
glColor3f(1.f, 1.f, 1.f);
for (i=0;i<polyshape->getNumVertices();i++)
{
btPoint3 vtx;
polyshape->getVertex(i,vtx);
glRasterPos3f(vtx.x(), vtx.y(), vtx.z());
char buf[12];
sprintf(buf," %d",i);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
for (i=0;i<polyshape->getNumPlanes();i++)
{
btVector3 normal;
btPoint3 vtx;
polyshape->getPlane(normal,vtx,i);
btScalar d = vtx.dot(normal);
glRasterPos3f(normal.x()*d, normal.y()*d, normal.z()*d);
char buf[12];
sprintf(buf," plane %d",i);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
btPoint3 vtx;
polyshape->getVertex(i,vtx);
glRasterPos3f(vtx.x(), vtx.y(), vtx.z());
char buf[12];
sprintf(buf," %d",i);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
for (i=0;i<polyshape->getNumPlanes();i++)
{
btVector3 normal;
btPoint3 vtx;
polyshape->getPlane(normal,vtx,i);
btScalar d = vtx.dot(normal);
glRasterPos3f(normal.x()*d, normal.y()*d, normal.z()*d);
char buf[12];
sprintf(buf," plane %d",i);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
}
}
@ -564,6 +627,7 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
}
#endif
/*
if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
{
btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;
@ -575,6 +639,8 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
}
*/
glDisable(GL_DEPTH_BUFFER_BIT);
@ -595,3 +661,22 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons
glPopMatrix();
}
GL_ShapeDrawer::GL_ShapeDrawer()
{
}
GL_ShapeDrawer::~GL_ShapeDrawer()
{
int i;
for (i=0;i<m_shapeHulls.size();i++)
{
btShapeHull* hull = m_shapeHulls[i];
hull->~btShapeHull();
btAlignedFree(hull);
m_shapeHulls[i] = 0;
}
m_shapeHulls.clear();
}

View File

@ -16,16 +16,26 @@ subject to the following restrictions:
#define GL_SHAPE_DRAWER_H
class btCollisionShape;
class btShapeHull;
#include "LinearMath/btAlignedObjectArray.h"
#include "LinearMath/btVector3.h"
/// OpenGL shape drawing
class GL_ShapeDrawer
{
public:
//clean-up memory of dynamically created shape hulls
btAlignedObjectArray<btShapeHull*> m_shapeHulls;
static void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode);
static void drawCoordSystem();
public:
GL_ShapeDrawer();
virtual ~GL_ShapeDrawer();
///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode);
static void drawCylinder(float radius,float halfHeight, int upAxis);
static void drawCoordSystem();
};
void OGL_displaylist_register_shape(btCollisionShape * shape);

View File

@ -1,3 +1,3 @@
Bullet Collision Detection and Physics Library version 2.66
Bullet Collision Detection and Physics Library version 2.67
http://bullet.sourceforge.net

View File

@ -43,7 +43,7 @@ struct btDispatcherInfo
m_useContinuous(false),
m_debugDraw(0),
m_enableSatConvex(false),
m_enableSPU(false),
m_enableSPU(true),
m_stackAllocator(0)
{

View File

@ -26,6 +26,7 @@ btCollisionObject::btCollisionObject()
m_deactivationTime(btScalar(0.)),
m_friction(btScalar(0.5)),
m_restitution(btScalar(0.)),
m_typedUserInfo (NULL),
m_userObjectPointer(0),
m_internalOwner(0),
m_hitFraction(btScalar(1.)),

View File

@ -27,6 +27,7 @@ subject to the following restrictions:
struct btBroadphaseProxy;
class btCollisionShape;
class btTypedUserInfo;
#include "LinearMath/btMotionState.h"
#include "LinearMath/btAlignedAllocator.h"
@ -69,6 +70,8 @@ protected:
///m_internalOwner is reserved to point to Bullet's btRigidBody. Don't use this, use m_userObjectPointer instead.
void* m_internalOwner;
btTypedUserInfo* m_typedUserInfo;
///time of impact calculation
btScalar m_hitFraction;
@ -334,6 +337,16 @@ public:
m_userObjectPointer = userPointer;
}
btTypedUserInfo* getTypedUserInfo () const
{
return m_typedUserInfo;
}
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
{
m_typedUserInfo = typedUserInfo;
}
inline bool checkCollideWith(btCollisionObject* co)
{
if (m_checkCollideWith)
@ -341,9 +354,6 @@ public:
return true;
}
}
;
};
#endif //COLLISION_OBJECT_H

View File

@ -227,7 +227,7 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
btVoronoiSimplexSolver simplexSolver;
#define USE_SUBSIMPLEX_CONVEX_CAST 1
#ifdef USE_SUBSIMPLEX_CONVEX_CAST
btSubsimplexConvexCast convexCaster(castShape,convexShape,&simplexSolver);
btSubsimplexConvexCast convexCaster(castShape,convexShape,&simplexSolver);
#else
//btGjkConvexCast convexCaster(castShape,convexShape,&simplexSolver);
//btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
@ -412,11 +412,6 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
{
if (castResult.m_fraction < resultCallback.m_closestHitFraction)
{
#ifdef USE_SUBSIMPLEX_CONVEX_CAST
//rotate normal into worldspace
castResult.m_normal = convexFromTrans.getBasis() * castResult.m_normal;
#endif //USE_SUBSIMPLEX_CONVEX_CAST
castResult.m_normal.normalize();
btCollisionWorld::LocalConvexResult localConvexResult
(
@ -477,7 +472,7 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
hitPointLocal,
hitFraction);
bool normalInWorldSpace = false;
bool normalInWorldSpace = true;
return m_resultCallback->AddSingleResult(convexResult,normalInWorldSpace);
@ -620,17 +615,21 @@ void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& r
}
void btCollisionWorld::convexTest(const btConvexShape* castShape, const btVector3& convexFromWorld, const btVector3& convexToWorld, ConvexResultCallback& resultCallback,short int collisionFilterMask)
void btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, ConvexResultCallback& resultCallback,short int collisionFilterMask)
{
btTransform convexFromTrans,convexToTrans;
convexFromTrans.setIdentity();
convexFromTrans.setOrigin(convexFromWorld);
convexToTrans.setIdentity();
convexToTrans.setOrigin(convexToWorld);
convexFromTrans = convexFromWorld;
convexToTrans = convexToWorld;
btVector3 castShapeAabbMin, castShapeAabbMax;
btTransform I;
I.setIdentity();
castShape->getAabb (I, castShapeAabbMin, castShapeAabbMax);
/* Compute AABB that encompasses angular movement */
{
btVector3 linVel, angVel;
btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0, linVel, angVel);
btTransform R;
R.setIdentity ();
R.setRotation (convexFromTrans.getRotation());
castShape->calculateTemporalAabb (R, linVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
}
/// go over all objects, and if the ray intersects their aabb + cast shape aabb,
// do a ray-shape query using convexCaster (CCD)
@ -646,7 +645,7 @@ void btCollisionWorld::convexTest(const btConvexShape* castShape, const btVector
AabbExpand (collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
btVector3 hitNormal;
if (btRayAabb(convexFromWorld,convexToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
if (btRayAabb(convexFromWorld.getOrigin(),convexToWorld.getOrigin(),collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
{
objectQuerySingle(castShape, convexFromTrans,convexToTrans,
collisionObject,

View File

@ -307,9 +307,10 @@ public:
/// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback, short int collisionFilterMask=-1);
// convexTest performs a linear convex cast on all objects in the btCollisionWorld, and calls the resultCallback
// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback
// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
void convexTest (const btConvexShape* castShape, const btVector3& from, const btVector3& to, ConvexResultCallback& resultCallback, short int collisionFilterMask=-1);
void convexSweepTest (const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback, short int collisionFilterMask=-1);
/// rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest.
/// In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape.

View File

@ -109,9 +109,12 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i
{
btTriangleShape tm(triangle[0],triangle[1],triangle[2]);
tm.setMargin(m_collisionMarginTriangle);
btCollisionShape* tmpShape = ob->getCollisionShape();
//copy over user pointers to temporary shape
tm.setTypedUserInfo(tmpShape->getTypedUserInfo());
tm.setUserPointer(tmpShape->getUserPointer());
ob->setCollisionShape( &tm );

View File

@ -71,9 +71,9 @@ void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0
btTransform convexInPlaneTrans;
convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexObj->getWorldTransform();
btVector3 vtx = convexShape->localGetSupportingVertexWithoutMargin(planeInConvex.getBasis()*-planeNormal);
btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
btVector3 vtxInPlane = convexInPlaneTrans(vtx);
btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant) - convexShape->getMargin();
btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
btVector3 vtxInPlaneWorld = planeObj->getWorldTransform() * vtxInPlaneProjected;

View File

@ -87,6 +87,11 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
//BP mod, store contact triangles.
newPt.m_partId0 = m_partId0;
newPt.m_partId1 = m_partId1;
newPt.m_index0 = m_index0;
newPt.m_index1 = m_index1;
///todo, check this for any side effects
if (insertIndex >= 0)

View File

@ -91,14 +91,14 @@ btBvhTriangleMeshShape::~btBvhTriangleMeshShape()
}
}
void btBvhTriangleMeshShape::performRaycast (btTriangleRaycastCallback* callback, const btVector3& raySource, const btVector3& rayTarget)
void btBvhTriangleMeshShape::performRaycast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget)
{
struct MyNodeOverlapCallback : public btNodeOverlapCallback
{
btStridingMeshInterface* m_meshInterface;
btTriangleRaycastCallback* m_callback;
btTriangleCallback* m_callback;
MyNodeOverlapCallback(btTriangleRaycastCallback* callback,btStridingMeshInterface* meshInterface)
MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
:m_meshInterface(meshInterface),
m_callback(callback)
{
@ -151,14 +151,14 @@ void btBvhTriangleMeshShape::performRaycast (btTriangleRaycastCallback* callback
m_bvh->reportRayOverlappingNodex(&myNodeCallback,raySource,rayTarget);
}
void btBvhTriangleMeshShape::performConvexcast (btTriangleConvexcastCallback* callback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax)
void btBvhTriangleMeshShape::performConvexcast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax)
{
struct MyNodeOverlapCallback : public btNodeOverlapCallback
{
btStridingMeshInterface* m_meshInterface;
btTriangleConvexcastCallback* m_callback;
btTriangleCallback* m_callback;
MyNodeOverlapCallback(btTriangleConvexcastCallback* callback,btStridingMeshInterface* meshInterface)
MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
:m_meshInterface(meshInterface),
m_callback(callback)
{

View File

@ -19,7 +19,7 @@ subject to the following restrictions:
#include "btTriangleMeshShape.h"
#include "btOptimizedBvh.h"
#include "LinearMath/btAlignedAllocator.h"
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
@ -48,8 +48,8 @@ public:
return TRIANGLE_MESH_SHAPE_PROXYTYPE;
}
void performRaycast (btTriangleRaycastCallback* callback, const btVector3& raySource, const btVector3& rayTarget);
void performConvexcast (btTriangleConvexcastCallback* callback, const btVector3& boxSource, const btVector3& boxTarget, const btVector3& boxMin, const btVector3& boxMax);
void performRaycast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget);
void performConvexcast (btTriangleCallback* callback, const btVector3& boxSource, const btVector3& boxTarget, const btVector3& boxMin, const btVector3& boxMax);
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;

View File

@ -21,6 +21,7 @@ subject to the following restrictions:
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
{
m_upAxis = 1;
m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
}
@ -50,7 +51,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
{
btVector3 pos(0,getHalfHeight(),0);
btVector3 pos(0,0,0);
pos[getUpAxis()] = getHalfHeight();
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@ -60,7 +63,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
}
}
{
btVector3 pos(0,-getHalfHeight(),0);
btVector3 pos(0,0,0);
pos[getUpAxis()] = -getHalfHeight();
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@ -88,7 +93,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
btVector3 vtx;
btScalar newDot;
{
btVector3 pos(0,getHalfHeight(),0);
btVector3 pos(0,0,0);
pos[getUpAxis()] = getHalfHeight();
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@ -98,7 +104,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
}
}
{
btVector3 pos(0,-getHalfHeight(),0);
btVector3 pos(0,0,0);
pos[getUpAxis()] = -getHalfHeight();
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@ -122,7 +129,8 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con
btScalar radius = getRadius();
btVector3 halfExtents(radius,radius+getHalfHeight(),radius);
btVector3 halfExtents(radius,radius,radius);
halfExtents[getUpAxis()]+=getHalfHeight();
btScalar margin = CONVEX_DISTANCE_MARGIN;
@ -140,6 +148,22 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) con
}
btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height)
{
m_upAxis = 0;
m_implicitShapeDimensions.setValue(0.5f*height, radius,radius);
}
btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height)
{
m_upAxis = 2;
m_implicitShapeDimensions.setValue(radius,radius,0.5f*height);
}

View File

@ -1,60 +1,119 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BT_CAPSULE_SHAPE_H
#define BT_CAPSULE_SHAPE_H
#include "btConvexInternalShape.h"
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
///btCapsuleShape represents a capsule around the Y axis
///A more general solution that can represent capsules is the btMultiSphereShape
class btCapsuleShape : public btConvexInternalShape
{
public:
btCapsuleShape(btScalar radius,btScalar height);
///CollisionShape Interface
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
/// btConvexShape Interface
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
virtual int getShapeType() const { return CAPSULE_SHAPE_PROXYTYPE; }
virtual const char* getName()const
{
return "CapsuleShape";
}
btScalar getRadius() const
{
return m_implicitShapeDimensions.getX();
}
btScalar getHalfHeight() const
{
return m_implicitShapeDimensions.getY();
}
};
#endif //BT_CAPSULE_SHAPE_H
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BT_CAPSULE_SHAPE_H
#define BT_CAPSULE_SHAPE_H
#include "btConvexInternalShape.h"
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
///btCapsuleShape represents a capsule around the Y axis
///A more general solution that can represent capsules is the btMultiSphereShape
///the total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
class btCapsuleShape : public btConvexInternalShape
{
protected:
int m_upAxis;
protected:
///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
btCapsuleShape() {};
public:
btCapsuleShape(btScalar radius,btScalar height);
///CollisionShape Interface
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
/// btConvexShape Interface
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
virtual int getShapeType() const { return CAPSULE_SHAPE_PROXYTYPE; }
virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
{
btVector3 halfExtents(getRadius(),getRadius(),getRadius());
halfExtents[m_upAxis] = getRadius()*btScalar(2.0) + btScalar(0.5)*getHalfHeight();
btMatrix3x3 abs_b = t.getBasis().absolute();
btPoint3 center = t.getOrigin();
btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));
extent += btVector3(getMargin(),getMargin(),getMargin());
aabbMin = center - extent;
aabbMax = center + extent;
}
virtual const char* getName()const
{
return "CapsuleShape";
}
int getUpAxis() const
{
return m_upAxis;
}
btScalar getRadius() const
{
int radiusAxis = (m_upAxis+2)%3;
return m_implicitShapeDimensions[radiusAxis];
}
btScalar getHalfHeight() const
{
return m_implicitShapeDimensions[m_upAxis];
}
};
///btCapsuleShapeX represents a capsule around the Z axis
///the total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
class btCapsuleShapeX : public btCapsuleShape
{
public:
btCapsuleShapeX(btScalar radius,btScalar height);
//debugging
virtual const char* getName()const
{
return "CapsuleX";
}
};
///btCapsuleShapeZ represents a capsule around the Z axis
///the total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
class btCapsuleShapeZ : public btCapsuleShape
{
public:
btCapsuleShapeZ(btScalar radius,btScalar height);
//debugging
virtual const char* getName()const
{
return "CapsuleZ";
}
};
#endif //BT_CAPSULE_SHAPE_H

View File

@ -46,7 +46,7 @@ btScalar btCollisionShape::getAngularMotionDisc() const
return disc;
}
void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax)
void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const
{
//start with static aabb
getAabb(curTrans,temporalAabbMin,temporalAabbMax);

View File

@ -16,6 +16,7 @@ subject to the following restrictions:
#ifndef COLLISION_SHAPE_H
#define COLLISION_SHAPE_H
class btTypedUserInfo;
#include "LinearMath/btTransform.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btMatrix3x3.h"
@ -25,9 +26,13 @@ subject to the following restrictions:
///btCollisionShape provides interface for collision shapes that can be shared among btCollisionObjects.
class btCollisionShape
{
void* m_userPointer;
btTypedUserInfo* m_typedUserInfo;
public:
btCollisionShape()
btCollisionShape() : m_userPointer(0), m_typedUserInfo (0)
{
}
virtual ~btCollisionShape()
@ -45,7 +50,7 @@ public:
///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
///result is conservative
void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax);
void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const;
#ifndef __SPU__
@ -88,6 +93,27 @@ public:
virtual void setMargin(btScalar margin) = 0;
virtual btScalar getMargin() const = 0;
///optional user data pointer
void setUserPointer(void* userPtr)
{
m_userPointer = userPtr;
}
void* getUserPointer() const
{
return m_userPointer;
}
btTypedUserInfo* getTypedUserInfo () const
{
return m_typedUserInfo;
}
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
{
m_typedUserInfo = typedUserInfo;
}
};
#endif //COLLISION_SHAPE_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,138 @@
/*
Stan Melax Convex Hull Computation
Copyright (c) 2008 Stan Melax http://www.melax.com/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
///includes modifications/improvements by John Ratcliff, see BringOutYourDead below.
#ifndef CD_HULL_H
#define CD_HULL_H
#include "LinearMath/btVector3.h"
class HullResult
{
public:
HullResult(void)
{
mPolygons = true;
mNumOutputVertices = 0;
mOutputVertices = 0;
mNumFaces = 0;
mNumIndices = 0;
mIndices = 0;
}
bool mPolygons; // true if indices represents polygons, false indices are triangles
unsigned int mNumOutputVertices; // number of vertices in the output hull
btVector3 *mOutputVertices; // array of vertices
unsigned int mNumFaces; // the number of faces produced
unsigned int mNumIndices; // the total number of indices
unsigned int *mIndices; // pointer to indices.
// If triangles, then indices are array indexes into the vertex list.
// If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc..
};
enum HullFlag
{
QF_TRIANGLES = (1<<0), // report results as triangles, not polygons.
QF_REVERSE_ORDER = (1<<1), // reverse order of the triangle indices.
QF_DEFAULT = QF_TRIANGLES
};
class HullDesc
{
public:
HullDesc(void)
{
mFlags = QF_DEFAULT;
mVcount = 0;
mVertices = 0;
mVertexStride = sizeof(btVector3);
mNormalEpsilon = 0.001f;
mMaxVertices = 4096; // maximum number of points to be considered for a convex hull.
mMaxFaces = 4096;
};
HullDesc(HullFlag flag,
unsigned int vcount,
const btVector3 *vertices,
unsigned int stride = sizeof(btVector3))
{
mFlags = flag;
mVcount = vcount;
mVertices = vertices;
mVertexStride = stride;
mNormalEpsilon = btScalar(0.001);
mMaxVertices = 4096;
}
bool HasHullFlag(HullFlag flag) const
{
if ( mFlags & flag ) return true;
return false;
}
void SetHullFlag(HullFlag flag)
{
mFlags|=flag;
}
void ClearHullFlag(HullFlag flag)
{
mFlags&=~flag;
}
unsigned int mFlags; // flags to use when generating the convex hull.
unsigned int mVcount; // number of vertices in the input point cloud
const btVector3 *mVertices; // the array of vertices.
unsigned int mVertexStride; // the stride of each vertex, in bytes.
btScalar mNormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on.
unsigned int mMaxVertices; // maximum number of vertices to be considered for the hull!
unsigned int mMaxFaces;
};
enum HullError
{
QE_OK, // success!
QE_FAIL // failed.
};
class HullLibrary
{
public:
HullError CreateConvexHull(const HullDesc& desc, // describes the input request
HullResult& result); // contains the resulst
HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
private:
//BringOutYourDead (John Ratcliff): When you create a convex hull you hand it a large input set of vertices forming a 'point cloud'.
//After the hull is generated it give you back a set of polygon faces which index the *original* point cloud.
//The thing is, often times, there are many 'dead vertices' in the point cloud that are on longer referenced by the hull.
//The routine 'BringOutYourDead' find only the referenced vertices, copies them to an new buffer, and re-indexes the hull so that it is a minimal representation.
void BringOutYourDead(const btVector3* verts,unsigned int vcount, btVector3* overts,unsigned int &ocount,unsigned int* indices,unsigned indexcount);
bool CleanupVertices(unsigned int svcount,
const btVector3* svertices,
unsigned int stride,
unsigned int &vcount, // output number of vertices
btVector3* vertices, // location to store the results.
btScalar normalepsilon,
btVector3& scale);
};
#endif

View File

@ -17,10 +17,7 @@ class btConvexInternalShape : public btConvexShape
btScalar m_collisionMargin;
btScalar m_padding[2];
btScalar m_padding;
public:
@ -93,6 +90,8 @@ public:
btAssert(0);
}
};

View File

@ -182,20 +182,16 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
}
void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point) const
void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point,int isMax) const
{
btVector3 clampedPoint(point);
clampedPoint.setMax(m_localAabbMin);
clampedPoint.setMin(m_localAabbMax);
btVector3 v = (clampedPoint );// * m_quantization;
// SMJ - Add 0.5 in the correct direction before doing the int conversion.
out[0] = (int)(v.getX() + v.getX() / btFabs(v.getX())* btScalar(0.5) );
out[1] = (int)(v.getY() + v.getY() / btFabs(v.getY())* btScalar(0.5) );
out[2] = (int)(v.getZ() + v.getZ() / btFabs(v.getZ())* btScalar(0.5) );
btVector3 v = (clampedPoint);// - m_bvhAabbMin) * m_bvhQuantization;
out[0] = (unsigned short)(((unsigned short)v.getX() & 0xffffffe) | isMax);
out[1] = (unsigned short)(((unsigned short)v.getY() & 0xffffffe) | isMax);
out[2] = (unsigned short)(((unsigned short)v.getZ() & 0xffffffe) | isMax);
}
@ -214,8 +210,8 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
btVector3 localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
btVector3 localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
quantizeWithClamp(quantizedAabbMin, localAabbMin);
quantizeWithClamp(quantizedAabbMax, localAabbMax);
quantizeWithClamp(quantizedAabbMin, localAabbMin,0);
quantizeWithClamp(quantizedAabbMax, localAabbMax,1);

View File

@ -47,7 +47,7 @@ protected:
btVector3 m_localScaling;
virtual btScalar getHeightFieldValue(int x,int y) const;
void quantizeWithClamp(int* out, const btVector3& point) const;
void quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
void getVertex(int x,int y,btVector3& vertex) const;
inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const int* aabbMin2,const int* aabbMax2) const

View File

@ -132,8 +132,8 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized
aabbMin.setZ(aabbMin.z() - MIN_AABB_HALF_DIMENSION);
}
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMin[0],aabbMin);
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMax[0],aabbMax);
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMin[0],aabbMin,0);
m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMax[0],aabbMax,1);
node.m_escapeIndexOrTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
@ -221,8 +221,8 @@ void btOptimizedBvh::refitPartial(btStridingMeshInterface* meshInterface,const b
unsigned short quantizedQueryAabbMin[3];
unsigned short quantizedQueryAabbMax[3];
quantizeWithClamp(&quantizedQueryAabbMin[0],aabbMin);
quantizeWithClamp(&quantizedQueryAabbMax[0],aabbMax);
quantizeWithClamp(&quantizedQueryAabbMin[0],aabbMin,0);
quantizeWithClamp(&quantizedQueryAabbMax[0],aabbMax,1);
int i;
for (i=0;i<this->m_SubtreeHeaders.size();i++)
@ -328,8 +328,8 @@ void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int f
aabbMin.setMin(triangleVerts[2]);
aabbMax.setMax(triangleVerts[2]);
quantizeWithClamp(&curNode.m_quantizedAabbMin[0],aabbMin);
quantizeWithClamp(&curNode.m_quantizedAabbMax[0],aabbMax);
quantizeWithClamp(&curNode.m_quantizedAabbMin[0],aabbMin,0);
quantizeWithClamp(&curNode.m_quantizedAabbMax[0],aabbMax,1);
} else
{
@ -613,8 +613,8 @@ void btOptimizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallb
///quantize query AABB
unsigned short int quantizedQueryAabbMin[3];
unsigned short int quantizedQueryAabbMax[3];
quantizeWithClamp(quantizedQueryAabbMin,aabbMin);
quantizeWithClamp(quantizedQueryAabbMax,aabbMax);
quantizeWithClamp(quantizedQueryAabbMin,aabbMin,0);
quantizeWithClamp(quantizedQueryAabbMax,aabbMax,1);
switch (m_traversalMode)
{
@ -764,6 +764,7 @@ void btOptimizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
btVector3 rayDirection = (rayTarget-raySource);
rayDirection.normalize ();
lambda_max = rayDirection.dot(rayTarget-raySource);
///what about division by zero?
rayDirection[0] = btScalar(1.0) / rayDirection[0];
rayDirection[1] = btScalar(1.0) / rayDirection[1];
rayDirection[2] = btScalar(1.0) / rayDirection[2];
@ -782,8 +783,8 @@ void btOptimizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
unsigned short int quantizedQueryAabbMin[3];
unsigned short int quantizedQueryAabbMax[3];
quantizeWithClamp(quantizedQueryAabbMin,rayAabbMin);
quantizeWithClamp(quantizedQueryAabbMax,rayAabbMax);
quantizeWithClamp(quantizedQueryAabbMin,rayAabbMin,0);
quantizeWithClamp(quantizedQueryAabbMax,rayAabbMax,1);
while (curIndex < endNodeIndex)
{
@ -832,9 +833,13 @@ void btOptimizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
}
#endif
#ifdef RAYAABB2
rayBoxOverlap = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
///careful with this check: need to check division by zero (above) and fix the unQuantize method
///thanks Joerg/hiker for the reproduction case!
///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
rayBoxOverlap = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max);
#else
rayBoxOverlap = btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal);
rayBoxOverlap = true;//btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal);
#endif
}
@ -985,20 +990,6 @@ void btOptimizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCa
}
btVector3 btOptimizedBvh::unQuantize(const unsigned short* vecIn) const
{
btVector3 vecOut;
vecOut.setValue(
(btScalar)(vecIn[0]) / (m_bvhQuantization.getX()),
(btScalar)(vecIn[1]) / (m_bvhQuantization.getY()),
(btScalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
vecOut += m_bvhAabbMin;
return vecOut;
}
void btOptimizedBvh::swapLeafNodes(int i,int splitIndex)
{
if (m_useQuantization)

View File

@ -191,7 +191,7 @@ protected:
{
if (m_useQuantization)
{
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[0] ,aabbMin);
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[0] ,aabbMin,0);
} else
{
m_contiguousNodes[nodeIndex].m_aabbMinOrg = aabbMin;
@ -202,7 +202,7 @@ protected:
{
if (m_useQuantization)
{
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[0],aabbMax);
quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[0],aabbMax,1);
} else
{
m_contiguousNodes[nodeIndex].m_aabbMaxOrg = aabbMax;
@ -251,8 +251,8 @@ protected:
{
unsigned short int quantizedAabbMin[3];
unsigned short int quantizedAabbMax[3];
quantizeWithClamp(quantizedAabbMin,newAabbMin);
quantizeWithClamp(quantizedAabbMax,newAabbMax);
quantizeWithClamp(quantizedAabbMin,newAabbMin,0);
quantizeWithClamp(quantizedAabbMax,newAabbMax,1);
for (int i=0;i<3;i++)
{
if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] > quantizedAabbMin[i])
@ -333,7 +333,7 @@ public:
void reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const;
void reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const;
SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point) const
SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point,int isMax) const
{
btAssert(m_useQuantization);
@ -341,15 +341,22 @@ public:
btVector3 clampedPoint(point);
clampedPoint.setMax(m_bvhAabbMin);
clampedPoint.setMin(m_bvhAabbMax);
btVector3 v = (clampedPoint - m_bvhAabbMin) * m_bvhQuantization;
out[0] = (unsigned short)(v.getX()+0.5f);
out[1] = (unsigned short)(v.getY()+0.5f);
out[2] = (unsigned short)(v.getZ()+0.5f);
out[0] = (unsigned short)(((unsigned short)v.getX() & 0xfffe) | isMax);
out[1] = (unsigned short)(((unsigned short)v.getY() & 0xfffe) | isMax);
out[2] = (unsigned short)(((unsigned short)v.getZ() & 0xfffe) | isMax);
}
btVector3 unQuantize(const unsigned short* vecIn) const;
SIMD_FORCE_INLINE btVector3 unQuantize(const unsigned short* vecIn) const
{
btVector3 vecOut;
vecOut.setValue(
(btScalar)(vecIn[0]) / (m_bvhQuantization.getX()),
(btScalar)(vecIn[1]) / (m_bvhQuantization.getY()),
(btScalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
vecOut += m_bvhAabbMin;
return vecOut;
}
///setTraversalMode let's you choose between stackless, recursive or stackless cache friendly tree traversal. Note this is only implemented for quantized trees.
void setTraversalMode(btTraversalMode traversalMode)

View File

@ -0,0 +1,161 @@
/*
btbtShapeHull implemented by John McCutchan.
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2008 Erwin Coumans http://bulletphysics.com
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "btShapeHull.h"
#include "btConvexHull.h"
#define NUM_UNITSPHERE_POINTS 42
static btVector3 btUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
{
btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
};
btShapeHull::btShapeHull (const btConvexShape* shape)
{
m_shape = shape;
m_vertices.clear ();
m_indices = NULL;
m_numIndices = 0;
}
btShapeHull::~btShapeHull ()
{
if (m_indices)
delete [] m_indices;
m_vertices.clear ();
}
bool
btShapeHull::buildHull (btScalar margin)
{
int numSampleDirections = NUM_UNITSPHERE_POINTS;
{
int numPDA = m_shape->getNumPreferredPenetrationDirections();
if (numPDA)
{
for (int i=0;i<numPDA;i++)
{
btVector3 norm;
m_shape->getPreferredPenetrationDirection(i,norm);
btUnitSpherePoints[numSampleDirections] = norm;
numSampleDirections++;
}
}
}
btVector3 supportPoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
int i;
for (i = 0; i < numSampleDirections; i++)
{
supportPoints[i] = m_shape->localGetSupportingVertex(btUnitSpherePoints[i]);
}
HullDesc hd;
hd.mFlags = QF_TRIANGLES;
hd.mVcount = numSampleDirections;
#ifdef BT_USE_DOUBLE_PRECISION
hd.mVertices = &supportPoints[0];
hd.mVertexStride = sizeof(btVector3);
#else
hd.mVertices = &supportPoints[0];
hd.mVertexStride = sizeof (btVector3);
#endif
HullLibrary hl;
HullResult hr;
if (hl.CreateConvexHull (hd, hr) == QE_FAIL)
{
return false;
}
m_vertices.resize (hr.mNumOutputVertices);
for (i = 0; i < hr.mNumOutputVertices; i++)
{
m_vertices[i] = hr.mOutputVertices[i];
}
m_numIndices = hr.mNumIndices;
m_indices = new unsigned int [m_numIndices];
for (i = 0; i < m_numIndices; i++)
{
m_indices[i] = hr.mIndices[i];
}
return true;
}
int
btShapeHull::numTriangles () const
{
return m_numIndices / 3;
}
int
btShapeHull::numVertices () const
{
return m_vertices.size ();
}
int
btShapeHull::numIndices () const
{
return m_numIndices;
}

View File

@ -0,0 +1,54 @@
/*
btShapeHull implemented by John McCutchan.
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _SHAPE_HULL_H
#define _SHAPE_HULL_H
#include "LinearMath/btAlignedObjectArray.h"
#include "BulletCollision/CollisionShapes/btConvexShape.h"
///btShapeHull takes a btConvexShape, builds the convex hull using btConvexHull and provides triangle indices and vertices.
class btShapeHull
{
public:
btShapeHull (const btConvexShape* shape);
~btShapeHull ();
bool buildHull (btScalar margin);
int numTriangles () const;
int numVertices () const;
int numIndices () const;
const btVector3* getVertexPointer() const
{
return &m_vertices[0];
}
const unsigned int* getIndexPointer() const
{
return m_indices;
}
protected:
btAlignedObjectArray<btVector3> m_vertices;
unsigned int* m_indices;
unsigned int m_numIndices;
const btConvexShape* m_shape;
};
#endif //_SHAPE_HULL_H

View File

@ -30,6 +30,7 @@ class btManifoldPoint
public:
btManifoldPoint()
:m_userPersistentData(0),
m_appliedImpulse(0.f),
m_lifeTime(0)
{
}
@ -43,7 +44,8 @@ class btManifoldPoint
m_distance1( distance ),
m_combinedFriction(btScalar(0.)),
m_combinedRestitution(btScalar(0.)),
m_userPersistentData(0),
m_userPersistentData(0),
m_appliedImpulse(0.f),
m_lifeTime(0)
{
@ -63,8 +65,14 @@ class btManifoldPoint
btScalar m_combinedFriction;
btScalar m_combinedRestitution;
//BP mod, store contact triangles.
int m_partId0;
int m_partId1;
int m_index0;
int m_index1;
mutable void* m_userPersistentData;
btScalar m_appliedImpulse;
int m_lifeTime;//lifetime of the contactpoint in frames

View File

@ -20,6 +20,7 @@ subject to the following restrictions:
btScalar gContactBreakingThreshold = btScalar(0.02);
ContactDestroyedCallback gContactDestroyedCallback = 0;
ContactProcessedCallback gContactProcessedCallback = 0;
@ -234,6 +235,11 @@ void btPersistentManifold::refreshContactPoints(const btTransform& trA,const btT
if (distance2d > getContactBreakingThreshold()*getContactBreakingThreshold() )
{
removeContactPoint(i);
} else
{
//contact point processed callback
if (gContactProcessedCallback)
(*gContactProcessedCallback)(manifoldPoint,m_body0,m_body1);
}
}
}

View File

@ -28,6 +28,7 @@ struct btCollisionResult;
extern btScalar gContactBreakingThreshold;
typedef bool (*ContactDestroyedCallback)(void* userPersistentData);
typedef bool (*ContactProcessedCallback)(btManifoldPoint& cp,void* body0,void* body1);
extern ContactDestroyedCallback gContactDestroyedCallback;
@ -123,6 +124,7 @@ public:
m_pointCache[index] = m_pointCache[lastUsedIndex];
//get rid of duplicated userPersistentData pointer
m_pointCache[lastUsedIndex].m_userPersistentData = 0;
m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f;
m_pointCache[lastUsedIndex].m_lifeTime = 0;
}
@ -136,12 +138,14 @@ public:
#define MAINTAIN_PERSISTENCY 1
#ifdef MAINTAIN_PERSISTENCY
int lifeTime = m_pointCache[insertIndex].getLifeTime();
btScalar appliedImpulse = 0.f;//m_pointCache[insertIndex].m_appliedImpulse;
btAssert(lifeTime>=0);
void* cache = m_pointCache[insertIndex].m_userPersistentData;
m_pointCache[insertIndex] = newPoint;
m_pointCache[insertIndex].m_userPersistentData = cache;
m_pointCache[insertIndex].m_appliedImpulse = appliedImpulse;
m_pointCache[insertIndex].m_lifeTime = lifeTime;
#else
clearUserCache(m_pointCache[insertIndex]);

View File

@ -17,7 +17,6 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btConvexShape.h"
#include "BulletCollision/CollisionShapes/btTriangleShape.h"
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
@ -124,6 +123,7 @@ btTriangleConvexcastCallback::processTriangle (btVector3* triangle, int partId,
//#define USE_SUBSIMPLEX_CONVEX_CAST 1
//if you reenable USE_SUBSIMPLEX_CONVEX_CAST see commented out code below
#ifdef USE_SUBSIMPLEX_CONVEX_CAST
btSubsimplexConvexCast convexCaster(m_convexShape, &triangleShape, &simplexSolver);
#else
@ -140,11 +140,13 @@ btTriangleConvexcastCallback::processTriangle (btVector3* triangle, int partId,
{
if (castResult.m_fraction < m_hitFraction)
{
/* btContinuousConvexCast's normal is already in world space */
/*
#ifdef USE_SUBSIMPLEX_CONVEX_CAST
//rotate normal into worldspace
castResult.m_normal = m_convexShapeFrom.getBasis() * castResult.m_normal;
#endif //USE_SUBSIMPLEX_CONVEX_CAST
*/
castResult.m_normal.normalize();
reportHit (castResult.m_normal,

View File

@ -106,7 +106,7 @@ bool MyContactDestroyedCallback(void* userPersistentData)
btSequentialImpulseConstraintSolver::btSequentialImpulseConstraintSolver()
:m_solverMode(SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY), //not using SOLVER_USE_WARMSTARTING,
:m_solverMode(SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING ),
m_btSeed2(0)
{
gContactDestroyedCallback = &MyContactDestroyedCallback;
@ -386,6 +386,7 @@ void btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3&
solverConstraint.m_frictionIndex = frictionIndex;
solverConstraint.m_friction = cp.m_combinedFriction;
solverConstraint.m_originalContactPoint = 0;
solverConstraint.m_appliedImpulse = btScalar(0.);
solverConstraint.m_appliedVelocityImpulse = 0.f;
@ -435,6 +436,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
(void)stackAlloc;
(void)debugDrawer;
if (!(numConstraints + numManifolds))
{
// printf("empty\n");
@ -608,6 +610,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
solverConstraint.m_solverBodyIdB = solverBodyIdB;
solverConstraint.m_constraintType = btSolverConstraint::BT_SOLVER_CONTACT_1D;
solverConstraint.m_originalContactPoint = &cp;
btVector3 torqueAxis0 = rel_pos1.cross(cp.m_normalWorldOnB);
solverConstraint.m_angularComponentA = rb0 ? rb0->getInvInertiaTensorWorld()*torqueAxis0 : btVector3(0,0,0);
btVector3 torqueAxis1 = rel_pos2.cross(cp.m_normalWorldOnB);
@ -667,7 +671,14 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
solverConstraint.m_appliedImpulse = 0.f;
///warm starting (or zero if disabled)
if (m_solverMode & SOLVER_USE_WARMSTARTING)
{
solverConstraint.m_appliedImpulse = cp.m_appliedImpulse;
} else
{
solverConstraint.m_appliedImpulse = 0.f;
}
solverConstraint.m_appliedVelocityImpulse = 0.f;
@ -774,7 +785,6 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(
for (j=0;j<numConstraints;j++)
{
BT_PROFILE("solveConstraint");
btTypedConstraint* constraint = constraints[j];
///todo: use solver bodies, so we don't need to copy from/to btRigidBody
@ -801,7 +811,6 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(
}
{
BT_PROFILE("resolveSingleCollisionCombinedCacheFriendly");
int numPoolConstraints = m_tmpSolverConstraintPool.size();
for (j=0;j<numPoolConstraints;j++)
{
@ -813,7 +822,6 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(
}
{
BT_PROFILE("resolveSingleFrictionCacheFriendly");
int numFrictionPoolConstraints = m_tmpSolverFrictionConstraintPool.size();
for (j=0;j<numFrictionPoolConstraints;j++)
@ -832,6 +840,20 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(
}
}
{
int numPoolConstraints = m_tmpSolverConstraintPool.size();
int j;
for (j=0;j<numPoolConstraints;j++)
{
const btSolverConstraint& solveManifold = m_tmpSolverConstraintPool[j];
btManifoldPoint* pt = (btManifoldPoint*) solveManifold.m_originalContactPoint;
btAssert(pt);
pt->m_appliedImpulse = solveManifold.m_appliedImpulse;
//do a callback here?
}
}
return 0.f;
}

View File

@ -50,7 +50,9 @@ ATTRIBUTE_ALIGNED16 (struct) btSolverConstraint
int m_constraintType;
int m_frictionIndex;
int m_unusedPadding[2];
void* m_originalContactPoint;
int m_unusedPadding[1];
enum btSolverConstraintType
{

View File

@ -23,6 +23,7 @@ btTypedConstraint::btTypedConstraint(btTypedConstraintType type)
:m_userConstraintType(-1),
m_userConstraintId(-1),
m_constraintType (type),
m_typedUserInfo(0),
m_rbA(s_fixed),
m_rbB(s_fixed),
m_appliedImpulse(btScalar(0.))
@ -32,6 +33,7 @@ m_appliedImpulse(btScalar(0.))
btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA)
:m_userConstraintType(-1),
m_userConstraintId(-1),
m_typedUserInfo(0),
m_constraintType (type),
m_rbA(rbA),
m_rbB(s_fixed),
@ -45,6 +47,7 @@ m_appliedImpulse(btScalar(0.))
btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA,btRigidBody& rbB)
:m_userConstraintType(-1),
m_userConstraintId(-1),
m_typedUserInfo(0),
m_constraintType (type),
m_rbA(rbA),
m_rbB(rbB),

View File

@ -17,6 +17,7 @@ subject to the following restrictions:
#define TYPED_CONSTRAINT_H
class btRigidBody;
class btTypedUserInfo;
#include "LinearMath/btScalar.h"
enum btTypedConstraintType
@ -33,6 +34,7 @@ class btTypedConstraint
{
int m_userConstraintType;
int m_userConstraintId;
btTypedUserInfo* m_typedUserInfo;
btTypedConstraintType m_constraintType;
@ -107,6 +109,16 @@ public:
{
return m_constraintType;
}
btTypedUserInfo* getTypedUserInfo () const
{
return m_typedUserInfo;
}
void setTypedUserInfo (btTypedUserInfo* typedUserInfo)
{
m_typedUserInfo = typedUserInfo;
}
};
#endif //TYPED_CONSTRAINT_H

View File

@ -42,6 +42,7 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btSphereShape.h"
#include "BulletCollision/CollisionShapes/btTriangleCallback.h"
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
#include "LinearMath/btIDebugDraw.h"
@ -329,7 +330,9 @@ int btDiscreteDynamicsWorld::stepSimulation( btScalar timeStep,int maxSubSteps,
clearForces();
#ifndef BT_NO_PROFILE
CProfileManager::Increment_Frame_Counter();
#endif //BT_NO_PROFILE
return numSimulationSubSteps;
}
@ -388,6 +391,11 @@ void btDiscreteDynamicsWorld::setGravity(const btVector3& gravity)
}
}
btVector3 btDiscreteDynamicsWorld::getGravity () const
{
return m_gravity;
}
void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body)
{
@ -593,7 +601,11 @@ void btDiscreteDynamicsWorld::solveConstraints(btContactSolverInfo& solverInfo)
}
}
m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,startConstraint,numCurConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher);
///only call solveGroup if there is some work: avoid virtual function call, its overhead can be excessive
if (numManifolds + numCurConstraints)
{
m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,startConstraint,numCurConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher);
}
}
}
@ -717,40 +729,10 @@ void btDiscreteDynamicsWorld::startProfiling(btScalar timeStep)
{
(void)timeStep;
#ifndef BT_NO_PROFILE
CProfileManager::Reset();
#endif //BT_NO_PROFILE
#ifdef USE_QUICKPROF
//toggle btProfiler
if ( m_debugDrawer && m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_ProfileTimings)
{
if (!m_profileTimings)
{
m_profileTimings = 1;
// To disable profiling, simply comment out the following line.
static int counter = 0;
char filename[128];
sprintf(filename,"quickprof_bullet_timings%i.csv",counter++);
btProfiler::init(filename, btProfiler::BLOCK_CYCLE_SECONDS);//BLOCK_TOTAL_MICROSECONDS
} else
{
btProfiler::endProfilingCycle();
}
} else
{
if (m_profileTimings)
{
btProfiler::endProfilingCycle();
m_profileTimings = 0;
btProfiler::destroy();
}
}
#endif //USE_QUICKPROF
}
@ -937,6 +919,25 @@ void btDiscreteDynamicsWorld::debugDrawObject(const btTransform& worldTransform,
getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
break;
}
case STATIC_PLANE_PROXYTYPE:
{
const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
btScalar planeConst = staticPlaneShape->getPlaneConstant();
const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
btVector3 planeOrigin = planeNormal * planeConst;
btVector3 vec0,vec1;
btPlaneSpace1(planeNormal,vec0,vec1);
btScalar vecLen = 100.f;
btVector3 pt0 = planeOrigin + vec0*vecLen;
btVector3 pt1 = planeOrigin - vec0*vecLen;
btVector3 pt2 = planeOrigin + vec1*vecLen;
btVector3 pt3 = planeOrigin - vec1*vecLen;
getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color);
getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color);
break;
}
default:
{

View File

@ -118,6 +118,7 @@ public:
virtual void setGravity(const btVector3& gravity);
virtual btVector3 getGravity () const;
virtual void addRigidBody(btRigidBody* body);

View File

@ -61,6 +61,7 @@ class btDynamicsWorld : public btCollisionWorld
//once a rigidbody is added to the dynamics world, it will get this gravity assigned
//existing rigidbodies in the world get gravity assigned too, during this method
virtual void setGravity(const btVector3& gravity) = 0;
virtual btVector3 getGravity () const = 0;
virtual void addRigidBody(btRigidBody* body) = 0;

View File

@ -54,7 +54,7 @@ void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo&
m_contactSolverType = 0;
m_frictionSolverType = 0;
m_additionalDamping = constructionInfo.m_additionalDamping;
m_additionalDampingFactor = constructionInfo.m_additionalDampingFactor;
m_additionalLinearDampingThresholdSqr = constructionInfo.m_additionalLinearDampingThresholdSqr;
m_additionalAngularDampingThresholdSqr = constructionInfo.m_additionalAngularDampingThresholdSqr;
m_additionalAngularDampingFactor = constructionInfo.m_additionalAngularDampingFactor;

View File

@ -449,7 +449,6 @@ public:
return m_constraintRefs.size();
}
int m_debugBodyId;
};

View File

@ -121,6 +121,11 @@ void btSimpleDynamicsWorld::setGravity(const btVector3& gravity)
}
}
btVector3 btSimpleDynamicsWorld::getGravity () const
{
return m_gravity;
}
void btSimpleDynamicsWorld::removeRigidBody(btRigidBody* body)
{
removeCollisionObject(body);

View File

@ -52,6 +52,8 @@ public:
virtual void setGravity(const btVector3& gravity);
virtual btVector3 getGravity () const;
virtual void addRigidBody(btRigidBody* body);
virtual void removeRigidBody(btRigidBody* body);

View File

@ -15,6 +15,8 @@
#include "LinearMath/btQuickprof.h"
#ifdef USE_BT_CLOCK
static btClock gProfileClock;
inline void Profile_Get_Ticks(unsigned long int * ticks)
@ -29,6 +31,8 @@ inline float Profile_Get_Tick_Rate(void)
}
/***************************************************************************************************
**
** CProfileNode
@ -264,5 +268,5 @@ float CProfileManager::Get_Time_Since_Reset( void )
return (float)time / Profile_Get_Tick_Rate();
}
#endif //USE_BT_CLOCK

View File

@ -23,7 +23,7 @@ subject to the following restrictions:
#include <cfloat>
#include <float.h>
#define BT_BULLET_VERSION 266
#define BT_BULLET_VERSION 267
inline int btGetVersion()
{

View File

@ -70,7 +70,9 @@ public:
predictedOrn += (angvel * predictedOrn) * (timeStep * btScalar(0.5));
predictedOrn.normalize();
#else
//exponential map
//Exponential map
//google for "Practical Parameterization of Rotations Using the Exponential Map", F. Sebastian Grassia
btVector3 axis;
btScalar fAngle = angvel.length();
//limit the angular motion

View File

@ -0,0 +1,54 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BT_TYPE_USER_INFO_H
#define BT_TYPE_USER_INFO_H
class btTypedUserInfo
{
protected:
int m_type;
char* m_name;
void* m_userPointer;
/* Only systems internal to Bullet are allowed
* to use this pointer
*/
void* m_privatePointer;
public:
btTypedUserInfo ()
{
m_type = 0;
m_name = 0;
m_userPointer = 0;
m_privatePointer = 0;
}
virtual ~btTypedUserInfo () {};
int getType () { return m_type; }
void setType (int type) { m_type = type; }
char* getName () { return m_name; }
void setName (char* name) { m_name = name; }
void* getUserPointer () { return m_userPointer; }
void setUserPointer (void* userPointer) { m_userPointer = userPointer; }
void* getPrivatePointer () { return m_privatePointer; }
void setPrivatePointer (void* privatePointer) { m_privatePointer = privatePointer; }
};
#endif //BT_TYPE_USER_INFO_H

View File

@ -12,6 +12,7 @@ libbulletmath_a_SOURCES = \
LinearMath/btTransform.h LinearMath/btGeometryUtil.h \
LinearMath/btQuaternion.h LinearMath/btTransformUtil.h \
LinearMath/btIDebugDraw.h LinearMath/btQuickprof.cpp \
LinearMath/btTypedUserInfo.h LinearMath/btTypedUserInfo.h \
LinearMath/btVector3.h
libbulletcollision_a_SOURCES := \
@ -80,6 +81,8 @@ libbulletcollision_a_SOURCES := \
BulletCollision/CollisionShapes/btConcaveShape.h \
BulletCollision/CollisionShapes/btConeShape.cpp \
BulletCollision/CollisionShapes/btConeShape.h \
BulletCollision/CollisionShapes/btConvexHull.cpp \
BulletCollision/CollisionShapes/btConvexHull.h \
BulletCollision/CollisionShapes/btConvexHullShape.cpp \
BulletCollision/CollisionShapes/btConvexHullShape.h \
BulletCollision/CollisionShapes/btConvexInternalShape.cpp \
@ -102,6 +105,8 @@ libbulletcollision_a_SOURCES := \
BulletCollision/CollisionShapes/btOptimizedBvh.h \
BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp \
BulletCollision/CollisionShapes/btPolyhedralConvexShape.h \
BulletCollision/CollisionShapes/btShapeHull.cpp \
BulletCollision/CollisionShapes/btShapeHull.h \
BulletCollision/CollisionShapes/btSphereShape.cpp \
BulletCollision/CollisionShapes/btSphereShape.h \
BulletCollision/CollisionShapes/btStaticPlaneShape.cpp \

View File

@ -298,6 +298,10 @@
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btConeShape.cpp"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btConvexHull.cpp"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btConvexHullShape.cpp"
>
@ -342,6 +346,10 @@
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btPolyhedralConvexShape.cpp"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btShapeHull.cpp"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btSphereShape.cpp"
>
@ -665,6 +673,10 @@
RelativePath="..\..\bullet\src\LinearMath\btTransformUtil.h"
>
</File>
<File
RelativePath="..\..\bullet\src\LinearMath\btTypedUserInfo.h"
>
</File>
<File
RelativePath="..\..\bullet\src\LinearMath\btVector3.h"
>
@ -824,6 +836,10 @@
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btConeShape.h"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btConvexHull.h"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btConvexHullShape.h"
>
@ -868,6 +884,10 @@
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btPolyhedralConvexShape.h"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btShapeHull.h"
>
</File>
<File
RelativePath="..\..\bullet\src\BulletCollision\CollisionShapes\btSphereShape.h"
>

View File

@ -17,9 +17,6 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "bullet/Demos/OpenGL/GL_ShapeDrawer.h"
#include "physics.hpp"
#include "ssg_help.hpp"
#include "world.hpp"
@ -285,7 +282,7 @@ void Physics::draw()
void Physics::debugDraw(float m[16], btCollisionShape *s, const btVector3 color)
{
GL_ShapeDrawer::drawOpenGL(m, s, color, 0);
m_shape_drawer.drawOpenGL(m, s, color, 0);
// btIDebugDraw::DBG_DrawWireframe);
// btIDebugDraw::DBG_DrawAabb);

View File

@ -27,12 +27,15 @@
#include "btBulletDynamicsCommon.h"
#include "bullet/Demos/OpenGL/GLDebugDrawer.h"
#include "bullet/Demos/OpenGL/GL_ShapeDrawer.h"
class Physics : public btSequentialImpulseConstraintSolver
{
private:
btDynamicsWorld *m_dynamics_world;
Kart *m_kart;
GLDebugDrawer *m_debug_drawer;
GL_ShapeDrawer m_shape_drawer;
btCollisionDispatcher *m_dispatcher;
btBroadphaseInterface *m_axis_sweep;
btDefaultCollisionConfiguration *m_collision_conf;

View File

@ -176,6 +176,9 @@ void DefaultRobot::handle_braking()
#ifdef AI_DEBUG
std::cout << "BRAKING" << std::endl;
#endif
printf("vel %f %f ang %f %f\n",
getVelocityLC().getY(), m_curve_target_speed,
kart_ang_diff,MIN_TRACK_ANGLE );
m_controls.brake = true;
return;
}

View File

@ -51,7 +51,7 @@ void TriangleMesh::createBody(btCollisionObject::CollisionFlags flags)
return;
}
// Now convert the triangle mesh into a static rigid body
m_collision_shape = new btBvhTriangleMeshShape(&m_mesh, false);
m_collision_shape = new btBvhTriangleMeshShape(&m_mesh, true);
btTransform startTransform;
startTransform.setIdentity();
m_motion_state = new btDefaultMotionState(startTransform);