Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2007-07-06 07:12:31 +0400
committerErwin Coumans <blender@erwincoumans.com>2007-07-06 07:12:31 +0400
commit376be529bb932f867b01466592c33899ee5ec2c8 (patch)
treee89c72da658f04ed4aa816ada6adabfb5d938b74 /extern/bullet2/src/BulletDynamics/Dynamics
parentcff039bc58fe2ed54d4dad0828f5dede0b26a206 (diff)
synchronized to latest version of Bullet. added btConeTwistConstraint (useful for ragdolls etc)
Diffstat (limited to 'extern/bullet2/src/BulletDynamics/Dynamics')
-rw-r--r--extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp124
-rw-r--r--extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h5
-rw-r--r--extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h2
-rw-r--r--extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp34
-rw-r--r--extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h11
5 files changed, 154 insertions, 22 deletions
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
index f80a0826fbf..29719ec9a3e 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
@@ -30,15 +30,17 @@ subject to the following restrictions:
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
//for debug rendering
-#include "BulletCollision/CollisionShapes/btCompoundShape.h"
-#include "BulletCollision/CollisionShapes/btSphereShape.h"
#include "BulletCollision/CollisionShapes/btBoxShape.h"
-#include "BulletCollision/CollisionShapes/btCylinderShape.h"
+#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
+#include "BulletCollision/CollisionShapes/btCompoundShape.h"
#include "BulletCollision/CollisionShapes/btConeShape.h"
-#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
-#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btCylinderShape.h"
+#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
+#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
+#include "BulletCollision/CollisionShapes/btSphereShape.h"
#include "BulletCollision/CollisionShapes/btTriangleCallback.h"
+#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
#include "LinearMath/btIDebugDraw.h"
@@ -325,6 +327,19 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
}
}
+void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short mask)
+{
+ if (!body->isStaticOrKinematicObject())
+ {
+ body->setGravity(m_gravity);
+ }
+
+ if (body->getCollisionShape())
+ {
+ addCollisionObject(body,group,mask);
+ }
+}
+
void btDiscreteDynamicsWorld::updateVehicles(btScalar timeStep)
{
@@ -370,14 +385,21 @@ void btDiscreteDynamicsWorld::updateActivationState(btScalar timeStep)
END_PROFILE("updateActivationState");
}
-void btDiscreteDynamicsWorld::addConstraint(btTypedConstraint* constraint)
+void btDiscreteDynamicsWorld::addConstraint(btTypedConstraint* constraint,bool disableCollisionsBetweenLinkedBodies)
{
m_constraints.push_back(constraint);
+ if (disableCollisionsBetweenLinkedBodies)
+ {
+ constraint->getRigidBodyA().addConstraintRef(constraint);
+ constraint->getRigidBodyB().addConstraintRef(constraint);
+ }
}
void btDiscreteDynamicsWorld::removeConstraint(btTypedConstraint* constraint)
{
m_constraints.remove(constraint);
+ constraint->getRigidBodyA().removeConstraintRef(constraint);
+ constraint->getRigidBodyB().removeConstraintRef(constraint);
}
void btDiscreteDynamicsWorld::addVehicle(btRaycastVehicle* vehicle)
@@ -726,10 +748,42 @@ public:
}
};
-
+void btDiscreteDynamicsWorld::debugDrawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
+{
+ btVector3 start = transform.getOrigin();
+
+ const btVector3 xoffs = transform.getBasis() * btVector3(radius,0,0);
+ const btVector3 yoffs = transform.getBasis() * btVector3(0,radius,0);
+ const btVector3 zoffs = transform.getBasis() * btVector3(0,0,radius);
+
+ // XY
+ getDebugDrawer()->drawLine(start-xoffs, start+yoffs, color);
+ getDebugDrawer()->drawLine(start+yoffs, start+xoffs, color);
+ getDebugDrawer()->drawLine(start+xoffs, start-yoffs, color);
+ getDebugDrawer()->drawLine(start-yoffs, start-xoffs, color);
+
+ // XZ
+ getDebugDrawer()->drawLine(start-xoffs, start+zoffs, color);
+ getDebugDrawer()->drawLine(start+zoffs, start+xoffs, color);
+ getDebugDrawer()->drawLine(start+xoffs, start-zoffs, color);
+ getDebugDrawer()->drawLine(start-zoffs, start-xoffs, color);
+
+ // YZ
+ getDebugDrawer()->drawLine(start-yoffs, start+zoffs, color);
+ getDebugDrawer()->drawLine(start+zoffs, start+yoffs, color);
+ getDebugDrawer()->drawLine(start+yoffs, start-zoffs, color);
+ getDebugDrawer()->drawLine(start-zoffs, start-yoffs, color);
+}
void btDiscreteDynamicsWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)
{
+ // Draw a small simplex at the center of the object
+ {
+ btVector3 start = worldTransform.getOrigin();
+ getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(1,0,0), btVector3(1,0,0));
+ getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(0,1,0), btVector3(0,1,0));
+ getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(0,0,1), btVector3(0,0,1));
+ }
if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
{
@@ -750,14 +804,52 @@ void btDiscreteDynamicsWorld::debugDrawObject(const btTransform& worldTransform,
{
const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
- btVector3 start = worldTransform.getOrigin();
- getDebugDrawer()->drawLine(start,start+worldTransform.getBasis() * btVector3(radius,0,0),color);
- getDebugDrawer()->drawLine(start,start+worldTransform.getBasis() * btVector3(0,radius,0),color);
- getDebugDrawer()->drawLine(start,start+worldTransform.getBasis() * btVector3(0,0,radius),color);
- //drawSphere
+
+ debugDrawSphere(radius, worldTransform, color);
break;
}
case MULTI_SPHERE_SHAPE_PROXYTYPE:
+ {
+ const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);
+
+ for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)
+ {
+ btTransform childTransform = worldTransform;
+ childTransform.getOrigin() += multiSphereShape->getSpherePosition(i);
+ debugDrawSphere(multiSphereShape->getSphereRadius(i), childTransform, color);
+ }
+
+ break;
+ }
+ case CAPSULE_SHAPE_PROXYTYPE:
+ {
+ const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);
+
+ btScalar radius = capsuleShape->getRadius();
+ btScalar halfHeight = capsuleShape->getHalfHeight();
+
+ // Draw the ends
+ {
+ btTransform childTransform = worldTransform;
+ childTransform.getOrigin() = worldTransform * btVector3(0,halfHeight,0);
+ debugDrawSphere(radius, childTransform, color);
+ }
+
+ {
+ btTransform childTransform = worldTransform;
+ childTransform.getOrigin() = worldTransform * btVector3(0,-halfHeight,0);
+ debugDrawSphere(radius, childTransform, color);
+ }
+
+ // Draw some additional lines
+ btVector3 start = worldTransform.getOrigin();
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(-radius,halfHeight,0),start+worldTransform.getBasis() * btVector3(-radius,-halfHeight,0), color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(radius,halfHeight,0),start+worldTransform.getBasis() * btVector3(radius,-halfHeight,0), color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(0,halfHeight,-radius),start+worldTransform.getBasis() * btVector3(0,-halfHeight,-radius), color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(0,halfHeight,radius),start+worldTransform.getBasis() * btVector3(0,-halfHeight,radius), color);
+
+ break;
+ }
case CONE_SHAPE_PROXYTYPE:
{
const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
@@ -789,12 +881,10 @@ void btDiscreteDynamicsWorld::debugDrawObject(const btTransform& worldTransform,
default:
{
- if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
+ if (shape->isConcave())
{
- btTriangleMeshShape* concaveMesh = (btTriangleMeshShape*) shape;
- //btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
- //btVector3 aabbMax(100,100,100);//btScalar(1e30),btScalar(1e30),btScalar(1e30));
-
+ btConcaveShape* concaveMesh = (btConcaveShape*) shape;
+
//todo pass camera, for some culling
btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
index 7ffa2c07ee6..83b90bfeebc 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
@@ -80,6 +80,7 @@ protected:
void saveKinematicState(btScalar timeStep);
+ void debugDrawSphere(btScalar radius, const btTransform& transform, const btVector3& color);
public:
@@ -94,7 +95,7 @@ public:
virtual void updateAabbs();
- void addConstraint(btTypedConstraint* constraint);
+ void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
void removeConstraint(btTypedConstraint* constraint);
@@ -131,6 +132,8 @@ public:
virtual void addRigidBody(btRigidBody* body);
+ virtual void addRigidBody(btRigidBody* body, short group, short mask);
+
virtual void removeRigidBody(btRigidBody* body);
void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color);
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h
index d3ea7db8e5c..65b63fad4b5 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h
@@ -43,7 +43,7 @@ class btDynamicsWorld : public btCollisionWorld
virtual void updateAabbs() = 0;
- virtual void addConstraint(btTypedConstraint* constraint) { (void)constraint;};
+ virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false) { (void)constraint;};
virtual void removeConstraint(btTypedConstraint* constraint) {(void)constraint;};
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp
index dbf73b85bcf..3dae930a49f 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp
@@ -16,8 +16,9 @@ subject to the following restrictions:
#include "btRigidBody.h"
#include "BulletCollision/CollisionShapes/btConvexShape.h"
#include "LinearMath/btMinMax.h"
-#include <LinearMath/btTransformUtil.h>
-#include <LinearMath/btMotionState.h>
+#include "LinearMath/btTransformUtil.h"
+#include "LinearMath/btMotionState.h"
+#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
btScalar gLinearAirDamping = btScalar(1.);
//'temporarily' global variables
@@ -305,4 +306,33 @@ void btRigidBody::setCenterOfMassTransform(const btTransform& xform)
}
+bool btRigidBody::checkCollideWithOverride(btCollisionObject* co)
+{
+ btRigidBody* otherRb = btRigidBody::upcast(co);
+ if (!otherRb)
+ return true;
+
+ for (int i = 0; i < m_constraintRefs.size(); ++i)
+ {
+ btTypedConstraint* c = m_constraintRefs[i];
+ if (&c->getRigidBodyA() == otherRb || &c->getRigidBodyB() == otherRb)
+ return false;
+ }
+
+ return true;
+}
+void btRigidBody::addConstraintRef(btTypedConstraint* c)
+{
+ int index = m_constraintRefs.findLinearSearch(c);
+ if (index == m_constraintRefs.size())
+ m_constraintRefs.push_back(c);
+
+ m_checkCollideWith = true;
+}
+
+void btRigidBody::removeConstraintRef(btTypedConstraint* c)
+{
+ m_constraintRefs.remove(c);
+ m_checkCollideWith = m_constraintRefs.size() > 0;
+} \ No newline at end of file
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
index 9da545adb68..0707595d48e 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
@@ -16,6 +16,7 @@ subject to the following restrictions:
#ifndef RIGIDBODY_H
#define RIGIDBODY_H
+#include "../../LinearMath/btAlignedObjectArray.h"
#include "../../LinearMath/btPoint3.h"
#include "../../LinearMath/btTransform.h"
#include "../../BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -23,7 +24,7 @@ subject to the following restrictions:
class btCollisionShape;
class btMotionState;
-
+class btTypedConstraint;
extern btScalar gLinearAirDamping;
@@ -57,6 +58,9 @@ class btRigidBody : public btCollisionObject
//m_optionalMotionState allows to automatic synchronize the world transform for active objects
btMotionState* m_optionalMotionState;
+ //keep track of typed constraints referencing this rigid body
+ btAlignedObjectArray<btTypedConstraint*> m_constraintRefs;
+
public:
#ifdef OBSOLETE_MOTIONSTATE_LESS
@@ -339,6 +343,11 @@ public:
return (getBroadphaseProxy() != 0);
}
+ virtual bool checkCollideWithOverride(btCollisionObject* co);
+
+ void addConstraintRef(btTypedConstraint* c);
+ void removeConstraintRef(btTypedConstraint* c);
+
int m_debugBodyId;
};