示例#1
0
        protected override void OnAttach()
        {
            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;

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

            UpdatePhysicsTransformation(); //this will set position and rotation of the collider

            if (IsDefaultGroup)
            {
                Simulation.AddRigidBody(this, CollisionFilterGroupFlags.DefaultFilter, CollisionFilterGroupFlags.AllFilter);
            }
            else
            {
                Simulation.AddRigidBody(this, (CollisionFilterGroupFlags)CollisionGroup, CanCollideWith);
            }
        }
        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);
        }