BulletSim: add calls for creating all the different Bullet constraint types.

Updated the DLLs and SOs and code for BulletXNA to create the types.
All the detailed control calls are not all in place yet.
user_profiles
Robert Adams 2013-02-17 20:07:04 -08:00
parent 885b45b112
commit 1d7276235a
9 changed files with 338 additions and 47 deletions

View File

@ -438,6 +438,28 @@ public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world,
joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
}
public override BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1,
Vector3 frameInBloc, Quaternion frameInBrot,
bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies)
{
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintFixed2(worldu.ptr, bodyu1.ptr,
frameInBloc, frameInBrot, useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies));
}
public override BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frame1loc, Quaternion frame1rot,
Vector3 frame2loc, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.Create6DofSpringConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
}
public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 pivotinA, Vector3 pivotinB,
Vector3 axisInA, Vector3 axisInB,
@ -450,6 +472,52 @@ public override BulletConstraint CreateHingeConstraint(BulletWorld world, Bullet
pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
}
public override BulletConstraint CreateSliderConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frame1loc, Quaternion frame1rot,
Vector3 frame2loc, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.CreateSliderConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
}
public override BulletConstraint CreateConeTwistConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frame1loc, Quaternion frame1rot,
Vector3 frame2loc, Quaternion frame2rot,
bool disableCollisionsBetweenLinkedBodies)
{
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.CreateConeTwistConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
frame2loc, frame2rot, disableCollisionsBetweenLinkedBodies));
}
public override BulletConstraint CreateGearConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 axisInA, Vector3 axisInB,
float ratio, bool disableCollisionsBetweenLinkedBodies)
{
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.CreateGearConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, axisInA, axisInB,
ratio, disableCollisionsBetweenLinkedBodies));
}
public override BulletConstraint CreatePoint2PointConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 pivotInA, Vector3 pivotInB,
bool disableCollisionsBetweenLinkedBodies)
{
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.CreatePoint2PointConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, pivotInA, pivotInB,
disableCollisionsBetweenLinkedBodies));
}
public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
@ -1425,12 +1493,46 @@ public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr ob
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr Create6DofConstraintFixed2(IntPtr world, IntPtr obj1,
Vector3 frameInBloc, Quaternion frameInBrot,
bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr Create6DofSpringConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
Vector3 frame1loc, Quaternion frame1rot,
Vector3 frame2loc, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
Vector3 pivotinA, Vector3 pivotinB,
Vector3 axisInA, Vector3 axisInB,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateSliderConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
Vector3 frameInAloc, Quaternion frameInArot,
Vector3 frameInBloc, Quaternion frameInBrot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateConeTwistConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
Vector3 frameInAloc, Quaternion frameInArot,
Vector3 frameInBloc, Quaternion frameInBrot,
bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateGearConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
Vector3 axisInA, Vector3 axisInB,
float ratio, bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreatePoint2PointConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
Vector3 pivotInA, Vector3 pivotInB,
bool disableCollisionsBetweenLinkedBodies);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);

View File

@ -559,8 +559,9 @@ private sealed class BulletConstraintXNA : BulletConstraint
}
//BulletSimAPI.Create6DofConstraint(m_world.ptr, m_body1.ptr, m_body2.ptr,frame1, frame1rot,frame2, frame2rot,useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2,
Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot,
bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
{
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
@ -584,7 +585,24 @@ private sealed class BulletConstraintXNA : BulletConstraint
return new BulletConstraintXNA(consttr);
}
public override BulletConstraint Create6DofConstraintFixed(BulletWorld pWorld, BulletBody pBody1,
Vector3 pframe1, Quaternion pframe1rot,
bool pUseLinearReferenceFrameB, bool pdisableCollisionsBetweenLinkedBodies)
{
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody;
IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
frame1._origin = frame1v;
Generic6DofConstraint consttr = new Generic6DofConstraint(body1, ref frame1, pUseLinearReferenceFrameB);
consttr.CalculateTransforms();
world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies);
return new BulletConstraintXNA(consttr);
}
/// <summary>
///
/// </summary>
@ -1443,129 +1461,130 @@ private sealed class BulletConstraintXNA : BulletConstraint
public BSPhysicsShapeType BSShapeTypeFromBroadPhaseNativeType(BroadphaseNativeTypes pin)
{
BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
switch (pin)
{
case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_BOX;
ret = BSPhysicsShapeType.SHAPE_BOX;
break;
case BroadphaseNativeTypes.TRIANGLE_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.TETRAHEDRAL_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_MESH;
ret = BSPhysicsShapeType.SHAPE_MESH;
break;
case BroadphaseNativeTypes.CONVEX_HULL_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_HULL;
ret = BSPhysicsShapeType.SHAPE_HULL;
break;
case BroadphaseNativeTypes.CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.CUSTOM_POLYHEDRAL_SHAPE_TYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
//implicit convex shapes
case BroadphaseNativeTypes.IMPLICIT_CONVEX_SHAPES_START_HERE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_SPHERE;
ret = BSPhysicsShapeType.SHAPE_SPHERE;
break;
case BroadphaseNativeTypes.MULTI_SPHERE_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.CAPSULE_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_CAPSULE;
ret = BSPhysicsShapeType.SHAPE_CAPSULE;
break;
case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_CONE;
ret = BSPhysicsShapeType.SHAPE_CONE;
break;
case BroadphaseNativeTypes.CONVEX_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_CYLINDER;
ret = BSPhysicsShapeType.SHAPE_CYLINDER;
break;
case BroadphaseNativeTypes.UNIFORM_SCALING_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.MINKOWSKI_SUM_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.BOX_2D_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.CONVEX_2D_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.CUSTOM_CONVEX_SHAPE_TYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
//concave shape
case BroadphaseNativeTypes.CONCAVE_SHAPES_START_HERE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
//keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
case BroadphaseNativeTypes.TRIANGLE_MESH_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_MESH;
ret = BSPhysicsShapeType.SHAPE_MESH;
break;
case BroadphaseNativeTypes.SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_MESH;
ret = BSPhysicsShapeType.SHAPE_MESH;
break;
///used for demo integration FAST/Swift collision library and Bullet
case BroadphaseNativeTypes.FAST_CONCAVE_MESH_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_MESH;
ret = BSPhysicsShapeType.SHAPE_MESH;
break;
//terrain
case BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_HEIGHTMAP;
ret = BSPhysicsShapeType.SHAPE_HEIGHTMAP;
break;
///Used for GIMPACT Trimesh integration
case BroadphaseNativeTypes.GIMPACT_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_MESH;
ret = BSPhysicsShapeType.SHAPE_MESH;
break;
///Multimaterial mesh
case BroadphaseNativeTypes.MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_MESH;
ret = BSPhysicsShapeType.SHAPE_MESH;
break;
case BroadphaseNativeTypes.EMPTY_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_GROUNDPLANE;
ret = BSPhysicsShapeType.SHAPE_GROUNDPLANE;
break;
case BroadphaseNativeTypes.CUSTOM_CONCAVE_SHAPE_TYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.CONCAVE_SHAPES_END_HERE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.COMPOUND_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_COMPOUND;
ret = BSPhysicsShapeType.SHAPE_COMPOUND;
break;
case BroadphaseNativeTypes.SOFTBODY_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_MESH;
ret = BSPhysicsShapeType.SHAPE_MESH;
break;
case BroadphaseNativeTypes.HFFLUID_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
case BroadphaseNativeTypes.INVALID_SHAPE_PROXYTYPE:
return BSPhysicsShapeType.SHAPE_UNKNOWN;
ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
break;
}
return BSPhysicsShapeType.SHAPE_UNKNOWN;
return ret;
}
public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) { /* TODO */ }
@ -1579,7 +1598,39 @@ private sealed class BulletConstraintXNA : BulletConstraint
return new BulletShapeXNA(m_planeshape, BSPhysicsShapeType.SHAPE_GROUNDPLANE);
}
public override BulletConstraint CreateHingeConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
public override BulletConstraint Create6DofSpringConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2,
Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot,
bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
{
Generic6DofSpringConstraint constrain = null;
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody;
RigidBody body2 = (pBody2 as BulletBodyXNA).rigidBody;
if (body1 != null && body2 != null)
{
IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
frame1._origin = frame1v;
IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
frame2._origin = frame1v;
constrain = new Generic6DofSpringConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA);
world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
constrain.CalculateTransforms();
}
return new BulletConstraintXNA(constrain);
}
public override BulletConstraint CreateHingeConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2,
Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB,
bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
{
HingeConstraint constrain = null;
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
@ -1591,6 +1642,100 @@ private sealed class BulletConstraintXNA : BulletConstraint
IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z);
IndexedVector3 axisInA = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z);
IndexedVector3 axisInB = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z);
constrain = new HingeConstraint(rb1, rb2, ref pivotInA, ref pivotInB, ref axisInA, ref axisInB, puseLinearReferenceFrameA);
world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
}
return new BulletConstraintXNA(constrain);
}
public override BulletConstraint CreateSliderConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2,
Vector3 pframe1, Quaternion pframe1rot,
Vector3 pframe2, Quaternion pframe2rot,
bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
{
SliderConstraint constrain = null;
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
RigidBody rb1 = (pBody1 as BulletBodyXNA).rigidBody;
RigidBody rb2 = (pBody2 as BulletBodyXNA).rigidBody;
if (rb1 != null && rb2 != null)
{
IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
frame1._origin = frame1v;
IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
frame2._origin = frame1v;
constrain = new SliderConstraint(rb1, rb2, ref frame1, ref frame2, puseLinearReferenceFrameA);
world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
}
return new BulletConstraintXNA(constrain);
}
public override BulletConstraint CreateConeTwistConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2,
Vector3 pframe1, Quaternion pframe1rot,
Vector3 pframe2, Quaternion pframe2rot,
bool pdisableCollisionsBetweenLinkedBodies)
{
ConeTwistConstraint constrain = null;
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
RigidBody rb1 = (pBody1 as BulletBodyXNA).rigidBody;
RigidBody rb2 = (pBody2 as BulletBodyXNA).rigidBody;
if (rb1 != null && rb2 != null)
{
IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
frame1._origin = frame1v;
IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
frame2._origin = frame1v;
constrain = new ConeTwistConstraint(rb1, rb2, ref frame1, ref frame2);
world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
}
return new BulletConstraintXNA(constrain);
}
public override BulletConstraint CreateGearConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2,
Vector3 paxisInA, Vector3 paxisInB,
float pratio, bool pdisableCollisionsBetweenLinkedBodies)
{
Generic6DofConstraint constrain = null;
/* BulletXNA does not have a gear constraint
GearConstraint constrain = null;
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
RigidBody rb1 = (pBody1 as BulletBodyXNA).rigidBody;
RigidBody rb2 = (pBody2 as BulletBodyXNA).rigidBody;
if (rb1 != null && rb2 != null)
{
IndexedVector3 axis1 = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z);
IndexedVector3 axis2 = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z);
constrain = new GearConstraint(rb1, rb2, ref axis1, ref axis2, pratio);
world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
}
*/
return new BulletConstraintXNA(constrain);
}
public override BulletConstraint CreatePoint2PointConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2,
Vector3 ppivotInA, Vector3 ppivotInB,
bool pdisableCollisionsBetweenLinkedBodies)
{
Point2PointConstraint constrain = null;
DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
RigidBody rb1 = (pBody1 as BulletBodyXNA).rigidBody;
RigidBody rb2 = (pBody2 as BulletBodyXNA).rigidBody;
if (rb1 != null && rb2 != null)
{
IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z);
IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z);
constrain = new Point2PointConstraint(rb1, rb2, ref pivotInA, ref pivotInB);
world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
}
return new BulletConstraintXNA(constrain);

View File

@ -365,11 +365,38 @@ public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world,
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
public abstract BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1,
Vector3 frameInBloc, Quaternion frameInBrot,
bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies);
public abstract BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frame1loc, Quaternion frame1rot,
Vector3 frame2loc, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 pivotinA, Vector3 pivotinB,
Vector3 axisInA, Vector3 axisInB,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
public abstract BulletConstraint CreateSliderConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frameInAloc, Quaternion frameInArot,
Vector3 frameInBloc, Quaternion frameInBrot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
public abstract BulletConstraint CreateConeTwistConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frameInAloc, Quaternion frameInArot,
Vector3 frameInBloc, Quaternion frameInBrot,
bool disableCollisionsBetweenLinkedBodies);
public abstract BulletConstraint CreateGearConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 axisInA, Vector3 axisInB,
float ratio, bool disableCollisionsBetweenLinkedBodies);
public abstract BulletConstraint CreatePoint2PointConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 pivotInA, Vector3 pivotInB,
bool disableCollisionsBetweenLinkedBodies);
public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);

View File

@ -57,6 +57,7 @@ public sealed class BSConstraint6Dof : BSConstraint
obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
}
// 6 Dof constraint based on a midpoint between the two constrained bodies
public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
@ -94,6 +95,21 @@ public sealed class BSConstraint6Dof : BSConstraint
}
}
// A 6 Dof constraint that is fixed in the world and constrained to a on-the-fly created static object
public BSConstraint6Dof(BulletWorld world, BulletBody obj1, Vector3 frameInBloc, Quaternion frameInBrot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
: base(world)
{
m_body1 = obj1;
m_body2 = obj1; // Look out for confusion down the road
m_constraint = PhysicsScene.PE.Create6DofConstraintFixed(m_world, m_body1,
frameInBloc, frameInBrot,
useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
m_enabled = true;
world.physicsScene.DetailLog("{0},BS6DofConstraint,createFixed,wID={1},rID={2},rBody={3}",
BSScene.DetailLogZero, world.worldID, obj1.ID, obj1.AddrString);
}
public bool SetFrames(Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot)
{
bool ret = false;

View File

@ -117,8 +117,7 @@ public sealed class BSConstraintCollection : IDisposable
if (this.TryGetConstraint(body1, body2, out constrain))
{
// remove the constraint from our collection
RemoveAndDestroyConstraint(constrain);
ret = true;
ret = RemoveAndDestroyConstraint(constrain);
}
}
@ -126,17 +125,19 @@ public sealed class BSConstraintCollection : IDisposable
}
// The constraint MUST exist in the collection
// Could be called if the constraint was previously removed.
// Return 'true' if the constraint was actually removed and disposed.
public bool RemoveAndDestroyConstraint(BSConstraint constrain)
{
bool removed = false;
lock (m_constraints)
{
// remove the constraint from our collection
m_constraints.Remove(constrain);
removed = m_constraints.Remove(constrain);
}
// tell the engine that all its structures need to be freed
// Dispose() is safe to call multiple times
constrain.Dispose();
// we destroyed something
return true;
return removed;
}
// Remove all constraints that reference the passed body.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.