public RigidBodyConstructionInfo(float mass, MotionState motionState, CollisionShape collisionShape, Vector3 localInertia)
 {
     _native = btRigidBody_btRigidBodyConstructionInfo_new2(mass, (motionState != null) ? motionState._native : IntPtr.Zero,
         (collisionShape != null) ? collisionShape._native : IntPtr.Zero, ref localInertia);
     _collisionShape = collisionShape;
     _motionState = motionState;
 }
 public RigidBodyConstructionInfo(float mass, MotionState motionState, CollisionShape collisionShape)
 {
     _native = btRigidBody_btRigidBodyConstructionInfo_new(mass, (motionState != null) ? motionState._native : IntPtr.Zero,
         (collisionShape != null) ? collisionShape._native : IntPtr.Zero);
     _collisionShape = collisionShape;
     _motionState = motionState;
 }
Esempio n. 3
0
        public void SetUpBulletPhysicsBody(float mass, BulletSharp.MotionState motionState, BulletSharp.CollisionShape collisionShape, Vector3 localInertia)
        {
            BulletSharpPhysics.RigidBodyConstructionInfo rbInfo =
                new BulletSharpPhysics.RigidBodyConstructionInfo(mass, motionState, collisionShape, localInertia);
            RigidBody = new BulletSharpPhysics.RigidBody(rbInfo);

            bulletPhysics.World.AddRigidBody(RigidBody, GetCollisionFlags(), GetCollisionMask());
        }
Esempio n. 4
0
 public BulletSharpObject(Game game, string modelAssetName, float mass, BulletSharp.MotionState motionState, BulletSharp.CollisionShape collisionShape, Vector3 localInertia)
     : base(game, modelAssetName)
 {
     SetUpBulletPhysicsBody(mass, motionState, collisionShape, localInertia);
 }
Esempio n. 5
0
 public RigidBody(RigidBodyConstructionInfo constructionInfo)
     : base(btRigidBody_new(constructionInfo._native))
 {
     _collisionShape = constructionInfo.CollisionShape;
     _motionState = constructionInfo._motionState;
 }
        /**
        Creates or configures a RigidBody based on the current settings. Does not alter the internal state of this component in any way.
        Can be used to create copies of this BRigidBody for use in other physics simulations.
        */
        public bool CreateOrConfigureRigidBody(ref RigidBody rb, ref BulletSharp.Math.Vector3 localInertia, CollisionShape cs, MotionState motionState)
        {
            //rigidbody is dynamic if and only if mass is non zero, otherwise static
            localInertia = BulletSharp.Math.Vector3.Zero;
            if (isDynamic())
            {
                cs.CalculateLocalInertia(_mass, out localInertia);
            }

            if (rb == null)
            {
                float bulletMass = _mass;
                if (!isDynamic())
                {
                    bulletMass = 0f;
                }
                RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(bulletMass, motionState, cs, localInertia);
                rbInfo.Friction = _friction;
                rbInfo.RollingFriction = _rollingFriction;
                rbInfo.LinearDamping = _linearDamping;
                rbInfo.AngularDamping = _angularDamping;
                rbInfo.Restitution = _restitution;
                rbInfo.LinearSleepingThreshold = _linearSleepingThreshold;
                rbInfo.AngularSleepingThreshold = _angularSleepingThreshold;
                rbInfo.AdditionalDamping = _additionalDamping;
                rbInfo.AdditionalAngularDampingFactor = _additionalAngularDampingFactor;
                rbInfo.AdditionalAngularDampingThresholdSqr = _additionalAngularDampingThresholdSqr;
                rbInfo.AdditionalDampingFactor = _additionalDampingFactor;
                rbInfo.AdditionalLinearDampingThresholdSqr = _additionalLinearDampingThresholdSqr;
                rb = new RigidBody(rbInfo);
                rbInfo.Dispose();
            }
            else {
                float usedMass = 0f;
                if (isDynamic())
                {
                    usedMass = _mass;
                }
                rb.SetMassProps(usedMass, localInertia);
                rb.Friction = _friction;
                rb.RollingFriction = _rollingFriction;
                rb.SetDamping(_linearDamping, _angularDamping);
                rb.Restitution = _restitution;
                rb.SetSleepingThresholds(_linearSleepingThreshold, _angularSleepingThreshold);
                rb.CollisionShape = cs;
            }

            rb.AngularVelocity = angularVelocity.ToBullet();
            rb.LinearVelocity = velocity.ToBullet();

            rb.CollisionFlags = m_collisionFlags;
            rb.LinearFactor = _linearFactor.ToBullet();
            rb.AngularFactor = _angularFactor.ToBullet();
            if (m_rigidBody != null)
            {
                rb.DeactivationTime = m_rigidBody.DeactivationTime;
                rb.InterpolationLinearVelocity = m_rigidBody.InterpolationLinearVelocity;
                rb.InterpolationAngularVelocity = m_rigidBody.InterpolationAngularVelocity;
                rb.InterpolationWorldTransform = m_rigidBody.InterpolationWorldTransform;
            }

            //if kinematic then disable deactivation
            if ((m_collisionFlags & BulletSharp.CollisionFlags.KinematicObject) != 0)
            {
                rb.ActivationState = ActivationState.DisableDeactivation;
            }
            return true;
        }
Esempio n. 7
0
 public RigidBody(RigidBodyConstructionInfo constructionInfo)
     : base(btRigidBody_new(constructionInfo._native))
 {
     _collisionShape = constructionInfo.CollisionShape;
     _motionState    = constructionInfo.MotionState;
 }
Esempio n. 8
0
        /// <summary>
        /// Set up all of the stuff needed before we create our body
        /// </summary>
        private void SetUpBodyInfo(ThingDefinition def)
        {
            // set up our collision shapes
            CollisionShape shape = LKernel.GetG<CollisionShapeManager>().CreateAndRegisterShape(this, def);

            // get the physics type and set up the mass of the body
            ThingEnum physicsType = def.GetEnumProperty("physics", null);
            float mass = physicsType.HasFlag(ThingEnum.Static) ? 0 : def.GetFloatProperty("mass", 1);

            // create our construction info thingy
            Vector3 inertia;
            shape.CalculateLocalInertia(mass, out inertia);

            // if it's static and doesn't have a sound, we don't need a mogre motion state because we'll be disposing of the root node afterwards
            if (def.GetBoolProperty("Static", false) && SoundComponents == null)
                MotionState = new DefaultMotionState();
            else
                MotionState = InitializationMotionState;

            Info = new RigidBodyConstructionInfo(mass, MotionState, shape, inertia);

            // physics material stuff from a .physmat file
            string physmat = def.GetStringProperty("PhysicsMaterial", "Default");
            LKernel.GetG<PhysicsMaterialFactory>().ApplyMaterial(Info, physmat);

            // we can override some of them in the .thing file
            if (def.FloatTokens.ContainsKey("bounciness"))
                Info.Restitution = def.GetFloatProperty("bounciness", PhysicsMaterial.DEFAULT_BOUNCINESS);
            if (def.FloatTokens.ContainsKey("friction"))
                Info.Friction = def.GetFloatProperty("friction", PhysicsMaterial.DEFAULT_FRICTION);
            if (def.FloatTokens.ContainsKey("angulardamping"))
                Info.AngularDamping = def.GetFloatProperty("angulardamping", PhysicsMaterial.DEFAULT_ANGULAR_DAMPING);
            if (def.FloatTokens.ContainsKey("lineardamping"))
                Info.LinearDamping = def.GetFloatProperty("lineardamping", PhysicsMaterial.DEFAULT_LINEAR_DAMPING);

            // choose which group to use for a default
            ThingEnum defaultGroup;
            if (physicsType.HasFlag(ThingEnum.Dynamic))
                defaultGroup = ThingEnum.Default;
            else if (physicsType.HasFlag(ThingEnum.Static))
                defaultGroup = ThingEnum.Environment;
            else // kinematic
                defaultGroup = ThingEnum.Default;

            // collision group
            ThingEnum collisionGroup = def.GetEnumProperty("CollisionGroup", defaultGroup);
            PonykartCollisionGroups pcg;
            if (!Enum.TryParse<PonykartCollisionGroups>(collisionGroup + String.Empty, true, out pcg))
                throw new FormatException("Invalid collision group!");
            CollisionGroup = pcg;

            // collides-with group
            ThingEnum collidesWith = def.GetEnumProperty("CollidesWith", defaultGroup);
            PonykartCollidesWithGroups pcwg;
            if (!Enum.TryParse<PonykartCollidesWithGroups>(collidesWith + String.Empty, true, out pcwg))
                throw new FormatException("Invalid collides-with group!");
            CollidesWith = pcwg;

            // update the transforms
            Matrix4 transform = new Matrix4();
            transform.MakeTransform(SpawnPosition, SpawnScale, SpawnOrientation);
            Info.StartWorldTransform = transform;
            MotionState.WorldTransform = transform;
        }