Some changes in rendering, to get shadows for trimeshes
Add dynamic aabb tree (btDbvt) optimization for btCompoundShape/btCompoundCollisionAlgorithm Add btTransformAabb util, todo: deploy it throughout the codebase
This commit is contained in:
@@ -45,7 +45,7 @@ subject to the following restrictions:
|
|||||||
#include "GlutStuff.h"
|
#include "GlutStuff.h"
|
||||||
|
|
||||||
|
|
||||||
btVector3 centroid;
|
btVector3 centroid=btVector3(0,0,0);
|
||||||
btVector3 convexDecompositionObjectOffset(10,0,0);
|
btVector3 convexDecompositionObjectOffset(10,0,0);
|
||||||
|
|
||||||
#define CUBE_HALF_EXTENTS 4
|
#define CUBE_HALF_EXTENTS 4
|
||||||
@@ -100,6 +100,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
|||||||
#endif//USE_PARALLEL_DISPATCHER
|
#endif//USE_PARALLEL_DISPATCHER
|
||||||
|
|
||||||
|
|
||||||
|
convexDecompositionObjectOffset.setValue(10,0,0);
|
||||||
|
|
||||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||||
btVector3 worldAabbMax(10000,10000,10000);
|
btVector3 worldAabbMax(10000,10000,10000);
|
||||||
@@ -124,10 +125,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
|||||||
|
|
||||||
class MyConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface
|
class MyConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
ConvexDecompositionDemo* m_convexDemo;
|
ConvexDecompositionDemo* m_convexDemo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
btAlignedObjectArray<btConvexHullShape*> m_convexShapes;
|
||||||
|
btAlignedObjectArray<btVector3> m_convexCentroids;
|
||||||
|
|
||||||
MyConvexDecomposition (FILE* outputFile,ConvexDecompositionDemo* demo)
|
MyConvexDecomposition (FILE* outputFile,ConvexDecompositionDemo* demo)
|
||||||
:m_convexDemo(demo),
|
:m_convexDemo(demo),
|
||||||
mBaseCount(0),
|
mBaseCount(0),
|
||||||
@@ -162,6 +166,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
|||||||
|
|
||||||
//calc centroid, to shift vertices around center of mass
|
//calc centroid, to shift vertices around center of mass
|
||||||
centroid.setValue(0,0,0);
|
centroid.setValue(0,0,0);
|
||||||
|
|
||||||
btAlignedObjectArray<btVector3> vertices;
|
btAlignedObjectArray<btVector3> vertices;
|
||||||
if ( 1 )
|
if ( 1 )
|
||||||
{
|
{
|
||||||
@@ -245,29 +250,17 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
|||||||
btGeometryUtil::getVerticesFromPlaneEquations(shiftedPlaneEquations,shiftedVertices);
|
btGeometryUtil::getVerticesFromPlaneEquations(shiftedPlaneEquations,shiftedVertices);
|
||||||
|
|
||||||
|
|
||||||
btCollisionShape* convexShape = new btConvexHullShape(&(shiftedVertices[0].getX()),shiftedVertices.size());
|
btConvexHullShape* convexShape = new btConvexHullShape(&(shiftedVertices[0].getX()),shiftedVertices.size());
|
||||||
|
|
||||||
#else //SHRINK_OBJECT_INWARDS
|
#else //SHRINK_OBJECT_INWARDS
|
||||||
|
|
||||||
#ifdef USE_PARALLEL_DISPATCHER
|
btConvexHullShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||||
//SPU/multi threaded version only supports convex hull with contiguous vertices at the moment
|
|
||||||
btCollisionShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
|
||||||
#else
|
|
||||||
btCollisionShape* convexShape = new btConvexTriangleMeshShape(trimesh);
|
|
||||||
#endif //USE_PARALLEL_DISPATCHER
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
convexShape->setMargin(0.01);
|
convexShape->setMargin(0.01);
|
||||||
|
m_convexShapes.push_back(convexShape);
|
||||||
|
m_convexCentroids.push_back(centroid);
|
||||||
m_convexDemo->m_collisionShapes.push_back(convexShape);
|
m_convexDemo->m_collisionShapes.push_back(convexShape);
|
||||||
|
|
||||||
btTransform trans;
|
|
||||||
trans.setIdentity();
|
|
||||||
trans.setOrigin(centroid-convexDecompositionObjectOffset);
|
|
||||||
|
|
||||||
//btRigidBody* body = m_convexDemo->localCreateRigidBody( mass, trans,convexShape);
|
|
||||||
m_convexDemo->localCreateRigidBody( mass, trans,convexShape);
|
|
||||||
mBaseCount+=result.mHullVcount; // advance the 'base index' counter.
|
mBaseCount+=result.mHullVcount; // advance the 'base index' counter.
|
||||||
|
|
||||||
|
|
||||||
@@ -394,6 +387,34 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
|||||||
|
|
||||||
ConvexBuilder cb(desc.mCallback);
|
ConvexBuilder cb(desc.mCallback);
|
||||||
cb.process(desc);
|
cb.process(desc);
|
||||||
|
//now create some bodies
|
||||||
|
|
||||||
|
{
|
||||||
|
btCompoundShape* compound = new btCompoundShape();
|
||||||
|
m_collisionShapes.push_back (compound);
|
||||||
|
|
||||||
|
btTransform trans;
|
||||||
|
trans.setIdentity();
|
||||||
|
for (int i=0;i<convexDecomposition.m_convexShapes.size();i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
btVector3 centroid = convexDecomposition.m_convexCentroids[i];
|
||||||
|
trans.setOrigin(centroid);
|
||||||
|
btConvexHullShape* convexShape = convexDecomposition.m_convexShapes[i];
|
||||||
|
compound->addChildShape(trans,convexShape);
|
||||||
|
}
|
||||||
|
btScalar mass=10.f;
|
||||||
|
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||||
|
localCreateRigidBody( mass, trans,compound);
|
||||||
|
convexDecompositionObjectOffset.setZ(6);
|
||||||
|
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||||
|
localCreateRigidBody( mass, trans,compound);
|
||||||
|
convexDecompositionObjectOffset.setZ(-6);
|
||||||
|
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||||
|
localCreateRigidBody( mass, trans,compound);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (outputFile)
|
if (outputFile)
|
||||||
fclose(outputFile);
|
fclose(outputFile);
|
||||||
|
|||||||
@@ -51,29 +51,29 @@ extern int gTotalBytesAlignedAllocs;
|
|||||||
|
|
||||||
|
|
||||||
DemoApplication::DemoApplication()
|
DemoApplication::DemoApplication()
|
||||||
//see btIDebugDraw.h for modes
|
//see btIDebugDraw.h for modes
|
||||||
:
|
:
|
||||||
m_dynamicsWorld(0),
|
m_dynamicsWorld(0),
|
||||||
m_pickConstraint(0),
|
m_pickConstraint(0),
|
||||||
m_shootBoxShape(0),
|
m_shootBoxShape(0),
|
||||||
m_cameraDistance(15.0),
|
m_cameraDistance(15.0),
|
||||||
m_debugMode(0),
|
m_debugMode(0),
|
||||||
m_ele(20.f),
|
m_ele(20.f),
|
||||||
m_azi(0.f),
|
m_azi(0.f),
|
||||||
m_cameraPosition(0.f,0.f,0.f),
|
m_cameraPosition(0.f,0.f,0.f),
|
||||||
m_cameraTargetPosition(0.f,0.f,0.f),
|
m_cameraTargetPosition(0.f,0.f,0.f),
|
||||||
m_scaleBottom(0.5f),
|
m_scaleBottom(0.5f),
|
||||||
m_scaleFactor(2.f),
|
m_scaleFactor(2.f),
|
||||||
m_cameraUp(0,1,0),
|
m_cameraUp(0,1,0),
|
||||||
m_forwardAxis(2),
|
m_forwardAxis(2),
|
||||||
m_glutScreenWidth(0),
|
m_glutScreenWidth(0),
|
||||||
m_glutScreenHeight(0),
|
m_glutScreenHeight(0),
|
||||||
m_ShootBoxInitialSpeed(40.f),
|
m_ShootBoxInitialSpeed(40.f),
|
||||||
m_stepping(true),
|
m_stepping(true),
|
||||||
m_singleStep(false),
|
m_singleStep(false),
|
||||||
m_idle(false),
|
m_idle(false),
|
||||||
m_enableshadows(false),
|
m_enableshadows(false),
|
||||||
m_sundirection(btVector3(1,-2,1)*1000)
|
m_sundirection(btVector3(1,-2,1)*1000)
|
||||||
{
|
{
|
||||||
#ifndef BT_NO_PROFILE
|
#ifndef BT_NO_PROFILE
|
||||||
m_profileIterator = CProfileManager::Get_Iterator();
|
m_profileIterator = CProfileManager::Get_Iterator();
|
||||||
@@ -100,36 +100,36 @@ DemoApplication::~DemoApplication()
|
|||||||
void DemoApplication::myinit(void)
|
void DemoApplication::myinit(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
|
GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
|
||||||
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||||
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
|
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||||
/* light_position is NOT default value */
|
/* light_position is NOT default value */
|
||||||
GLfloat light_position0[] = { 1.0, 10.0, 1.0, 0.0 };
|
GLfloat light_position0[] = { 1.0, 10.0, 1.0, 0.0 };
|
||||||
GLfloat light_position1[] = { -1.0, -10.0, -1.0, 0.0 };
|
GLfloat light_position1[] = { -1.0, -10.0, -1.0, 0.0 };
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||||
|
|
||||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
glEnable(GL_LIGHT1);
|
glEnable(GL_LIGHT1);
|
||||||
|
|
||||||
|
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
|
|
||||||
glClearColor(0.7,0.7,0.7,0);
|
glClearColor(0.7,0.7,0.7,0);
|
||||||
|
|
||||||
// glEnable(GL_CULL_FACE);
|
// glEnable(GL_CULL_FACE);
|
||||||
// glCullFace(GL_BACK);
|
// glCullFace(GL_BACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,12 +146,12 @@ float DemoApplication::getCameraDistance()
|
|||||||
|
|
||||||
|
|
||||||
void DemoApplication::toggleIdle() {
|
void DemoApplication::toggleIdle() {
|
||||||
if (m_idle) {
|
if (m_idle) {
|
||||||
m_idle = false;
|
m_idle = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_idle = true;
|
m_idle = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -198,11 +198,11 @@ void DemoApplication::updateCamera() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2],
|
gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2],
|
||||||
m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2],
|
m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2],
|
||||||
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
|
m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -262,23 +262,23 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
|
|||||||
(void)x;
|
(void)x;
|
||||||
(void)y;
|
(void)y;
|
||||||
|
|
||||||
m_lastKey = 0;
|
m_lastKey = 0;
|
||||||
|
|
||||||
#ifndef BT_NO_PROFILE
|
#ifndef BT_NO_PROFILE
|
||||||
if (key >= 0x31 && key < 0x37)
|
if (key >= 0x31 && key < 0x37)
|
||||||
{
|
{
|
||||||
int child = key-0x31;
|
int child = key-0x31;
|
||||||
m_profileIterator->Enter_Child(child);
|
m_profileIterator->Enter_Child(child);
|
||||||
}
|
}
|
||||||
if (key==0x30)
|
if (key==0x30)
|
||||||
{
|
{
|
||||||
m_profileIterator->Enter_Parent();
|
m_profileIterator->Enter_Parent();
|
||||||
}
|
}
|
||||||
#endif //BT_NO_PROFILE
|
#endif //BT_NO_PROFILE
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case 'q' :
|
case 'q' :
|
||||||
#ifdef BT_USE_FREEGLUT
|
#ifdef BT_USE_FREEGLUT
|
||||||
//return from glutMainLoop(), detect memory leaks etc.
|
//return from glutMainLoop(), detect memory leaks etc.
|
||||||
glutLeaveMainLoop();
|
glutLeaveMainLoop();
|
||||||
@@ -287,88 +287,88 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l' : stepLeft(); break;
|
case 'l' : stepLeft(); break;
|
||||||
case 'r' : stepRight(); break;
|
case 'r' : stepRight(); break;
|
||||||
case 'f' : stepFront(); break;
|
case 'f' : stepFront(); break;
|
||||||
case 'b' : stepBack(); break;
|
case 'b' : stepBack(); break;
|
||||||
case 'z' : zoomIn(); break;
|
case 'z' : zoomIn(); break;
|
||||||
case 'x' : zoomOut(); break;
|
case 'x' : zoomOut(); break;
|
||||||
case 'i' : toggleIdle(); break;
|
case 'i' : toggleIdle(); break;
|
||||||
case 'g' : m_enableshadows=!m_enableshadows;break;
|
case 'g' : m_enableshadows=!m_enableshadows;break;
|
||||||
case 'u' : m_shapeDrawer.enableTexture(!m_shapeDrawer.enableTexture(false));break;
|
case 'u' : m_shapeDrawer.enableTexture(!m_shapeDrawer.enableTexture(false));break;
|
||||||
case 'h':
|
case 'h':
|
||||||
if (m_debugMode & btIDebugDraw::DBG_NoHelpText)
|
if (m_debugMode & btIDebugDraw::DBG_NoHelpText)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoHelpText);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoHelpText);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_NoHelpText;
|
m_debugMode |= btIDebugDraw::DBG_NoHelpText;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
if (m_debugMode & btIDebugDraw::DBG_DrawWireframe)
|
if (m_debugMode & btIDebugDraw::DBG_DrawWireframe)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawWireframe);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawWireframe);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
if (m_debugMode & btIDebugDraw::DBG_ProfileTimings)
|
if (m_debugMode & btIDebugDraw::DBG_ProfileTimings)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_ProfileTimings);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_ProfileTimings);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_ProfileTimings;
|
m_debugMode |= btIDebugDraw::DBG_ProfileTimings;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if (m_debugMode & btIDebugDraw::DBG_EnableSatComparison)
|
if (m_debugMode & btIDebugDraw::DBG_EnableSatComparison)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_EnableSatComparison);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_EnableSatComparison);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_EnableSatComparison;
|
m_debugMode |= btIDebugDraw::DBG_EnableSatComparison;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
if (m_debugMode & btIDebugDraw::DBG_DisableBulletLCP)
|
if (m_debugMode & btIDebugDraw::DBG_DisableBulletLCP)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DisableBulletLCP);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DisableBulletLCP);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_DisableBulletLCP;
|
m_debugMode |= btIDebugDraw::DBG_DisableBulletLCP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't' :
|
case 't' :
|
||||||
if (m_debugMode & btIDebugDraw::DBG_DrawText)
|
if (m_debugMode & btIDebugDraw::DBG_DrawText)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawText);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawText);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_DrawText;
|
m_debugMode |= btIDebugDraw::DBG_DrawText;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
if (m_debugMode & btIDebugDraw::DBG_DrawFeaturesText)
|
if (m_debugMode & btIDebugDraw::DBG_DrawFeaturesText)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawFeaturesText);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawFeaturesText);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_DrawFeaturesText;
|
m_debugMode |= btIDebugDraw::DBG_DrawFeaturesText;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
if (m_debugMode & btIDebugDraw::DBG_DrawAabb)
|
if (m_debugMode & btIDebugDraw::DBG_DrawAabb)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawAabb);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawAabb);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_DrawAabb;
|
m_debugMode |= btIDebugDraw::DBG_DrawAabb;
|
||||||
break;
|
break;
|
||||||
case 'c' :
|
case 'c' :
|
||||||
if (m_debugMode & btIDebugDraw::DBG_DrawContactPoints)
|
if (m_debugMode & btIDebugDraw::DBG_DrawContactPoints)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawContactPoints);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawContactPoints);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_DrawContactPoints;
|
m_debugMode |= btIDebugDraw::DBG_DrawContactPoints;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd' :
|
case 'd' :
|
||||||
if (m_debugMode & btIDebugDraw::DBG_NoDeactivation)
|
if (m_debugMode & btIDebugDraw::DBG_NoDeactivation)
|
||||||
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoDeactivation);
|
m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoDeactivation);
|
||||||
else
|
else
|
||||||
m_debugMode |= btIDebugDraw::DBG_NoDeactivation;
|
m_debugMode |= btIDebugDraw::DBG_NoDeactivation;
|
||||||
if (m_debugMode & btIDebugDraw::DBG_NoDeactivation)
|
if (m_debugMode & btIDebugDraw::DBG_NoDeactivation)
|
||||||
{
|
{
|
||||||
gDisableDeactivation = true;
|
gDisableDeactivation = true;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
gDisableDeactivation = false;
|
gDisableDeactivation = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -379,10 +379,10 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 's' : clientMoveAndDisplay(); break;
|
case 's' : clientMoveAndDisplay(); break;
|
||||||
// case ' ' : newRandom(); break;
|
// case ' ' : newRandom(); break;
|
||||||
case ' ':
|
case ' ':
|
||||||
clientResetScene();
|
clientResetScene();
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
{
|
{
|
||||||
if (m_debugMode & btIDebugDraw::DBG_EnableCCD)
|
if (m_debugMode & btIDebugDraw::DBG_EnableCCD)
|
||||||
@@ -392,27 +392,27 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
{
|
{
|
||||||
shootBox(getCameraTargetPosition());
|
shootBox(getCameraTargetPosition());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '+':
|
case '+':
|
||||||
{
|
{
|
||||||
m_ShootBoxInitialSpeed += 10.f;
|
m_ShootBoxInitialSpeed += 10.f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '-':
|
case '-':
|
||||||
{
|
{
|
||||||
m_ShootBoxInitialSpeed -= 10.f;
|
m_ShootBoxInitialSpeed -= 10.f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// std::cout << "unused key : " << key << std::endl;
|
// std::cout << "unused key : " << key << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getDynamicsWorld() && getDynamicsWorld()->getDebugDrawer())
|
if (getDynamicsWorld() && getDynamicsWorld()->getDebugDrawer())
|
||||||
getDynamicsWorld()->getDebugDrawer()->setDebugMode(m_debugMode);
|
getDynamicsWorld()->getDebugDrawer()->setDebugMode(m_debugMode);
|
||||||
@@ -432,7 +432,7 @@ void DemoApplication::setDebugMode(int mode)
|
|||||||
void DemoApplication::specialKeyboardUp(int key, int x, int y)
|
void DemoApplication::specialKeyboardUp(int key, int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,8 +441,8 @@ void DemoApplication::specialKeyboard(int key, int x, int y)
|
|||||||
(void)x;
|
(void)x;
|
||||||
(void)y;
|
(void)y;
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case GLUT_KEY_F1:
|
case GLUT_KEY_F1:
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -450,10 +450,10 @@ void DemoApplication::specialKeyboard(int key, int x, int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case GLUT_KEY_F2:
|
case GLUT_KEY_F2:
|
||||||
{
|
{
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case GLUT_KEY_END:
|
case GLUT_KEY_END:
|
||||||
@@ -475,17 +475,17 @@ void DemoApplication::specialKeyboard(int key, int x, int y)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GLUT_KEY_LEFT : stepLeft(); break;
|
case GLUT_KEY_LEFT : stepLeft(); break;
|
||||||
case GLUT_KEY_RIGHT : stepRight(); break;
|
case GLUT_KEY_RIGHT : stepRight(); break;
|
||||||
case GLUT_KEY_UP : stepFront(); break;
|
case GLUT_KEY_UP : stepFront(); break;
|
||||||
case GLUT_KEY_DOWN : stepBack(); break;
|
case GLUT_KEY_DOWN : stepBack(); break;
|
||||||
case GLUT_KEY_PAGE_UP : zoomIn(); break;
|
case GLUT_KEY_PAGE_UP : zoomIn(); break;
|
||||||
case GLUT_KEY_PAGE_DOWN : zoomOut(); break;
|
case GLUT_KEY_PAGE_DOWN : zoomOut(); break;
|
||||||
case GLUT_KEY_HOME : toggleIdle(); break;
|
case GLUT_KEY_HOME : toggleIdle(); break;
|
||||||
default:
|
default:
|
||||||
// std::cout << "unused (special) key : " << key << std::endl;
|
// std::cout << "unused (special) key : " << key << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
|
||||||
@@ -522,12 +522,12 @@ void DemoApplication::shootBox(const btVector3& destination)
|
|||||||
|
|
||||||
if (!m_shootBoxShape)
|
if (!m_shootBoxShape)
|
||||||
{
|
{
|
||||||
//#define TEST_UNIFORM_SCALING_SHAPE 1
|
//#define TEST_UNIFORM_SCALING_SHAPE 1
|
||||||
#ifdef TEST_UNIFORM_SCALING_SHAPE
|
#ifdef TEST_UNIFORM_SCALING_SHAPE
|
||||||
btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
||||||
m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
|
m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
|
||||||
#else
|
#else
|
||||||
m_shootBoxShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
m_shootBoxShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
||||||
#endif//
|
#endif//
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ btRigidBody* pickedBody = 0;//for deactivation state
|
|||||||
btVector3 DemoApplication::getRayTo(int x,int y)
|
btVector3 DemoApplication::getRayTo(int x,int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
float top = 1.f;
|
float top = 1.f;
|
||||||
float bottom = -1.f;
|
float bottom = -1.f;
|
||||||
float nearPlane = 1.f;
|
float nearPlane = 1.f;
|
||||||
float tanFov = (top-bottom)*0.5f / nearPlane;
|
float tanFov = (top-bottom)*0.5f / nearPlane;
|
||||||
@@ -642,14 +642,14 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
|
|||||||
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
|
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
|
||||||
if (body)
|
if (body)
|
||||||
{
|
{
|
||||||
body->setActivationState(ACTIVE_TAG);
|
body->setActivationState(ACTIVE_TAG);
|
||||||
btVector3 impulse = rayTo;
|
btVector3 impulse = rayTo;
|
||||||
impulse.normalize();
|
impulse.normalize();
|
||||||
float impulseStrength = 10.f;
|
float impulseStrength = 10.f;
|
||||||
impulse *= impulseStrength;
|
impulse *= impulseStrength;
|
||||||
btVector3 relPos = rayCallback.m_hitPointWorld - body->getCenterOfMassPosition();
|
btVector3 relPos = rayCallback.m_hitPointWorld - body->getCenterOfMassPosition();
|
||||||
body->applyImpulse(impulse,relPos);
|
body->applyImpulse(impulse,relPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -847,7 +847,7 @@ void DemoApplication::showProfileInfo(float& xOffset,float& yStart, float yIncr)
|
|||||||
static double time_since_reset = 0.f;
|
static double time_since_reset = 0.f;
|
||||||
if (!m_idle)
|
if (!m_idle)
|
||||||
{
|
{
|
||||||
time_since_reset = CProfileManager::Get_Time_Since_Reset();
|
time_since_reset = CProfileManager::Get_Time_Since_Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -916,57 +916,64 @@ void DemoApplication::showProfileInfo(float& xOffset,float& yStart, float yIncr)
|
|||||||
//
|
//
|
||||||
void DemoApplication::renderscene(int pass)
|
void DemoApplication::renderscene(int pass)
|
||||||
{
|
{
|
||||||
btScalar m[16];
|
btScalar m[16];
|
||||||
btMatrix3x3 rot;rot.setIdentity();
|
btMatrix3x3 rot;rot.setIdentity();
|
||||||
const int numObjects=m_dynamicsWorld->getNumCollisionObjects();
|
const int numObjects=m_dynamicsWorld->getNumCollisionObjects();
|
||||||
btVector3 wireColor(1,0,0);
|
btVector3 wireColor(1,0,0);
|
||||||
for(int i=0;i<numObjects;i++)
|
for(int i=0;i<numObjects;i++)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj=m_dynamicsWorld->getCollisionObjectArray()[i];
|
btCollisionObject* colObj=m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||||
btRigidBody* body=btRigidBody::upcast(colObj);
|
btRigidBody* body=btRigidBody::upcast(colObj);
|
||||||
if(body&&body->getMotionState())
|
if(body&&body->getMotionState())
|
||||||
{
|
{
|
||||||
btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
|
btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
|
||||||
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
|
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
|
||||||
rot=myMotionState->m_graphicsWorldTrans.getBasis();
|
rot=myMotionState->m_graphicsWorldTrans.getBasis();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colObj->getWorldTransform().getOpenGLMatrix(m);
|
colObj->getWorldTransform().getOpenGLMatrix(m);
|
||||||
rot=colObj->getWorldTransform().getBasis();
|
rot=colObj->getWorldTransform().getBasis();
|
||||||
}
|
}
|
||||||
btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
|
btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
|
||||||
if(i&1) wireColor=btVector3(0.f,0.0f,1.f);
|
if(i&1) wireColor=btVector3(0.f,0.0f,1.f);
|
||||||
///color differently for active, sleeping, wantsdeactivation states
|
///color differently for active, sleeping, wantsdeactivation states
|
||||||
if (colObj->getActivationState() == 1) //active
|
if (colObj->getActivationState() == 1) //active
|
||||||
{
|
{
|
||||||
if (i & 1)
|
if (i & 1)
|
||||||
{
|
{
|
||||||
wireColor += btVector3 (1.f,0.f,0.f);
|
wireColor += btVector3 (1.f,0.f,0.f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wireColor += btVector3 (.5f,0.f,0.f);
|
wireColor += btVector3 (.5f,0.f,0.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(colObj->getActivationState()==2) //ISLAND_SLEEPING
|
if(colObj->getActivationState()==2) //ISLAND_SLEEPING
|
||||||
{
|
{
|
||||||
if(i&1)
|
if(i&1)
|
||||||
{
|
{
|
||||||
wireColor += btVector3 (0.f,1.f, 0.f);
|
wireColor += btVector3 (0.f,1.f, 0.f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wireColor += btVector3 (0.f,0.5f,0.f);
|
wireColor += btVector3 (0.f,0.5f,0.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
btVector3 aabbMin,aabbMax;
|
btVector3 aabbMin,aabbMax;
|
||||||
m_dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin,aabbMax);
|
m_dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin,aabbMax);
|
||||||
|
|
||||||
switch(pass)
|
aabbMin-=btVector3(1e30,1e30,1e30);
|
||||||
|
aabbMax+=btVector3(1e30,1e30,1e30);
|
||||||
|
// printf("aabbMin=(%f,%f,%f)\n",aabbMin.getX(),aabbMin.getY(),aabbMin.getZ());
|
||||||
|
// printf("aabbMax=(%f,%f,%f)\n",aabbMax.getX(),aabbMax.getY(),aabbMax.getZ());
|
||||||
|
// m_dynamicsWorld->getDebugDrawer()->drawAabb(aabbMin,aabbMax,btVector3(1,1,1));
|
||||||
|
|
||||||
|
|
||||||
|
switch(pass)
|
||||||
{
|
{
|
||||||
case 0: m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode(),aabbMin,aabbMax);break;
|
case 0: m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode(),aabbMin,aabbMax);break;
|
||||||
case 1: m_shapeDrawer.drawShadow(m,m_sundirection*rot,colObj->getCollisionShape(),aabbMin,aabbMax);break;
|
case 1: m_shapeDrawer.drawShadow(m,m_sundirection*rot,colObj->getCollisionShape(),aabbMin,aabbMax);break;
|
||||||
case 2: m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor*0.3,0,aabbMin,aabbMax);break;
|
case 2: m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor*0.3,0,aabbMin,aabbMax);break;
|
||||||
}
|
}
|
||||||
@@ -983,7 +990,7 @@ void DemoApplication::renderme()
|
|||||||
if (m_dynamicsWorld)
|
if (m_dynamicsWorld)
|
||||||
{
|
{
|
||||||
if(m_enableshadows)
|
if(m_enableshadows)
|
||||||
{
|
{
|
||||||
glClear(GL_STENCIL_BUFFER_BIT);
|
glClear(GL_STENCIL_BUFFER_BIT);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
renderscene(0);
|
renderscene(0);
|
||||||
@@ -1023,27 +1030,28 @@ void DemoApplication::renderme()
|
|||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
renderscene(0);
|
renderscene(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float xOffset = 10.f;
|
float xOffset = 10.f;
|
||||||
float yStart = 20.f;
|
float yStart = 20.f;
|
||||||
float yIncr = 20.f;
|
float yIncr = 20.f;
|
||||||
char buf[124];
|
char buf[124];
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glColor3f(0, 0, 0);
|
glColor3f(0, 0, 0);
|
||||||
|
|
||||||
if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0)
|
if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0)
|
||||||
{
|
{
|
||||||
setOrthographicProjection();
|
setOrthographicProjection();
|
||||||
|
|
||||||
showProfileInfo(xOffset,yStart,yIncr);
|
showProfileInfo(xOffset,yStart,yIncr);
|
||||||
|
|
||||||
#ifdef USE_QUICKPROF
|
#ifdef USE_QUICKPROF
|
||||||
|
|
||||||
|
|
||||||
if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings)
|
if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings)
|
||||||
@@ -1062,139 +1070,139 @@ void DemoApplication::renderme()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif //USE_QUICKPROF
|
#endif //USE_QUICKPROF
|
||||||
|
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"mouse to interact");
|
sprintf(buf,"mouse to interact");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"space to reset");
|
sprintf(buf,"space to reset");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"cursor keys and z,x to navigate");
|
sprintf(buf,"cursor keys and z,x to navigate");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"i to toggle simulation, s single step");
|
sprintf(buf,"i to toggle simulation, s single step");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"q to quit");
|
sprintf(buf,"q to quit");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,". to shoot box");
|
sprintf(buf,". to shoot box");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
// not yet hooked up again after refactoring...
|
// not yet hooked up again after refactoring...
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"d to toggle deactivation");
|
sprintf(buf,"d to toggle deactivation");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"g to toggle mesh animation (ConcaveDemo)");
|
sprintf(buf,"g to toggle mesh animation (ConcaveDemo)");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"h to toggle help text");
|
sprintf(buf,"h to toggle help text");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"p to toggle profiling (+results to file)");
|
sprintf(buf,"p to toggle profiling (+results to file)");
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
|
|
||||||
//bool useBulletLCP = !(getDebugMode() & btIDebugDraw::DBG_DisableBulletLCP);
|
//bool useBulletLCP = !(getDebugMode() & btIDebugDraw::DBG_DisableBulletLCP);
|
||||||
//bool useCCD = (getDebugMode() & btIDebugDraw::DBG_EnableCCD);
|
//bool useCCD = (getDebugMode() & btIDebugDraw::DBG_EnableCCD);
|
||||||
//glRasterPos3f(xOffset,yStart,0);
|
//glRasterPos3f(xOffset,yStart,0);
|
||||||
//sprintf(buf,"1 CCD mode (adhoc) = %i",useCCD);
|
//sprintf(buf,"1 CCD mode (adhoc) = %i",useCCD);
|
||||||
//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
//yStart += yIncr;
|
//yStart += yIncr;
|
||||||
|
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"+- shooting speed = %10.2f",m_ShootBoxInitialSpeed);
|
sprintf(buf,"+- shooting speed = %10.2f",m_ShootBoxInitialSpeed);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
#ifdef SHOW_NUM_DEEP_PENETRATIONS
|
#ifdef SHOW_NUM_DEEP_PENETRATIONS
|
||||||
|
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"gNumDeepPenetrationChecks = %d",gNumDeepPenetrationChecks);
|
sprintf(buf,"gNumDeepPenetrationChecks = %d",gNumDeepPenetrationChecks);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"gNumGjkChecks= %d",gNumGjkChecks);
|
sprintf(buf,"gNumGjkChecks= %d",gNumGjkChecks);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"gNumSplitImpulseRecoveries= %d",gNumSplitImpulseRecoveries);
|
sprintf(buf,"gNumSplitImpulseRecoveries= %d",gNumSplitImpulseRecoveries);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"gNumAlignedAllocs = %d",gNumAlignedAllocs);
|
sprintf(buf,"gNumAlignedAllocs = %d",gNumAlignedAllocs);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree);
|
sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree);
|
sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
//enable BT_DEBUG_MEMORY_ALLOCATIONS define in Bullet/src/LinearMath/btAlignedAllocator.h for memory leak detection
|
//enable BT_DEBUG_MEMORY_ALLOCATIONS define in Bullet/src/LinearMath/btAlignedAllocator.h for memory leak detection
|
||||||
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs);
|
sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs);
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||||
|
|
||||||
if (getDynamicsWorld())
|
if (getDynamicsWorld())
|
||||||
{
|
{
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"# objects = %d",getDynamicsWorld()->getNumCollisionObjects());
|
sprintf(buf,"# objects = %d",getDynamicsWorld()->getNumCollisionObjects());
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
glRasterPos3f(xOffset,yStart,0);
|
glRasterPos3f(xOffset,yStart,0);
|
||||||
sprintf(buf,"# pairs = %d",getDynamicsWorld()->getBroadphase()->getOverlappingPairCache()->getNumOverlappingPairs());
|
sprintf(buf,"# pairs = %d",getDynamicsWorld()->getBroadphase()->getOverlappingPairCache()->getNumOverlappingPairs());
|
||||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
|
||||||
yStart += yIncr;
|
yStart += yIncr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif //SHOW_NUM_DEEP_PENETRATIONS
|
#endif //SHOW_NUM_DEEP_PENETRATIONS
|
||||||
|
|
||||||
resetPerspectiveProjection();
|
resetPerspectiveProjection();
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1243,13 +1251,13 @@ void DemoApplication::clientResetScene()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//quickly search some issue at a certain simulation frame, pressing space to reset
|
//quickly search some issue at a certain simulation frame, pressing space to reset
|
||||||
int fixed=18;
|
int fixed=18;
|
||||||
for (int i=0;i<fixed;i++)
|
for (int i=0;i<fixed;i++)
|
||||||
{
|
{
|
||||||
getDynamicsWorld()->stepSimulation(1./60.f,1);
|
getDynamicsWorld()->stepSimulation(1./60.f,1);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ void OGL_displaylist_register_shape(btCollisionShape * shape)
|
|||||||
|
|
||||||
glNewList(dlist.m_dlist,GL_COMPILE);
|
glNewList(dlist.m_dlist,GL_COMPILE);
|
||||||
|
|
||||||
glEnable(GL_CULL_FACE);
|
// glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ void OGL_displaylist_register_shape(btCollisionShape * shape)
|
|||||||
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
|
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
// glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
glEndList();
|
glEndList();
|
||||||
}
|
}
|
||||||
@@ -237,12 +237,16 @@ public:
|
|||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
glColor3f(1, 1, 1);
|
//glColor3f(1, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||||
//glColor3f(0, 1, 0);
|
|
||||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||||
//glColor3f(0, 0, 1);
|
|
||||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||||
|
|
||||||
|
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||||
|
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||||
|
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,17 @@ subject to the following restrictions:
|
|||||||
#include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
|
#include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||||
|
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
||||||
|
#include "LinearMath/btIDebugDraw.h"
|
||||||
|
#include "LinearMath/btAabbUtil2.h"
|
||||||
|
|
||||||
btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
|
btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
|
||||||
:btCollisionAlgorithm(ci),
|
:btCollisionAlgorithm(ci),
|
||||||
m_isSwapped(isSwapped)
|
m_isSwapped(isSwapped),
|
||||||
|
m_sharedManifold(ci.m_manifold)
|
||||||
{
|
{
|
||||||
|
m_ownsManifold = false;
|
||||||
|
|
||||||
btCollisionObject* colObj = m_isSwapped? body1 : body0;
|
btCollisionObject* colObj = m_isSwapped? body1 : body0;
|
||||||
btCollisionObject* otherObj = m_isSwapped? body0 : body1;
|
btCollisionObject* otherObj = m_isSwapped? body0 : body1;
|
||||||
assert (colObj->getCollisionShape()->isCompound());
|
assert (colObj->getCollisionShape()->isCompound());
|
||||||
@@ -33,11 +38,17 @@ m_isSwapped(isSwapped)
|
|||||||
m_childCollisionAlgorithms.resize(numChildren);
|
m_childCollisionAlgorithms.resize(numChildren);
|
||||||
for (i=0;i<numChildren;i++)
|
for (i=0;i<numChildren;i++)
|
||||||
{
|
{
|
||||||
btCollisionShape* tmpShape = colObj->getCollisionShape();
|
if (compoundShape->getDynamicAabbTree())
|
||||||
btCollisionShape* childShape = compoundShape->getChildShape(i);
|
{
|
||||||
colObj->internalSetTemporaryCollisionShape( childShape );
|
m_childCollisionAlgorithms[i] = 0;
|
||||||
m_childCollisionAlgorithms[i] = ci.m_dispatcher1->findAlgorithm(colObj,otherObj);
|
} else
|
||||||
colObj->internalSetTemporaryCollisionShape( tmpShape );
|
{
|
||||||
|
btCollisionShape* tmpShape = colObj->getCollisionShape();
|
||||||
|
btCollisionShape* childShape = compoundShape->getChildShape(i);
|
||||||
|
colObj->internalSetTemporaryCollisionShape( childShape );
|
||||||
|
m_childCollisionAlgorithms[i] = ci.m_dispatcher1->findAlgorithm(colObj,otherObj,m_sharedManifold);
|
||||||
|
colObj->internalSetTemporaryCollisionShape( tmpShape );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,11 +59,109 @@ btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm()
|
|||||||
int i;
|
int i;
|
||||||
for (i=0;i<numChildren;i++)
|
for (i=0;i<numChildren;i++)
|
||||||
{
|
{
|
||||||
m_childCollisionAlgorithms[i]->~btCollisionAlgorithm();
|
if (m_childCollisionAlgorithms[i])
|
||||||
m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
|
{
|
||||||
|
m_childCollisionAlgorithms[i]->~btCollisionAlgorithm();
|
||||||
|
m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct btCompoundLeafCallback : btDbvt::ICollide
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
btCollisionObject* m_compoundColObj;
|
||||||
|
btCollisionObject* m_otherObj;
|
||||||
|
btDispatcher* m_dispatcher;
|
||||||
|
const btDispatcherInfo& m_dispatchInfo;
|
||||||
|
btManifoldResult* m_resultOut;
|
||||||
|
btCollisionAlgorithm** m_childCollisionAlgorithms;
|
||||||
|
btPersistentManifold* m_sharedManifold;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
btCompoundLeafCallback (btCollisionObject* compoundObj,btCollisionObject* otherObj,btDispatcher* dispatcher,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut,btCollisionAlgorithm** childCollisionAlgorithms,btPersistentManifold* sharedManifold)
|
||||||
|
:m_compoundColObj(compoundObj),m_otherObj(otherObj),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
|
||||||
|
m_childCollisionAlgorithms(childCollisionAlgorithms),
|
||||||
|
m_sharedManifold(sharedManifold)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ProcessChildShape(btCollisionShape* childShape,int index)
|
||||||
|
{
|
||||||
|
|
||||||
|
btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape());
|
||||||
|
|
||||||
|
|
||||||
|
//backup
|
||||||
|
btTransform orgTrans = m_compoundColObj->getWorldTransform();
|
||||||
|
btTransform orgInterpolationTrans = m_compoundColObj->getInterpolationWorldTransform();
|
||||||
|
const btTransform& childTrans = compoundShape->getChildTransform(index);
|
||||||
|
btTransform newChildWorldTrans = orgTrans*childTrans ;
|
||||||
|
|
||||||
|
//perform an AABB check first
|
||||||
|
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
||||||
|
childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
|
||||||
|
m_otherObj->getCollisionShape()->getAabb(m_otherObj->getWorldTransform(),aabbMin1,aabbMax1);
|
||||||
|
|
||||||
|
if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
|
||||||
|
{
|
||||||
|
|
||||||
|
m_compoundColObj->setWorldTransform( newChildWorldTrans);
|
||||||
|
m_compoundColObj->setInterpolationWorldTransform(newChildWorldTrans);
|
||||||
|
|
||||||
|
//the contactpoint is still projected back using the original inverted worldtrans
|
||||||
|
btCollisionShape* tmpShape = m_compoundColObj->getCollisionShape();
|
||||||
|
m_compoundColObj->internalSetTemporaryCollisionShape( childShape );
|
||||||
|
|
||||||
|
if (!m_childCollisionAlgorithms[index])
|
||||||
|
m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold);
|
||||||
|
|
||||||
|
m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut);
|
||||||
|
if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
|
||||||
|
{
|
||||||
|
btVector3 worldAabbMin,worldAabbMax;
|
||||||
|
m_dispatchInfo.m_debugDraw->drawAabb(aabbMin0,aabbMax0,btVector3(1,1,1));
|
||||||
|
m_dispatchInfo.m_debugDraw->drawAabb(aabbMin1,aabbMax1,btVector3(1,1,1));
|
||||||
|
}
|
||||||
|
|
||||||
|
//revert back transform
|
||||||
|
m_compoundColObj->internalSetTemporaryCollisionShape( tmpShape);
|
||||||
|
m_compoundColObj->setWorldTransform( orgTrans );
|
||||||
|
m_compoundColObj->setInterpolationWorldTransform(orgInterpolationTrans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Process(const btDbvtNode* leaf)
|
||||||
|
{
|
||||||
|
int index = int(leaf->data);
|
||||||
|
|
||||||
|
btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape());
|
||||||
|
btCollisionShape* childShape = compoundShape->getChildShape(index);
|
||||||
|
if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
|
||||||
|
{
|
||||||
|
btVector3 worldAabbMin,worldAabbMax;
|
||||||
|
btTransform orgTrans = m_compoundColObj->getWorldTransform();
|
||||||
|
btTransformAabb(leaf->volume.Mins(),leaf->volume.Maxs(),0.,orgTrans,worldAabbMin,worldAabbMax);
|
||||||
|
m_dispatchInfo.m_debugDraw->drawAabb(worldAabbMin,worldAabbMax,btVector3(1,0,0));
|
||||||
|
}
|
||||||
|
ProcessChildShape(childShape,index);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||||
{
|
{
|
||||||
btCollisionObject* colObj = m_isSwapped? body1 : body0;
|
btCollisionObject* colObj = m_isSwapped? body1 : body0;
|
||||||
@@ -61,37 +170,69 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
|
|||||||
assert (colObj->getCollisionShape()->isCompound());
|
assert (colObj->getCollisionShape()->isCompound());
|
||||||
btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
|
btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
|
||||||
|
|
||||||
//We will use the OptimizedBVH, AABB tree to cull potential child-overlaps
|
btDbvt* tree = compoundShape->getDynamicAabbTree();
|
||||||
//If both proxies are Compound, we will deal with that directly, by performing sequential/parallel tree traversals
|
//use a dynamic aabb tree to cull potential child-overlaps
|
||||||
//given Proxy0 and Proxy1, if both have a tree, Tree0 and Tree1, this means:
|
btCompoundLeafCallback callback(colObj,otherObj,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);
|
||||||
//determine overlapping nodes of Proxy1 using Proxy0 AABB against Tree1
|
|
||||||
//then use each overlapping node AABB against Tree0
|
|
||||||
//and vise versa.
|
|
||||||
|
|
||||||
int numChildren = m_childCollisionAlgorithms.size();
|
|
||||||
int i;
|
if (tree)
|
||||||
for (i=0;i<numChildren;i++)
|
|
||||||
{
|
{
|
||||||
//temporarily exchange parent btCollisionShape with childShape, and recurse
|
|
||||||
btCollisionShape* childShape = compoundShape->getChildShape(i);
|
|
||||||
|
|
||||||
//backup
|
btVector3 localAabbMin,localAabbMax;
|
||||||
btTransform orgTrans = colObj->getWorldTransform();
|
btTransform otherInCompoundSpace;
|
||||||
btTransform orgInterpolationTrans = colObj->getInterpolationWorldTransform();
|
otherInCompoundSpace = colObj->getWorldTransform().inverse() * otherObj->getWorldTransform();
|
||||||
|
otherObj->getCollisionShape()->getAabb(otherInCompoundSpace,localAabbMin,localAabbMax);
|
||||||
|
|
||||||
|
const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
|
||||||
|
//process all children, that overlap with the given AABB bounds
|
||||||
|
tree->collideTV(tree->m_root,bounds,callback);
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
//iterate over all children, perform an AABB check inside ProcessChildShape
|
||||||
|
int numChildren = m_childCollisionAlgorithms.size();
|
||||||
|
int i;
|
||||||
|
for (i=0;i<numChildren;i++)
|
||||||
|
{
|
||||||
|
callback.ProcessChildShape(compoundShape->getChildShape(i),i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//iterate over all children, perform an AABB check inside ProcessChildShape
|
||||||
|
int numChildren = m_childCollisionAlgorithms.size();
|
||||||
|
int i;
|
||||||
|
btManifoldArray manifoldArray;
|
||||||
|
|
||||||
|
for (i=0;i<numChildren;i++)
|
||||||
|
{
|
||||||
|
if (m_childCollisionAlgorithms[i])
|
||||||
|
{
|
||||||
|
btCollisionShape* childShape = compoundShape->getChildShape(i);
|
||||||
|
//if not longer overlapping, remove the algorithm
|
||||||
|
btTransform orgTrans = colObj->getWorldTransform();
|
||||||
|
btTransform orgInterpolationTrans = colObj->getInterpolationWorldTransform();
|
||||||
|
const btTransform& childTrans = compoundShape->getChildTransform(i);
|
||||||
|
btTransform newChildWorldTrans = orgTrans*childTrans ;
|
||||||
|
|
||||||
|
//perform an AABB check first
|
||||||
|
btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
|
||||||
|
childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
|
||||||
|
otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1);
|
||||||
|
|
||||||
|
if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
|
||||||
|
{
|
||||||
|
m_childCollisionAlgorithms[i]->~btCollisionAlgorithm();
|
||||||
|
m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
|
||||||
|
m_childCollisionAlgorithms[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const btTransform& childTrans = compoundShape->getChildTransform(i);
|
|
||||||
btTransform newChildWorldTrans = orgTrans*childTrans ;
|
|
||||||
colObj->setWorldTransform( newChildWorldTrans);
|
|
||||||
colObj->setInterpolationWorldTransform(newChildWorldTrans);
|
|
||||||
|
|
||||||
//the contactpoint is still projected back using the original inverted worldtrans
|
|
||||||
btCollisionShape* tmpShape = colObj->getCollisionShape();
|
|
||||||
colObj->internalSetTemporaryCollisionShape( childShape );
|
|
||||||
m_childCollisionAlgorithms[i]->processCollision(colObj,otherObj,dispatchInfo,resultOut);
|
|
||||||
//revert back
|
|
||||||
colObj->internalSetTemporaryCollisionShape( tmpShape);
|
|
||||||
colObj->setWorldTransform( orgTrans );
|
|
||||||
colObj->setInterpolationWorldTransform(orgInterpolationTrans);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ class btDispatcher;
|
|||||||
class btDispatcher;
|
class btDispatcher;
|
||||||
|
|
||||||
/// btCompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision shapes
|
/// btCompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision shapes
|
||||||
/// Place holder, not fully implemented yet
|
|
||||||
class btCompoundCollisionAlgorithm : public btCollisionAlgorithm
|
class btCompoundCollisionAlgorithm : public btCollisionAlgorithm
|
||||||
{
|
{
|
||||||
btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
|
btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
|
||||||
bool m_isSwapped;
|
bool m_isSwapped;
|
||||||
|
|
||||||
|
class btPersistentManifold* m_sharedManifold;
|
||||||
|
bool m_ownsManifold;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
|
btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
|
||||||
|
|||||||
@@ -21,20 +21,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
void btBoxShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
|
void btBoxShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
|
||||||
{
|
{
|
||||||
btVector3 halfExtents = getHalfExtentsWithoutMargin();
|
btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax);
|
||||||
halfExtents += btVector3(getMargin(),getMargin(),getMargin());
|
|
||||||
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
aabbMin = center - extent;
|
|
||||||
aabbMax = center + extent;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,23 +14,29 @@ subject to the following restrictions:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "btCompoundShape.h"
|
#include "btCompoundShape.h"
|
||||||
|
|
||||||
|
|
||||||
#include "btCollisionShape.h"
|
#include "btCollisionShape.h"
|
||||||
|
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
||||||
|
|
||||||
btCompoundShape::btCompoundShape()
|
btCompoundShape::btCompoundShape()
|
||||||
:m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
|
:m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
|
||||||
m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
|
m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
|
||||||
m_aabbTree(0),
|
|
||||||
m_collisionMargin(btScalar(0.)),
|
m_collisionMargin(btScalar(0.)),
|
||||||
m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
|
m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
||||||
|
m_dynamicAabbTree(0)
|
||||||
{
|
{
|
||||||
|
void* mem = btAlignedAlloc(sizeof(btDbvt),16);
|
||||||
|
m_dynamicAabbTree = new(mem) btDbvt();
|
||||||
|
btAssert(mem==m_dynamicAabbTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
btCompoundShape::~btCompoundShape()
|
btCompoundShape::~btCompoundShape()
|
||||||
{
|
{
|
||||||
|
if (m_dynamicAabbTree)
|
||||||
|
{
|
||||||
|
m_dynamicAabbTree->~btDbvt();
|
||||||
|
btAlignedFree(m_dynamicAabbTree);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
|
void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
|
||||||
@@ -60,55 +66,72 @@ void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (m_dynamicAabbTree)
|
||||||
|
{
|
||||||
|
const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
|
||||||
|
int index = m_children.size()-1;
|
||||||
|
child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
|
||||||
|
{
|
||||||
|
btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size());
|
||||||
|
if (m_dynamicAabbTree)
|
||||||
|
{
|
||||||
|
m_dynamicAabbTree->remove(m_children[childShapeIndex].m_node);
|
||||||
|
}
|
||||||
|
m_children.swap(childShapeIndex,m_children.size()-1);
|
||||||
|
m_children.pop_back();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void btCompoundShape::removeChildShape(btCollisionShape* shape)
|
void btCompoundShape::removeChildShape(btCollisionShape* shape)
|
||||||
{
|
{
|
||||||
bool done_removing;
|
// Find the children containing the shape specified, and remove those children.
|
||||||
|
//note: there might be multiple children using the same shape!
|
||||||
|
for(int i = m_children.size()-1; i >= 0 ; i--)
|
||||||
|
{
|
||||||
|
if(m_children[i].m_childShape == shape)
|
||||||
|
{
|
||||||
|
m_children.swap(i,m_children.size()-1);
|
||||||
|
m_children.pop_back();
|
||||||
|
//remove it from the m_dynamicAabbTree too
|
||||||
|
//m_dynamicAabbTree->remove(m_aabbProxies[i]);
|
||||||
|
//m_aabbProxies.swap(i,m_children.size()-1);
|
||||||
|
//m_aabbProxies.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Find the children containing the shape specified, and remove those children.
|
|
||||||
do
|
|
||||||
{
|
|
||||||
done_removing = true;
|
|
||||||
|
|
||||||
for(int i = 0; i < m_children.size(); i++)
|
|
||||||
{
|
|
||||||
if(m_children[i].m_childShape == shape)
|
|
||||||
{
|
|
||||||
m_children.remove(m_children[i]);
|
|
||||||
done_removing = false; // Do another iteration pass after removing from the vector
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (!done_removing);
|
|
||||||
|
|
||||||
recalculateLocalAabb();
|
recalculateLocalAabb();
|
||||||
}
|
}
|
||||||
|
|
||||||
void btCompoundShape::recalculateLocalAabb()
|
void btCompoundShape::recalculateLocalAabb()
|
||||||
{
|
{
|
||||||
// Recalculate the local aabb
|
// Recalculate the local aabb
|
||||||
// Brute force, it iterates over all the shapes left.
|
// Brute force, it iterates over all the shapes left.
|
||||||
m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30));
|
m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30));
|
||||||
m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
|
m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
|
||||||
|
|
||||||
//extend the local aabbMin/aabbMax
|
//extend the local aabbMin/aabbMax
|
||||||
for (int j = 0; j < m_children.size(); j++)
|
for (int j = 0; j < m_children.size(); j++)
|
||||||
{
|
{
|
||||||
btVector3 localAabbMin,localAabbMax;
|
btVector3 localAabbMin,localAabbMax;
|
||||||
m_children[j].m_childShape->getAabb(m_children[j].m_transform, localAabbMin, localAabbMax);
|
m_children[j].m_childShape->getAabb(m_children[j].m_transform, localAabbMin, localAabbMax);
|
||||||
for (int i=0;i<3;i++)
|
for (int i=0;i<3;i++)
|
||||||
{
|
{
|
||||||
if (m_localAabbMin[i] > localAabbMin[i])
|
if (m_localAabbMin[i] > localAabbMin[i])
|
||||||
m_localAabbMin[i] = localAabbMin[i];
|
m_localAabbMin[i] = localAabbMin[i];
|
||||||
if (m_localAabbMax[i] < localAabbMax[i])
|
if (m_localAabbMax[i] < localAabbMax[i])
|
||||||
m_localAabbMax[i] = localAabbMax[i];
|
m_localAabbMax[i] = localAabbMax[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||||
void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
|
void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
|
||||||
{
|
{
|
||||||
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
|
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
|
||||||
@@ -120,8 +143,8 @@ void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVect
|
|||||||
btPoint3 center = trans(localCenter);
|
btPoint3 center = trans(localCenter);
|
||||||
|
|
||||||
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
|
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
|
||||||
abs_b[1].dot(localHalfExtents),
|
abs_b[1].dot(localHalfExtents),
|
||||||
abs_b[2].dot(localHalfExtents));
|
abs_b[2].dot(localHalfExtents));
|
||||||
aabbMin = center-extent;
|
aabbMin = center-extent;
|
||||||
aabbMax = center+extent;
|
aabbMax = center+extent;
|
||||||
|
|
||||||
@@ -152,56 +175,56 @@ void btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) co
|
|||||||
|
|
||||||
void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const
|
void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const
|
||||||
{
|
{
|
||||||
int n = m_children.size();
|
int n = m_children.size();
|
||||||
|
|
||||||
btScalar totalMass = 0;
|
btScalar totalMass = 0;
|
||||||
btVector3 center(0, 0, 0);
|
btVector3 center(0, 0, 0);
|
||||||
for (int k = 0; k < n; k++)
|
for (int k = 0; k < n; k++)
|
||||||
{
|
{
|
||||||
center += m_children[k].m_transform.getOrigin() * masses[k];
|
center += m_children[k].m_transform.getOrigin() * masses[k];
|
||||||
totalMass += masses[k];
|
totalMass += masses[k];
|
||||||
}
|
}
|
||||||
center /= totalMass;
|
center /= totalMass;
|
||||||
principal.setOrigin(center);
|
principal.setOrigin(center);
|
||||||
|
|
||||||
btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
for (int k = 0; k < n; k++)
|
for (int k = 0; k < n; k++)
|
||||||
{
|
{
|
||||||
btVector3 i;
|
btVector3 i;
|
||||||
m_children[k].m_childShape->calculateLocalInertia(masses[k], i);
|
m_children[k].m_childShape->calculateLocalInertia(masses[k], i);
|
||||||
|
|
||||||
const btTransform& t = m_children[k].m_transform;
|
const btTransform& t = m_children[k].m_transform;
|
||||||
btVector3 o = t.getOrigin() - center;
|
btVector3 o = t.getOrigin() - center;
|
||||||
|
|
||||||
//compute inertia tensor in coordinate system of compound shape
|
//compute inertia tensor in coordinate system of compound shape
|
||||||
btMatrix3x3 j = t.getBasis().transpose();
|
btMatrix3x3 j = t.getBasis().transpose();
|
||||||
j[0] *= i[0];
|
j[0] *= i[0];
|
||||||
j[1] *= i[1];
|
j[1] *= i[1];
|
||||||
j[2] *= i[2];
|
j[2] *= i[2];
|
||||||
j = t.getBasis() * j;
|
j = t.getBasis() * j;
|
||||||
|
|
||||||
//add inertia tensor
|
//add inertia tensor
|
||||||
tensor[0] += j[0];
|
tensor[0] += j[0];
|
||||||
tensor[1] += j[1];
|
tensor[1] += j[1];
|
||||||
tensor[2] += j[2];
|
tensor[2] += j[2];
|
||||||
|
|
||||||
//compute inertia tensor of pointmass at o
|
//compute inertia tensor of pointmass at o
|
||||||
btScalar o2 = o.length2();
|
btScalar o2 = o.length2();
|
||||||
j[0].setValue(o2, 0, 0);
|
j[0].setValue(o2, 0, 0);
|
||||||
j[1].setValue(0, o2, 0);
|
j[1].setValue(0, o2, 0);
|
||||||
j[2].setValue(0, 0, o2);
|
j[2].setValue(0, 0, o2);
|
||||||
j[0] += o * -o.x();
|
j[0] += o * -o.x();
|
||||||
j[1] += o * -o.y();
|
j[1] += o * -o.y();
|
||||||
j[2] += o * -o.z();
|
j[2] += o * -o.z();
|
||||||
|
|
||||||
//add inertia tensor of pointmass
|
//add inertia tensor of pointmass
|
||||||
tensor[0] += masses[k] * j[0];
|
tensor[0] += masses[k] * j[0];
|
||||||
tensor[1] += masses[k] * j[1];
|
tensor[1] += masses[k] * j[1];
|
||||||
tensor[2] += masses[k] * j[2];
|
tensor[2] += masses[k] * j[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
tensor.diagonalize(principal.getBasis(), btScalar(0.00001), 20);
|
tensor.diagonalize(principal.getBasis(), btScalar(0.00001), 20);
|
||||||
inertia.setValue(tensor[0][0], tensor[1][1], tensor[2][2]);
|
inertia.setValue(tensor[0][0], tensor[1][1], tensor[2][2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ subject to the following restrictions:
|
|||||||
#include "btCollisionMargin.h"
|
#include "btCollisionMargin.h"
|
||||||
#include "LinearMath/btAlignedObjectArray.h"
|
#include "LinearMath/btAlignedObjectArray.h"
|
||||||
|
|
||||||
class btOptimizedBvh;
|
//class btOptimizedBvh;
|
||||||
|
struct btDbvt;
|
||||||
|
|
||||||
ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild
|
ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild
|
||||||
{
|
{
|
||||||
@@ -35,14 +35,15 @@ ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild
|
|||||||
btCollisionShape* m_childShape;
|
btCollisionShape* m_childShape;
|
||||||
int m_childShapeType;
|
int m_childShapeType;
|
||||||
btScalar m_childMargin;
|
btScalar m_childMargin;
|
||||||
|
struct btDbvtNode* m_node;
|
||||||
};
|
};
|
||||||
|
|
||||||
SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2)
|
SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2)
|
||||||
{
|
{
|
||||||
return ( c1.m_transform == c2.m_transform &&
|
return ( c1.m_transform == c2.m_transform &&
|
||||||
c1.m_childShape == c2.m_childShape &&
|
c1.m_childShape == c2.m_childShape &&
|
||||||
c1.m_childShapeType == c2.m_childShapeType &&
|
c1.m_childShapeType == c2.m_childShapeType &&
|
||||||
c1.m_childMargin == c2.m_childMargin );
|
c1.m_childMargin == c2.m_childMargin );
|
||||||
}
|
}
|
||||||
|
|
||||||
/// btCompoundShape allows to store multiple other btCollisionShapes
|
/// btCompoundShape allows to store multiple other btCollisionShapes
|
||||||
@@ -55,7 +56,8 @@ ATTRIBUTE_ALIGNED16(class) btCompoundShape : public btCollisionShape
|
|||||||
btVector3 m_localAabbMin;
|
btVector3 m_localAabbMin;
|
||||||
btVector3 m_localAabbMax;
|
btVector3 m_localAabbMax;
|
||||||
|
|
||||||
btOptimizedBvh* m_aabbTree;
|
//btOptimizedBvh* m_aabbTree;
|
||||||
|
btDbvt* m_dynamicAabbTree;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
@@ -66,10 +68,10 @@ public:
|
|||||||
|
|
||||||
void addChildShape(const btTransform& localTransform,btCollisionShape* shape);
|
void addChildShape(const btTransform& localTransform,btCollisionShape* shape);
|
||||||
|
|
||||||
/** Remove all children shapes that contain the specified shape. */
|
/// Remove all children shapes that contain the specified shape
|
||||||
virtual void removeChildShape(btCollisionShape* shape);
|
virtual void removeChildShape(btCollisionShape* shape);
|
||||||
|
|
||||||
|
void removeChildShapeByIndex(int childShapeindex);
|
||||||
|
|
||||||
|
|
||||||
int getNumChildShapes() const
|
int getNumChildShapes() const
|
||||||
@@ -104,8 +106,8 @@ public:
|
|||||||
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||||
|
|
||||||
/** Re-calculate the local Aabb. Is called at the end of removeChildShapes.
|
/** Re-calculate the local Aabb. Is called at the end of removeChildShapes.
|
||||||
Use this yourself if you modify the children or their transforms. */
|
Use this yourself if you modify the children or their transforms. */
|
||||||
virtual void recalculateLocalAabb();
|
virtual void recalculateLocalAabb();
|
||||||
|
|
||||||
virtual void setLocalScaling(const btVector3& scaling)
|
virtual void setLocalScaling(const btVector3& scaling)
|
||||||
@@ -137,9 +139,9 @@ public:
|
|||||||
//this is optional, but should make collision queries faster, by culling non-overlapping nodes
|
//this is optional, but should make collision queries faster, by culling non-overlapping nodes
|
||||||
void createAabbTreeFromChildren();
|
void createAabbTreeFromChildren();
|
||||||
|
|
||||||
const btOptimizedBvh* getAabbTree() const
|
btDbvt* getDynamicAabbTree()
|
||||||
{
|
{
|
||||||
return m_aabbTree;
|
return m_dynamicAabbTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
|
///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
#include "LinearMath/btPoint3.h"
|
#include "LinearMath/btPoint3.h"
|
||||||
#include "LinearMath/btMatrix3x3.h"
|
#include "LinearMath/btMatrix3x3.h"
|
||||||
|
#include "LinearMath/btAabbUtil2.h"
|
||||||
#include "btConvexInternalShape.h"
|
#include "btConvexInternalShape.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -46,28 +47,7 @@ public:
|
|||||||
|
|
||||||
//lazy evaluation of local aabb
|
//lazy evaluation of local aabb
|
||||||
btAssert(m_isLocalAabbValid);
|
btAssert(m_isLocalAabbValid);
|
||||||
|
btTransformAabb(m_localAabbMin,m_localAabbMax,margin,trans,aabbMin,aabbMax);
|
||||||
btAssert(m_localAabbMin.getX() <= m_localAabbMax.getX());
|
|
||||||
btAssert(m_localAabbMin.getY() <= m_localAabbMax.getY());
|
|
||||||
btAssert(m_localAabbMin.getZ() <= m_localAabbMax.getZ());
|
|
||||||
|
|
||||||
|
|
||||||
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
|
|
||||||
localHalfExtents+= btVector3(margin,margin,margin);
|
|
||||||
btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
|
|
||||||
|
|
||||||
btMatrix3x3 abs_b = trans.getBasis().absolute();
|
|
||||||
|
|
||||||
btPoint3 center = trans(localCenter);
|
|
||||||
|
|
||||||
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
|
|
||||||
abs_b[1].dot(localHalfExtents),
|
|
||||||
abs_b[2].dot(localHalfExtents));
|
|
||||||
|
|
||||||
aabbMin = center-extent;
|
|
||||||
aabbMax = center+extent;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ subject to the following restrictions:
|
|||||||
#ifndef AABB_UTIL2
|
#ifndef AABB_UTIL2
|
||||||
#define AABB_UTIL2
|
#define AABB_UTIL2
|
||||||
|
|
||||||
|
#include "btTransform.h"
|
||||||
#include "btVector3.h"
|
#include "btVector3.h"
|
||||||
#include "btMinMax.h"
|
#include "btMinMax.h"
|
||||||
|
|
||||||
@@ -163,6 +164,38 @@ SIMD_FORCE_INLINE bool btRayAabb(const btVector3& rayFrom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SIMD_FORCE_INLINE void btTransformAabb(const btVector3& halfExtents, btScalar margin,const btTransform& t,btVector3& aabbMinOut,btVector3& aabbMaxOut)
|
||||||
|
{
|
||||||
|
btVector3 halfExtentsWithMargin = halfExtents+btVector3(margin,margin,margin);
|
||||||
|
btMatrix3x3 abs_b = t.getBasis().absolute();
|
||||||
|
btVector3 center = t.getOrigin();
|
||||||
|
btVector3 extent = btVector3(abs_b[0].dot(halfExtentsWithMargin),
|
||||||
|
abs_b[1].dot(halfExtentsWithMargin),
|
||||||
|
abs_b[2].dot(halfExtentsWithMargin));
|
||||||
|
aabbMinOut = center - extent;
|
||||||
|
aabbMaxOut = center + extent;
|
||||||
|
};
|
||||||
|
|
||||||
|
SIMD_FORCE_INLINE void btTransformAabb(const btVector3& localAabbMin,const btVector3& localAabbMax, btScalar margin,const btTransform& trans,btVector3& aabbMinOut,btVector3& aabbMaxOut)
|
||||||
|
{
|
||||||
|
btAssert(localAabbMin.getX() <= localAabbMax.getX());
|
||||||
|
btAssert(localAabbMin.getY() <= localAabbMax.getY());
|
||||||
|
btAssert(localAabbMin.getZ() <= localAabbMax.getZ());
|
||||||
|
btVector3 localHalfExtents = btScalar(0.5)*(localAabbMax-localAabbMin);
|
||||||
|
localHalfExtents+=btVector3(margin,margin,margin);
|
||||||
|
|
||||||
|
btVector3 localCenter = btScalar(0.5)*(localAabbMax+localAabbMin);
|
||||||
|
btMatrix3x3 abs_b = trans.getBasis().absolute();
|
||||||
|
btVector3 center = trans(localCenter);
|
||||||
|
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
|
||||||
|
abs_b[1].dot(localHalfExtents),
|
||||||
|
abs_b[2].dot(localHalfExtents));
|
||||||
|
aabbMinOut = center-extent;
|
||||||
|
aabbMaxOut = center+extent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user