Esempio n. 1
0
        protected override void OnAttach()
        {
            MotionState = new XenkoMotionState(this);

            SetupBoneLink();

            GetWorldTransformCallback = (out Matrix transform) => RigidBodyGetWorldTransform(out transform);
            SetWorldTransformCallback = transform => RigidBodySetWorldTransform(ref transform);

            InternalRigidBody = new BulletSharp.RigidBody(0.0f, MotionState, ColliderShape.InternalShape, Vector3.Zero)
            {
                UserObject = this
            };

            NativeCollisionObject = InternalRigidBody;

            NativeCollisionObject.ContactProcessingThreshold = !Simulation.CanCcd ? 1e18f : 1e30f;

            if (ColliderShape.NeedsCustomCollisionCallback)
            {
                NativeCollisionObject.CollisionFlags |= BulletSharp.CollisionFlags.CustomMaterialCallback;
            }

            if (ColliderShape.Is2D) //set different defaults for 2D shapes
            {
                InternalRigidBody.LinearFactor  = new Vector3(1.0f, 1.0f, 0.0f);
                InternalRigidBody.AngularFactor = new Vector3(0.0f, 0.0f, 1.0f);
            }

            var inertia = ColliderShape.InternalShape.CalculateLocalInertia(mass);

            InternalRigidBody.SetMassProps(mass, inertia);
            InternalRigidBody.UpdateInertiaTensor(); //this was the major headache when I had to debug Slider and Hinge constraint

            base.OnAttach();

            Mass            = mass;
            LinearDamping   = linearDamping;
            AngularDamping  = angularDamping;
            OverrideGravity = overrideGravity;
            Gravity         = gravity;
            RigidBodyType   = IsKinematic ? RigidBodyTypes.Kinematic : RigidBodyTypes.Dynamic;

            Simulation.AddRigidBody(this, (CollisionFilterGroupFlags)CollisionGroup, CanCollideWith);
        }
Esempio n. 2
0
 public RigidbodyComponent()
 {
     LinkedConstraints = new List <Constraint>();
     MotionState       = new XenkoMotionState(this);
 }
        protected override void OnAttach()
        {
            MotionState = new XenkoMotionState(this);

            SetupBoneLink();

            GetWorldTransformCallback = (out Matrix transform) => RigidBodyGetWorldTransform(out transform);
            SetWorldTransformCallback = transform => RigidBodySetWorldTransform(ref transform);

            InternalRigidBody = new BulletSharp.RigidBody(0.0f, MotionState, ColliderShape.InternalShape, Vector3.Zero)
            {
                UserObject = this
            };

            NativeCollisionObject = InternalRigidBody;

            NativeCollisionObject.ContactProcessingThreshold = !Simulation.CanCcd ? 1e18f : 1e30f;

            if (ColliderShape.NeedsCustomCollisionCallback)
            {
                NativeCollisionObject.CollisionFlags |= BulletSharp.CollisionFlags.CustomMaterialCallback;
            }

            if (ColliderShape.Is2D) //set different defaults for 2D shapes
            {
                InternalRigidBody.LinearFactor = new Vector3(1.0f, 1.0f, 0.0f);
                InternalRigidBody.AngularFactor = new Vector3(0.0f, 0.0f, 1.0f);
            }

            var inertia = ColliderShape.InternalShape.CalculateLocalInertia(mass);
            InternalRigidBody.SetMassProps(mass, inertia);
            InternalRigidBody.UpdateInertiaTensor(); //this was the major headache when I had to debug Slider and Hinge constraint

            base.OnAttach();

            Mass = mass;
            LinearDamping = linearDamping;
            AngularDamping = angularDamping;
            OverrideGravity = overrideGravity;
            Gravity = gravity;
            RigidBodyType = IsKinematic ? RigidBodyTypes.Kinematic : RigidBodyTypes.Dynamic;

            Simulation.AddRigidBody(this, (CollisionFilterGroupFlags)CollisionGroup, CanCollideWith);
        }
Esempio n. 4
0
 public RigidbodyComponent()
 {
     LinkedConstraints = new List<Constraint>();
     MotionState = new XenkoMotionState(this);
 }
Esempio n. 5
0
 internal RigidBody(ColliderShape collider)
     : base(collider)
 {
     LinkedConstraints = new List<Constraint>();
     MotionState = new XenkoMotionState(this);
 }
Esempio n. 6
0
 internal RigidBody(ColliderShape collider)
     : base(collider)
 {
     LinkedConstraints = new List <Constraint>();
     MotionState       = new XenkoMotionState(this);
 }