Add support for b3Generic6DofConstraint in Bullet, CPU only for now. Also the b3GpuDynamicsWorld supports conversion of this constraint.
This means, picking works both with and without holding SHIFT (rayTest is only implemented for spheres)
This commit is contained in:
@@ -10,12 +10,14 @@
|
||||
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"
|
||||
#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "Bullet3OpenCL/BroadphaseCollision/b3GpuSapBroadphase.h"
|
||||
#include "Bullet3OpenCL/RigidBody/b3GpuNarrowPhase.h"
|
||||
#include "Bullet3OpenCL/RigidBody/b3GpuRigidBodyPipeline.h"
|
||||
#include "Bullet3Dynamics/ConstraintSolver/b3Point2PointConstraint.h"
|
||||
#include "Bullet3Dynamics/ConstraintSolver/b3Generic6DofConstraint.h"
|
||||
|
||||
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
@@ -68,6 +70,8 @@ int b3GpuDynamicsWorld::stepSimulation( btScalar timeStepUnused, int maxSubStep
|
||||
BT_PROFILE("stepSimulation");
|
||||
|
||||
{
|
||||
BT_PROFILE("sync constraints CPU");
|
||||
//todo: determine what data has changed, or perform copy on GPU?
|
||||
for (int i=0;i<m_constraints.size();i++)
|
||||
{
|
||||
btTypedConstraint* constraint = m_constraints[i];
|
||||
@@ -88,6 +92,19 @@ int b3GpuDynamicsWorld::stepSimulation( btScalar timeStepUnused, int maxSubStep
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
case D6_CONSTRAINT_TYPE:
|
||||
{
|
||||
btGeneric6DofConstraint* dof2 = (btGeneric6DofConstraint*) constraint;
|
||||
b3Generic6DofConstraint* dof3 = (b3Generic6DofConstraint*) c;
|
||||
const b3RigidBodyCL* bodiesCL = m_np->getBodiesCpu();
|
||||
|
||||
b3Transform frameInA = (b3Transform&) dof2->getFrameOffsetA();
|
||||
b3Transform frameInB = (b3Transform&) dof2->getFrameOffsetB();
|
||||
dof3->setFrames(frameInA,frameInB,bodiesCL);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
}
|
||||
@@ -572,19 +589,14 @@ void b3GpuDynamicsWorld::addConstraint(btTypedConstraint* constraint, bool disab
|
||||
case POINT2POINT_CONSTRAINT_TYPE:
|
||||
{
|
||||
btPoint2PointConstraint* p = (btPoint2PointConstraint*) constraint;
|
||||
|
||||
int rbA = p->getRigidBodyA().getUserIndex();
|
||||
int rbB = p->getRigidBodyB().getUserIndex();
|
||||
|
||||
btVector3 pivotInB = p->getPivotInB();
|
||||
|
||||
if (rbB<=0)
|
||||
{
|
||||
|
||||
pivotInB = p->getRigidBodyA().getWorldTransform()*p->getPivotInA();
|
||||
rbB = m_staticBody->getUserIndex();
|
||||
}
|
||||
|
||||
if (rbA>=0 && rbB>=0)
|
||||
{
|
||||
b3Point2PointConstraint* p2p = new b3Point2PointConstraint(rbA,rbB, (const b3Vector3&)p->getPivotInA(),(const b3Vector3&)pivotInB);
|
||||
@@ -593,11 +605,67 @@ void b3GpuDynamicsWorld::addConstraint(btTypedConstraint* constraint, bool disab
|
||||
m_rigidBodyPipeline->addConstraint(p2p);
|
||||
} else
|
||||
{
|
||||
|
||||
b3Error("invalid body index in addConstraint.\n");
|
||||
b3Error("invalid body index in addConstraint,b3Point2PointConstraint\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case D6_CONSTRAINT_TYPE:
|
||||
{
|
||||
btGeneric6DofConstraint* dof2 = (btGeneric6DofConstraint*) constraint;
|
||||
const b3RigidBodyCL* bodiesCL = m_np->getBodiesCpu();
|
||||
|
||||
int rbA = dof2->getRigidBodyA().getUserIndex();
|
||||
int rbB = dof2->getRigidBodyB().getUserIndex();
|
||||
|
||||
btTransform frameInA = dof2->getFrameOffsetB();
|
||||
btTransform frameInB = dof2->getFrameOffsetB();
|
||||
|
||||
if (rbA<=0)
|
||||
{
|
||||
frameInA = dof2->getRigidBodyB().getWorldTransform()*dof2->getFrameOffsetB();
|
||||
rbA = m_staticBody->getUserIndex();
|
||||
}
|
||||
|
||||
if (rbB<=0)
|
||||
{
|
||||
frameInB = dof2->getRigidBodyA().getWorldTransform()*dof2->getFrameOffsetA();
|
||||
rbB = m_staticBody->getUserIndex();
|
||||
}
|
||||
if (rbA>=0 && rbB>=0)
|
||||
{
|
||||
b3Generic6DofConstraint* dof3 = new b3Generic6DofConstraint(rbA,rbB,(b3Transform&)frameInA,(b3Transform&)frameInB,false,bodiesCL);//(();//(rbA,rbB, (const b3Vector3&)p->getPivotInA(),(const b3Vector3&)pivotInB);
|
||||
{
|
||||
btVector3 limit(0,0,0);
|
||||
dof2->getLinearLowerLimit(limit);
|
||||
dof3->setLinearLowerLimit((const b3Vector3&)limit);
|
||||
|
||||
dof2->setLinearUpperLimit(limit);
|
||||
dof3->setLinearUpperLimit((const b3Vector3&)limit);
|
||||
|
||||
dof2->setAngularLowerLimit(limit);
|
||||
dof3->setAngularLowerLimit((const b3Vector3&)limit);
|
||||
|
||||
dof2->setAngularUpperLimit(limit);
|
||||
dof3->setAngularUpperLimit((const b3Vector3&)limit);
|
||||
/* for (int i=0;i<6;i++)
|
||||
{
|
||||
dof3->setParam(BT_CONSTRAINT_STOP_CFM,dof2->getParam(BT_CONSTRAINT_STOP_CFM,i),i);
|
||||
dof3->setParam(BT_CONSTRAINT_STOP_ERP,dof2->getParam(BT_CONSTRAINT_STOP_ERP,i),i);
|
||||
}
|
||||
*/
|
||||
dof3->setBreakingImpulseThreshold(dof2->getBreakingImpulseThreshold());
|
||||
}
|
||||
// p2p->setBreakingImpulseThreshold(p->getBreakingImpulseThreshold());
|
||||
constraint->setUserConstraintPtr(dof3);
|
||||
m_rigidBodyPipeline->addConstraint(dof3);
|
||||
} else
|
||||
{
|
||||
b3Error("invalid body index in addConstraint, btGeneric6DofConstraint.\n");
|
||||
}
|
||||
|
||||
// b3Generic6DofConstraint
|
||||
break;
|
||||
}
|
||||
default:
|
||||
b3Warning("Warning: b3GpuDynamicsWorld::addConstraint with unsupported constraint type\n");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user