Beispiel #1
0
    // Called to update/change the body and shape for an object.
    // The object has some shape and body on it. Here we decide if that is the correct shape
    //    for the current state of the object (static/dynamic/...).
    // If bodyCallback is not null, it is called if either the body or the shape are changed
    //    so dependencies (like constraints) can be removed before the physical object is dereferenced.
    // Return 'true' if either the body or the shape changed.
    // Called at taint-time.
    public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim, PhysicalDestructionCallback bodyCallback)
    {
        m_physicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape");

        bool ret = false;

        // This lock could probably be pushed down lower but building shouldn't take long
        lock (m_collectionActivityLock)
        {
            // Do we have the correct geometry for this type of object?
            // Updates prim.BSShape with information/pointers to shape.
            // Returns 'true' of BSShape is changed to a new shape.
            bool newGeom = CreateGeom(forceRebuild, prim, bodyCallback);
            // If we had to select a new shape geometry for the object,
            //    rebuild the body around it.
            // Updates prim.BSBody with information/pointers to requested body
            // Returns 'true' if BSBody was changed.
            bool newBody = CreateBody((newGeom || forceRebuild), prim, m_physicsScene.World, bodyCallback);
            ret = newGeom || newBody;
        }
        DetailLog("{0},BSShapeCollection.GetBodyAndShape,taintExit,force={1},ret={2},body={3},shape={4}",
                                prim.LocalID, forceRebuild, ret, prim.PhysBody, prim.PhysShape);

        return ret;
    }
 public BSConstraintHinge(BulletWorld world, BulletBody obj1, BulletBody obj2,
                 Vector3 pivotInA, Vector3 pivotInB,
                 Vector3 axisInA, Vector3 axisInB,
                 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
     : base(world)
 {
     m_body1 = obj1;
     m_body2 = obj2;
     m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2,
                             pivotInA, pivotInB, axisInA, axisInB,
                             useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
 }
 public BSConstraintConeTwist(BulletWorld world, BulletBody obj1, BulletBody obj2,
                 Vector3 frameInAloc, Quaternion frameInArot,
                 Vector3 frameInBloc, Quaternion frameInBrot,
                 bool disableCollisionsBetweenLinkedBodies)
     : base(world)
 {
     m_body1 = obj1;
     m_body2 = obj2;
     m_constraint = PhysicsScene.PE.CreateConeTwistConstraint(world, obj1, obj2,
                             frameInAloc, frameInArot, frameInBloc, frameInBrot,
                             disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
 }
 public BSConstraintSlider(BulletWorld world, BulletBody obj1, BulletBody obj2,
                 Vector3 frameInAloc, Quaternion frameInArot,
                 Vector3 frameInBloc, Quaternion frameInBrot,
                 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
     : base(world)
 {
     m_body1 = obj1;
     m_body2 = obj2;
     m_constraint = PhysicsScene.PE.CreateSliderConstraint(world, obj1, obj2,
                             frameInAloc, frameInArot, frameInBloc, frameInBrot,
                             useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
 }
    public BSConstraintSpring(BulletWorld world, BulletBody obj1, BulletBody obj2,
                    Vector3 frame1Loc, Quaternion frame1Rot,
                    Vector3 frame2Loc, Quaternion frame2Rot,
                    bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
        :base(world, obj1, obj2)
    {
        m_constraint = PhysicsScene.PE.Create6DofSpringConstraint(world, obj1, obj2,
                                frame1Loc, frame1Rot, frame2Loc, frame2Rot,
                                useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
        m_enabled = true;

        PhysicsScene.DetailLog("{0},BSConstraintSpring,create,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
                            obj1.ID, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
        PhysicsScene.DetailLog("{0},BSConstraintSpring,create,  f1Loc={1},f1Rot={2},f2Loc={3},f2Rot={4},usefA={5},disCol={6}",
                    m_body1.ID, frame1Loc, frame1Rot, frame2Loc, frame2Rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
    }
    // 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)
        : base(world)
    {
        m_body1 = obj1;
        m_body2 = obj2;
        if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody)
        {
            world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
                            BSScene.DetailLogZero, world.worldID,
                            obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
            world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
                            LogHeader, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
            m_enabled = false;
        }
        else
        {
            m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2,
                                    joinPoint,
                                    useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);

            PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}",
                                m_body1.ID, world.worldID, m_constraint.AddrString,
                                obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);

            if (!m_constraint.HasPhysicalConstraint)
            {
                world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}",
                                LogHeader, obj1.ID, obj2.ID);
                m_enabled = false;
            }
            else
            {
                m_enabled = true;
            }
        }
    }
Beispiel #7
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="pWorld"></param>
    /// <param name="pBody1"></param>
    /// <param name="pBody2"></param>
    /// <param name="pjoinPoint"></param>
    /// <param name="puseLinearReferenceFrameA"></param>
    /// <param name="pdisableCollisionsBetweenLinkedBodies"></param>
    /// <returns></returns>
    public override BulletConstraint Create6DofConstraintToPoint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
    {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody;
        RigidBody body2 = (pBody2 as BulletBodyXNA).rigidBody;
        IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
        IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));

        IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
        IndexedMatrix mat = IndexedMatrix.Identity;
        mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
        frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint;
        frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint;

        Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA);
        consttr.CalculateTransforms();
        world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies);

        return new BulletConstraintXNA(consttr);
    }
Beispiel #8
0
 public override bool DestroyConstraint(BulletWorld pWorld, BulletConstraint pConstraint)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain;
     world.RemoveConstraint(constraint);
     return true;
 }
Beispiel #9
0
    public override bool GetForceUpdateAllAabbs(BulletWorld pWorld) {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        return world.GetForceUpdateAllAabbs();

    }
Beispiel #10
0
 public override void UpdateSingleAabb(BulletWorld pWorld, BulletBody pCollisionObject)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
     world.UpdateSingleAabb(collisionObject);
 }
Beispiel #11
0
    public bool RayCastGround(BulletWorld pWorld, Vector3 _RayOrigin, float pRayHeight, BulletBody NotMe)
    {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        if (world != null)
        {
            if (NotMe is BulletBodyXNA && NotMe.HasPhysicalBody)
            {
                CollisionObject AvoidBody = (NotMe as BulletBodyXNA).body;

                IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z);
                IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight);
                using (
                    ClosestNotMeRayResultCallback rayCallback =
                                            new ClosestNotMeRayResultCallback(rOrigin, rEnd, AvoidBody)
                    )
                {
                    world.RayTest(ref rOrigin, ref rEnd, rayCallback);
                    if (rayCallback.HasHit())
                    {
                        IndexedVector3 hitLocation = rayCallback.m_hitPointWorld;
                    }
                    return rayCallback.HasHit();
                }
           }
        }
        return false;
    }
Beispiel #12
0
 private static EntityProperties GetDebugProperties(BulletWorld pWorld, BulletBody pCollisionObject)
 {
     EntityProperties ent = new EntityProperties();
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody;
     IndexedMatrix transform = collisionObject.GetWorldTransform();
     IndexedVector3 LinearVelocity = collisionObject.GetInterpolationLinearVelocity();
     IndexedVector3 AngularVelocity = collisionObject.GetInterpolationAngularVelocity();
     IndexedQuaternion rotation = transform.GetRotation();
     ent.Acceleration = Vector3.Zero;
     ent.ID = (uint)collisionObject.GetUserPointer();
     ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z);
     ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W);
     ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z);
     ent.RotationalVelocity = new Vector3(AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z);
     return ent;
 }
Beispiel #13
0
 private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep,
                 out int updatedEntityCount, out EntityProperties[] updatedEntities,
                 out int collidersCount, out CollisionDesc[] colliders)
 {
     int epic = PhysicsStepint(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities,
                             out collidersCount, out colliders, m_maxCollisions, m_maxUpdatesPerFrame);
     return epic;
 }
Beispiel #14
0
    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 BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2) : base(world)
 {
     m_body1   = obj1;
     m_body2   = obj2;
     m_enabled = false;
 }
Beispiel #16
0
 public BSConstraint(BulletWorld world)
 {
     m_world      = world;
     PhysicsScene = m_world.physicsScene;
 }
Beispiel #17
0
    public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
                        out int updatedEntityCount, out int collidersCount)
    {
        /* TODO */
        updatedEntityCount = 0;
        collidersCount = 0;


        int ret = PhysicsStep2(world,timeStep,maxSubSteps,fixedTimeStep,out updatedEntityCount,out world.physicsScene.m_updateArray, out collidersCount, out world.physicsScene.m_collisionArray);

        return ret;
    }
Beispiel #18
0
 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);
 }
Beispiel #19
0
    private int PhysicsStepint(BulletWorld pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount,
        out  EntityProperties[] updatedEntities, out int collidersCount, out CollisionDesc[] colliders, int maxCollisions, int maxUpdates)
    {
        int numSimSteps = 0;
        Array.Clear(UpdatedObjects, 0, UpdatedObjects.Length);
        Array.Clear(UpdatedCollisions, 0, UpdatedCollisions.Length);
        LastEntityProperty=0;






        LastCollisionDesc=0;

        updatedEntityCount = 0;
        collidersCount = 0;


        if (pWorld is BulletWorldXNA)
        {
            DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;

            world.LastCollisionDesc = 0;
            world.LastEntityProperty = 0;
            numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep);

            PersistentManifold contactManifold;
            CollisionObject objA;
            CollisionObject objB;
            ManifoldPoint manifoldPoint;
            PairCachingGhostObject pairCachingGhostObject;

            m_collisionsThisFrame = 0;
            int numManifolds = world.GetDispatcher().GetNumManifolds();
            for (int j = 0; j < numManifolds; j++)
            {
                contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j);
                int numContacts = contactManifold.GetNumContacts();
                if (numContacts == 0)
                    continue;

                objA = contactManifold.GetBody0() as CollisionObject;
                objB = contactManifold.GetBody1() as CollisionObject;

                manifoldPoint = contactManifold.GetContactPoint(0);
                //IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB();
               // IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A

                RecordCollision(this, objA, objB, manifoldPoint.GetPositionWorldOnB(), -manifoldPoint.m_normalWorldOnB, manifoldPoint.GetDistance());
                m_collisionsThisFrame ++;
                if (m_collisionsThisFrame >= 9999999)
                    break;


            }

            foreach (GhostObject ghostObject in specialCollisionObjects.Values)
            {
                pairCachingGhostObject = ghostObject as PairCachingGhostObject;
                if (pairCachingGhostObject != null)
                {
                    RecordGhostCollisions(pairCachingGhostObject);
                }

            }


            updatedEntityCount = LastEntityProperty;
            updatedEntities = UpdatedObjects;

            collidersCount = LastCollisionDesc;
            colliders = UpdatedCollisions;


        }
        else
        {
            //if (updatedEntities is null)
            //updatedEntities = new List<BulletXNA.EntityProperties>();
            //updatedEntityCount = 0;


            //collidersCount = 0;

            updatedEntities = new EntityProperties[0];


            colliders = new CollisionDesc[0];

        }
        return numSimSteps;
    }
Beispiel #20
0
 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);
 }
Beispiel #21
0
 public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value) { /* TODO */
     return false; }
Beispiel #22
0
    public override BulletShape CreateHullShape(BulletWorld pWorld, int pHullCount, float[] pConvHulls)
    {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        CompoundShape compoundshape = new CompoundShape(false);

        compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin);
        int ii = 1;

        for (int i = 0; i < pHullCount; i++)
        {
            int vertexCount = (int) pConvHulls[ii];

            IndexedVector3 centroid = new IndexedVector3(pConvHulls[ii + 1], pConvHulls[ii + 2], pConvHulls[ii + 3]);
            IndexedMatrix childTrans = IndexedMatrix.Identity;
            childTrans._origin = centroid;

            List<IndexedVector3> virts = new List<IndexedVector3>();
            int ender = ((ii + 4) + (vertexCount*3));
            for (int iii = ii + 4; iii < ender; iii+=3)
            {

                virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2]));
            }
            ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount);
            convexShape.SetMargin(world.WorldSettings.Params.collisionMargin);
            compoundshape.AddChildShape(ref childTrans, convexShape);
            ii += (vertexCount*3 + 4);
        }

        return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL);
    }
Beispiel #23
0
    public override bool AddObjectToWorld(BulletWorld pWorld, BulletBody pBody)
    {
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        CollisionObject cbody = (pBody as BulletBodyXNA).body;
        RigidBody rbody = cbody as RigidBody;

        // Bullet resets several variables when an object is added to the world. In particular,
        //   BulletXNA resets position and rotation. Gravity is also reset depending on the static/dynamic
        //   type. Of course, the collision flags in the broadphase proxy are initialized to default.
        IndexedMatrix origPos = cbody.GetWorldTransform();
        if (rbody != null)
        {
            IndexedVector3 origGrav = rbody.GetGravity();
            world.AddRigidBody(rbody);
            rbody.SetGravity(origGrav);
        }
        else
        {
            world.AddCollisionObject(cbody);
        }
        cbody.SetWorldTransform(origPos);

        pBody.ApplyCollisionMask(pWorld.physicsScene);

        //if (body.GetBroadphaseHandle() != null)
        //    world.UpdateSingleAabb(body);
        return true;
    }
Beispiel #24
0
 public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms)
 {
     /* TODO */ return null;
 }
Beispiel #25
0
 public override void UpdateAabbs(BulletWorld pWorld) {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     world.UpdateAabbs();
 }
Beispiel #26
0
 public override BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
 {
     /* TODO */ return null;
 }
Beispiel #27
0
 public override void SetForceUpdateAllAabbs(BulletWorld pWorld, bool pForce)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     world.SetForceUpdateAllAabbs(pForce);
 }
Beispiel #28
0
 public override BulletShape CreateConvexHullShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
 {
     /* TODO */ return null;
 }
Beispiel #29
0
    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);
    }
Beispiel #30
0
    public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
    {
        //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount);

        for (int iter = 0; iter < pVerticesCount; iter++)
        {
            if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0;
            if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0;
        }

        ObjectArray<int> indicesarr = new ObjectArray<int>(indices);
        ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats);
        DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount);
        DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
        IndexedMesh mesh = new IndexedMesh();
        mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
        mesh.m_numTriangles = pIndicesCount/3;
        mesh.m_numVertices = pVerticesCount;
        mesh.m_triangleIndexBase = indicesarr;
        mesh.m_vertexBase = vertices;
        mesh.m_vertexStride = 3;
        mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
        mesh.m_triangleIndexStride = 3;

        TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
        tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
        BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true);
        meshShape.SetMargin(world.WorldSettings.Params.collisionMargin);
       // world.UpdateSingleAabb(meshShape);
        return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH);

    }
Beispiel #31
0
 public override bool IsInWorld(BulletWorld pWorld, BulletBody pCollisionObject)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
     return world.IsInWorld(collisionObject);
 }
Beispiel #32
0
 public override BulletShape CreateGImpactShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
 {
     // TODO:
     return null;
 }