示例#1
0
        ///setupRigidBody is only used internally by the constructor
        public void SetupRigidBody(RigidBodyConstructionInfo constructionInfo)
        {
            m_internalType = CollisionObjectTypes.CO_RIGID_BODY;

            m_linearVelocity       = IndexedVector3.Zero;
            m_angularVelocity      = IndexedVector3.Zero;
            m_angularFactor        = IndexedVector3.One;
            m_linearFactor         = IndexedVector3.One;
            m_gravity              = IndexedVector3.Zero;
            m_gravity_acceleration = IndexedVector3.Zero;
            m_totalForce           = IndexedVector3.Zero;
            m_totalTorque          = IndexedVector3.Zero;
            SetDamping(constructionInfo.m_linearDamping, constructionInfo.m_angularDamping);
            m_linearSleepingThreshold              = constructionInfo.m_linearSleepingThreshold;
            m_angularSleepingThreshold             = constructionInfo.m_angularSleepingThreshold;
            m_optionalMotionState                  = constructionInfo.m_motionState;
            m_contactSolverType                    = 0;
            m_frictionSolverType                   = 0;
            m_additionalDamping                    = constructionInfo.m_additionalDamping;
            m_additionalDampingFactor              = constructionInfo.m_additionalDampingFactor;
            m_additionalLinearDampingThresholdSqr  = constructionInfo.m_additionalLinearDampingThresholdSqr;
            m_additionalAngularDampingThresholdSqr = constructionInfo.m_additionalAngularDampingThresholdSqr;
            m_additionalAngularDampingFactor       = constructionInfo.m_additionalAngularDampingFactor;

            if (m_optionalMotionState != null)
            {
                m_optionalMotionState.GetWorldTransform(out m_worldTransform);
            }
            else
            {
                SetWorldTransform(ref constructionInfo.m_startWorldTransform);
            }

            m_interpolationWorldTransform  = m_worldTransform;
            m_interpolationLinearVelocity  = IndexedVector3.Zero;
            m_interpolationAngularVelocity = IndexedVector3.Zero;

            //moved to btCollisionObject
            m_friction    = constructionInfo.m_friction;
            m_restitution = constructionInfo.m_restitution;

            SetCollisionShape(constructionInfo.m_collisionShape);
            m_debugBodyId = uniqueId++;

            SetMassProps(constructionInfo.m_mass, constructionInfo.m_localInertia);
            UpdateInertiaTensor();
            m_rigidbodyFlags = RigidBodyFlags.BT_NONE;
            m_constraintRefs = new List <TypedConstraint>();

            m_deltaLinearVelocity  = IndexedVector3.Zero;
            m_deltaAngularVelocity = IndexedVector3.Zero;
            m_invMass      = m_inverseMass * m_linearFactor;
            m_pushVelocity = IndexedVector3.Zero;
            m_turnVelocity = IndexedVector3.Zero;
        }
示例#2
0
        public void BuildCollisionData(Color[] map, int width, int height, Vector3 bottomLeft)
        {
            Vector2 dim   = Vector2.One;
            Vector3 scale = new Vector3(dim, 1);

            BoxShape collisionBoxShape = new BoxShape(new IndexedVector3(0.5f));

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int currentIndex = x + y * width;
                    if (map[currentIndex] == Color.White)
                    {
                        float   yOffset  = -dim.Y;//0f;// -(dim.Y / 2f);
                        Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z);
                        m_waterLocations.Add(position);
                    }

                    if (map[currentIndex] == Color.White)
                    {
                        // check the 4 ordinals , if we're surrounded by other solid blocks
                        // then we don't need a block here.
                        bool upSet    = false;
                        bool downSet  = false;
                        bool leftSet  = false;
                        bool rightSet = false;

                        if (x >= 1 && x < width - 1)
                        {
                            if (map[currentIndex - 1] == Color.White)
                            {
                                leftSet = true;
                            }
                            if (map[currentIndex + 1] == Color.White)
                            {
                                rightSet = true;
                            }
                        }

                        if (y >= 1 && y < height - 1)
                        {
                            if (map[currentIndex - height] == Color.White)
                            {
                                upSet = true;
                            }
                            if (map[currentIndex + height] == Color.White)
                            {
                                downSet = true;
                            }
                        }

                        // if we're not surrounded by blocks then add in.
                        if (!(upSet && downSet && leftSet && rightSet))
                        {
                            Object  rigifdBody;
                            float   yOffset  = -dim.Y;//0f;// -(dim.Y / 2f);
                            Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z);

                            RigidBodyConstructionInfo constructionInfo = new BulletMonogame.BulletDynamics.RigidBodyConstructionInfo(0f, null, (BulletMonogame.BulletCollision.CollisionShape)collisionBoxShape);
                            RigidBody rigidBody = new BulletMonogame.BulletDynamics.RigidBody(constructionInfo);
                            Matrix    bsm       = Matrix.CreateTranslation(position);
                            rigidBody.SetWorldTransform(bsm);
                            // FIXME MAN - setup some collision flags on these bodies...
                            BulletMonogame.BulletCollision.CollisionFilterGroups flags = (BulletMonogame.BulletCollision.CollisionFilterGroups)(1 << 8);
                            BulletMonogame.BulletCollision.CollisionFilterGroups mask  = (BulletMonogame.BulletCollision.CollisionFilterGroups)(1 << 9);
                            //rigidBody.CollisionFlags |= (BulletSharp.CollisionFlags)CollisionObjectType.Ground;
                            m_dynamicsWorld.AddRigidBody(rigidBody, flags, mask);
                        }
                    }

                    // Build water ghost objects.
                    foreach (Vector3 pos in m_waterLocations)
                    {
                        GhostObject ghostObject = new GhostObject();

                        ghostObject.SetCollisionShape((BulletMonogame.BulletCollision.CollisionShape)collisionBoxShape);

                        CollisionFilterGroups flags = (CollisionFilterGroups)(1 << 10);
                        CollisionFilterGroups mask  = (CollisionFilterGroups)(1 << 9);

                        ghostObject.SetCollisionFlags(CollisionFlags.CF_NO_CONTACT_RESPONSE | CollisionFlags.CF_STATIC_OBJECT);         // We can choose to make it "solid" if we want...
                        ghostObject.SetWorldTransform(BulletMonogame.LinearMath.IndexedMatrix.CreateTranslation(pos));
                        m_dynamicsWorld.AddCollisionObject(ghostObject, flags, mask);
                        break;
                    }
                }
            }
        }
示例#3
0
        ///btRigidBody constructor for backwards compatibility.
        ///To specify friction (etc) during rigid body construction, please use the other constructor (using btRigidBodyConstructionInfo)
        public RigidBody(float mass, IMotionState motionState, CollisionShape collisionShape, IndexedVector3 localInertia)
        {
            RigidBodyConstructionInfo cinfo = new RigidBodyConstructionInfo(mass, motionState, collisionShape, localInertia);

            SetupRigidBody(cinfo);
        }
示例#4
0
 ///btRigidBody constructor using construction info
 public RigidBody(RigidBodyConstructionInfo constructionInfo)
 {
     SetupRigidBody(constructionInfo);
 }