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;
 }
 // Create a btGeneric6DofConstraint
 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
     Vector3 frame1, Quaternion frame1rot,
     Vector3 frame2, Quaternion frame2rot,
     bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
     : base(world)
 {
     m_body1 = obj1;
     m_body2 = obj2;
     m_constraint = PhysicsScene.PE.Create6DofConstraint(m_world, m_body1, m_body2,
                         frame1, frame1rot,
                         frame2, frame2rot,
                         useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
     world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
                     BSScene.DetailLogZero, world.worldID,
                     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)
     : 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}",
             BSScene.DetailLogZero, 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;
         }
     }
 }
        // Create terrain mesh from a heightmap.
        public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap,
            Vector3 minCoords, Vector3 maxCoords)
            : base(physicsScene, regionBase, id)
        {
            int indicesCount;
            int[] indices;
            int verticesCount;
            float[] vertices;

            m_savedHeightMap = initialMap;

            m_sizeX = (int)(maxCoords.X - minCoords.X);
            m_sizeY = (int)(maxCoords.Y - minCoords.Y);

            bool meshCreationSuccess = false;
            if (BSParam.TerrainMeshMagnification == 1)
            {
                // If a magnification of one, use the old routine that is tried and true.
                meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh(PhysicsScene,
                    initialMap, m_sizeX, m_sizeY, // input size
                    Vector3.Zero, // base for mesh
                    out indicesCount, out indices, out verticesCount, out vertices);
            }
            else
            {
                // Other magnifications use the newer routine
                meshCreationSuccess = BSTerrainMesh.ConvertHeightmapToMesh2(PhysicsScene,
                    initialMap, m_sizeX, m_sizeY, // input size
                    BSParam.TerrainMeshMagnification,
                    physicsScene.TerrainManager.WorldMax,
                    Vector3.Zero, // base for mesh
                    out indicesCount, out indices, out verticesCount, out vertices);
            }
            if (!meshCreationSuccess)
            {
                // DISASTER!!
                PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedConversionOfHeightmap,id={1}",
                    BSScene.DetailLogZero, ID);
                PhysicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh! base={1}", LogHeader,
                    TerrainBase);
                // Something is very messed up and a crash is in our future.
                return;
            }

            PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshid,id={1},indices={2},indSz={3},vertices={4},vertSz={5}",
                BSScene.DetailLogZero, ID, indicesCount, indices.Length, verticesCount, vertices.Length);

            m_terrainShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, indicesCount, indices, verticesCount,
                vertices);

            if (!m_terrainShape.HasPhysicalShape)
            {
                // DISASTER!!
                PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape,id={1}", BSScene.DetailLogZero,
                    ID);
                PhysicsScene.Logger.ErrorFormat("{0} Failed creation of terrain mesh! base={1}", LogHeader, TerrainBase);
                // Something is very messed up and a crash is in our future.
                return;
            }

            Vector3 pos = regionBase;
            Quaternion rot = Quaternion.Identity;

            m_terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot);
            if (!m_terrainBody.HasPhysicalBody)
            {
                // DISASTER!!
                PhysicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase);
                // Something is very messed up and a crash is in our future.
                return;
            }

            physicsScene.PE.SetShapeCollisionMargin(m_terrainShape, BSParam.TerrainCollisionMargin);

            // Set current terrain attributes
            PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction);
            PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction);
            PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution);
            PhysicsScene.PE.SetContactProcessingThreshold(m_terrainBody, BSParam.TerrainContactProcessingThreshold);
            PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT);

            // Static objects are not very massive.
            PhysicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero);

            // Put the new terrain to the world of physical objects
            PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody);

            // Redo its bounding box now that it is in the world
            PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody);

            m_terrainBody.collisionType = CollisionType.Terrain;
            m_terrainBody.ApplyCollisionMask(PhysicsScene);

            if (BSParam.UseSingleSidedMeshes)
            {
                PhysicsScene.DetailLog("{0},BSTerrainMesh.settingCustomMaterial,id={1}", BSScene.DetailLogZero, id);
                PhysicsScene.PE.AddToCollisionFlags(m_terrainBody, CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
            }

            // Make it so the terrain will not move or be considered for movement.
            PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION);
        }
Exemplo n.º 5
0
 public override Vector3 GetAngularFactor(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     IndexedVector3 iv3 = body.GetAngularFactor();
     return new Vector3(iv3.X, iv3.Y, iv3.Z);
 }
Exemplo n.º 6
0
 public override int GetActivationState(BulletBody pBody)
 {
     /* TODO */
     return 0;
 }
Exemplo n.º 7
0
 public override void DestroyObject(BulletWorld pWorld, BulletBody pBody)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     CollisionObject co = (pBody as BulletBodyXNA).rigidBody;
     RigidBody bo = co as RigidBody;
     if (bo == null)
     {
         if (world.IsInWorld(co))
         {
             world.RemoveCollisionObject(co);
         }
     }
     else
     {
         if (world.IsInWorld(bo))
         {
             world.RemoveRigidBody(bo);
         }
     }
     if (co != null)
     {
         if (co.GetUserPointer() != null)
         {
             uint localId = (uint)co.GetUserPointer();
             if (specialCollisionObjects.ContainsKey(localId))
             {
                 specialCollisionObjects.Remove(localId);
             }
         }
     }
 }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
0
 public override void ApplyDamping(BulletBody pBody, float timeStep)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     body.ApplyDamping(timeStep);
 }
Exemplo n.º 10
0
 public override CollisionFlags AddToCollisionFlags(BulletBody pCollisionObject, CollisionFlags pcollisionFlags)
 {
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
     CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)collisionObject.GetCollisionFlags();
     existingcollisionFlags |= pcollisionFlags;
     collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
     return (CollisionFlags)(uint)existingcollisionFlags;
 }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
 private static EntityProperties GetDebugProperties(BulletWorld pWorld, BulletBody pCollisionObject)
 {
     EntityProperties ent = new EntityProperties();
     // 20131224 not used        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;
 }
Exemplo n.º 13
0
 public override bool WantsSleeping(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     return body.WantsSleeping();
 }
Exemplo n.º 14
0
 public override void UpdateSingleAabb(BulletWorld pWorld, BulletBody pCollisionObject)
 {
     DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world;
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
     world.UpdateSingleAabb(collisionObject);
 }
Exemplo n.º 15
0
 public override void UpdateInertiaTensor(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     if (body != null) // can't update inertia tensor on CollisionObject
         body.UpdateInertiaTensor();
 }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
 }
Exemplo n.º 18
0
 public override void ApplyForce(BulletBody pBody, Vector3 force, Vector3 pos)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     IndexedVector3 forceiv3 = new IndexedVector3(force.X, force.Y, force.Z);
     IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z);
     body.ApplyForce(ref forceiv3, ref posiv3);
 }
Exemplo n.º 19
0
        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;

                // 20131224 not used            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);
        }
Exemplo n.º 20
0
 public override void ApplyGravity(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     body.ApplyGravity();
 }
Exemplo n.º 21
0
 public override void ForceActivationState(BulletBody pCollisionObject, ActivationState pActivationState)
 {
     CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
     collisionObject.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState);
 }
Exemplo n.º 22
0
 public override void ApplyImpulse(BulletBody pBody, Vector3 imp, Vector3 pos)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     IndexedVector3 impiv3 = new IndexedVector3(imp.X, imp.Y, imp.Z);
     IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z);
     body.ApplyImpulse(ref impiv3, ref posiv3);
 }
Exemplo n.º 23
0
 public override float GetAngularDamping(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     return body.GetAngularDamping();
 }
Exemplo n.º 24
0
 public override void ApplyTorqueImpulse(BulletBody pBody, Vector3 pfSum)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
     body.ApplyTorqueImpulse(ref fSum);
 }
        // Create the initial instance of terrain and the underlying ground plane.
        // This is called from the initialization routine so we presume it is
        //    safe to call Bullet in real time. We hope no one is moving prims around yet.
        public void CreateInitialGroundPlaneAndTerrain()
        {
            DetailLog("{0},BSTerrainManager.CreateInitialGroundPlaneAndTerrain,region={1}", BSScene.DetailLogZero,
                PhysicsScene.RegionName);
            // The ground plane is here to catch things that are trying to drop to negative infinity
            BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f,
                BSParam.TerrainCollisionMargin);
            m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape,
                BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity);

            PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane);
            PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane);
            // Ground plane does not move
            PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);
            // Everything collides with the ground plane.
            m_groundPlane.collisionType = CollisionType.Groundplane;
            m_groundPlane.ApplyCollisionMask(PhysicsScene);

            m_terrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, m_worldMax);
        }
Exemplo n.º 26
0
        public override void ClearAllForces(BulletBody pCollisionObject)
        {
            CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body;
            IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0);
            collisionObject.SetInterpolationLinearVelocity(ref zeroVector);
            collisionObject.SetInterpolationAngularVelocity(ref zeroVector);
            IndexedMatrix bodytransform = collisionObject.GetWorldTransform();

            collisionObject.SetInterpolationWorldTransform(ref bodytransform);

            if (collisionObject is RigidBody)
            {
                RigidBody rigidbody = collisionObject as RigidBody;
                rigidbody.SetLinearVelocity(zeroVector);
                rigidbody.SetAngularVelocity(zeroVector);
                rigidbody.ClearForces();
            }
        }
 // 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 useLinearReferenceFrameB, 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,
         useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies);
     m_enabled = true;
     world.physicsScene.DetailLog("{0},BS6DofConstraint,createFixed,wID={1},rID={2},rBody={3}",
         BSScene.DetailLogZero, world.worldID, obj1.ID, obj1.AddrString);
 }
Exemplo n.º 28
0
 public override void ClearForces(BulletBody pBody)
 {
     RigidBody body = (pBody as BulletBodyXNA).rigidBody;
     body.ClearForces();
 }
Exemplo n.º 29
0
        protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
        {
            PhysicsScene = parentScene;
            LocalID = localID;
            PhysObjectName = name;
            Name = name;    // PhysicsActor also has the name of the object. Someday consolidate.
            TypeName = typeName;

            // The collection of things that push me around
            PhysicalActors = new BSActorCollection(PhysicsScene);

            // Initialize variables kept in base.
            GravityMultiplier = 1.0f;
            Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
            //HoverActive = false;

            // We don't have any physical representation yet.
            PhysBody = new BulletBody(localID);
            PhysShape = new BulletShape();

            PrimAssetState = PrimAssetCondition.Unknown;

            // Default material type. Also sets Friction, Restitution and Density.
            SetMaterial((int)MaterialAttributes.Material.Wood);

            CollisionCollection = new CollisionEventUpdate();
            CollisionsLastTick = CollisionCollection;
            SubscribedEventsMs = 0;
            CollidingStep = 0;
            TrueCollidingStep = 0;
            CollisionAccumulation = 0;
            ColliderIsMoving = false;
            CollisionScore = 0;

            // All axis free.
            LockedAxis = LockedAxisFree;
        }
Exemplo n.º 30
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);
        }