Exemplo n.º 1
0
        private BodyDescription CreateBoxDescription(float width, float height, float lenght)
        {
            var boxShape      = new Box(width, height, lenght);
            var boxShapeIndex = Simulation.Shapes.Add(boxShape);

            boxShape.ComputeInertia(1, out var boxInertia);
            Symmetric3x3.Scale(boxInertia.InverseInertiaTensor, .5f, out boxInertia.InverseInertiaTensor);
            var boxDescription = new BodyDescription()
            {
                LocalInertia = boxInertia,
                Pose         = new RigidPose
                {
                    Position    = Vector3.Zero,
                    Orientation = Quaternion.Identity
                },
                Activity = new BodyActivityDescription {
                    MinimumTimestepCountUnderThreshold = 32, SleepThreshold = .01f
                },
                Collidable = new CollidableDescription {
                    Shape = boxShapeIndex, SpeculativeMargin = .1f
                },
            };

            return(boxDescription);
        }
Exemplo n.º 2
0
        public override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(-30, 8, -60);
            camera.Yaw      = MathHelper.Pi * 3f / 4;
            camera.Pitch    = 0;


            _poseIntegrator = new DefaultPoseIntegratorCallbacks(BufferPool);

            Simulation = Simulation.Create(BufferPool, new DefaultNarrowPhaseCallbacks(), _poseIntegrator);


            var boxShape  = new Box(1, 1, 1);
            var baseShape = new Box(5, 1, 5);


            boxShape.ComputeInertia(1000, out var boxInertia);

            var boxShapeIndex  = Simulation.Shapes.Add(boxShape);
            var baseShapeIndex = Simulation.Shapes.Add(baseShape);

            Symmetric3x3.Scale(boxInertia.InverseInertiaTensor, .5f, out boxInertia.InverseInertiaTensor);

            var boxDescription = new BodyDescription
            {
                //Make the uppermost block kinematic to hold up the rest of the chain.
                LocalInertia = boxInertia,
                Pose         = new RigidPose
                {
                    Position    = new Vector3(0, -2, 0),
                    Orientation = Quaternion.Identity
                },
                Activity = new BodyActivityDescription {
                    MinimumTimestepCountUnderThreshold = 32, SleepThreshold = .01f
                },
                Collidable = new CollidableDescription {
                    Shape = boxShapeIndex, SpeculativeMargin = .1f
                },
            };


            var baseDescription = new BodyDescription
            {
                //Make the uppermost block kinematic to hold up the rest of the chain.
                LocalInertia = new BodyInertia(),
                Pose         = new RigidPose
                {
                    Position    = new Vector3(0, 0, 0),
                    Orientation = Quaternion.Identity
                },
                Activity = new BodyActivityDescription {
                    MinimumTimestepCountUnderThreshold = 32, SleepThreshold = .01f
                },
                Collidable = new CollidableDescription {
                    Shape = baseShapeIndex, SpeculativeMargin = .1f
                },
            };

            var boxIndex  = Simulation.Bodies.Add(boxDescription);
            var baseIndex = Simulation.Bodies.Add(baseDescription);

            _boxReference  = new BodyReference(boxIndex, Simulation.Bodies);
            _baseReference = new BodyReference(baseIndex, Simulation.Bodies);
        }