Esempio n. 1
0
        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher    = new CollisionDispatcher(CollisionConf);

            Broadphase = new AxisSweep3(
                new Vector3(-1000, -1000, -1000),
                new Vector3(1000, 1000, 1000));

            World         = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            renderCallback = new DrawingResult(World);

            var boxA = new BoxShape(1.0f)
            {
                Margin = 0
            };
            var boxB = new BoxShape(0.5f)
            {
                Margin = 0
            };

            CollisionShapes.Add(boxA);
            CollisionShapes.Add(boxB);

            Quaternion rotA = new Quaternion(0.739f, -0.204f, 0.587f, 0.257f);

            rotA.Normalize();

            objectA = new CollisionObject
            {
                CollisionShape = boxA,
                WorldTransform = Matrix.RotationQuaternion(rotA) * Matrix.Translation(0, 3, 0)
            };
            objectB = new CollisionObject
            {
                CollisionShape = boxB,
                WorldTransform = Matrix.Translation(0, 4.248f, 0)
            };

            //World.AddCollisionObject(objectA);
            World.AddCollisionObject(objectB);
        }
        public override void OnUpdate()
        {
            base.OnUpdate();

            DrawingResult renderCallback = new DrawingResult(World);
            World.ContactTest(objects[0], renderCallback);

            Matrix t = objects[0].WorldTransform;
            Vector4 pos = t.get_Rows(3);
            t.set_Rows(3, new Vector4(0, 0, 0, 1));
            t *= Matrix.RotationYawPitchRoll(0.1f * FrameDelta, 0.05f * FrameDelta, 0);
            t.set_Rows(3, pos);
            objects[0].WorldTransform = t;

            Vector3 min = new Vector3(-1, -1, -1);
            Vector3 max = new Vector3(1, 1, 1);
            World.DebugDrawer.DrawBox(ref min, ref max, ref t, System.Drawing.Color.White);
        }
Esempio n. 3
0
        public override void OnUpdate()
        {
            base.OnUpdate();

            DrawingResult renderCallback = new DrawingResult(World);

            World.ContactTest(objects[0], renderCallback);

            Matrix  t   = objects[0].WorldTransform;
            Vector4 pos = t.Row4;

            t.Row4 = new Vector4(0, 0, 0, 1);
            t     *= Matrix.RotationYawPitchRoll(0.1f * FrameDelta, 0.05f * FrameDelta, 0);
            t.Row4 = pos;
            objects[0].WorldTransform = t;

            Vector3 min = new Vector3(-1, -1, -1);
            Vector3 max = new Vector3(1, 1, 1);

            World.DebugDrawer.DrawBox(ref min, ref max, ref t, ref min);
        }
        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            renderCallback = new DrawingResult(World);


            BoxShape boxA = new BoxShape(new Vector3(1, 1, 1));
            boxA.Margin = 0;

            BoxShape boxB = new BoxShape(new Vector3(0.5f, 0.5f, 0.5f));
            boxB.Margin = 0;

            CollisionShapes.Add(boxA);
            CollisionShapes.Add(boxB);

            objects[0] = new CollisionObject();
            objects[1] = new CollisionObject();

            objects[0].CollisionShape = boxA;
            objects[1].CollisionShape = boxB;

            //World.AddCollisionObject(objects[0]);
            World.AddCollisionObject(objects[1]);

            Quaternion rotA = new Quaternion(0.739f, -0.204f, 0.587f, 0.257f);
            rotA.Normalize();

            objects[0].WorldTransform = Matrix.RotationQuaternion(rotA) * Matrix.Translation(0, 3, 0);
            objects[1].WorldTransform = Matrix.Translation(0, 4.248f, 0);
        }
        public CollisionInterfaceDemoSimulation()
        {
            CollisionConfiguration = new DefaultCollisionConfiguration();
            Dispatcher             = new CollisionDispatcher(CollisionConfiguration);

            Broadphase = new AxisSweep3(
                new Vector3(-1000, -1000, -1000),
                new Vector3(1000, 1000, 1000));

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration);

            RenderCallback = new DrawingResult(World);

            _movingBox = new BoxShape(1.0f)
            {
                Margin = 0
            };
            var rotation = Quaternion.RotationYawPitchRoll((float)Math.PI * 0.6f, (float)Math.PI * 0.2f, 0);

            MovingObject = new CollisionObject
            {
                CollisionShape = _movingBox,
                WorldTransform = Matrix.RotationQuaternion(rotation) * Matrix.Translation(0, 3, 0)
            };

            _staticShape = new BoxShape(0.5f)
            {
                Margin = 0
            };
            _staticObject = new CollisionObject
            {
                CollisionShape = _staticShape,
                WorldTransform = Matrix.Translation(0, 4.248f, 0)
            };
            World.AddCollisionObject(_staticObject);
        }