Exemple #1
0
        private void initializePhysicsEngine()
        {
            engine = new PhysicsEngine3D(partition);
            engine.Gravity = new Vector3(0, -0.1f, 0);
            engine.AddRigidBody(player.Body); //physics body of player

            //floor and walls
            engine.AddRigidBody(new PlaneBody(Vector3.Up, new Vector3(0, 1f, 0)));
            engine.AddRigidBody(new PlaneBody(new Vector3(1f, 0, 0), new Vector3(1f, 0, 0)));
            engine.AddRigidBody(new PlaneBody(new Vector3(-1f, 0, 0), new Vector3(map.Width - 1, 0, 0)));
            engine.AddRigidBody(new PlaneBody(new Vector3(0, 0, 1f), new Vector3(0, 0, 1f)));
            engine.AddRigidBody(new PlaneBody(new Vector3(0, 0, -1f), new Vector3(0, 0, map.Depth - 1)));
        }
        private void setupEngine()
        {
            engine = new PhysicsEngine3D(new GridPartition3D(Vector3.Zero, new Vector3(10, 10, 10), 3, 3, 3));

            float boxSize = 10;

            engine.AddRigidBody(new PlaneBody(Vector3.Up, Vector3.Zero));
            engine.AddRigidBody(new PlaneBody(Vector3.Right, Vector3.Zero));
            engine.AddRigidBody(new PlaneBody(new Vector3(0, 0, 1), Vector3.Zero));

            engine.AddRigidBody(new PlaneBody(-Vector3.Up, new Vector3(0, boxSize, 0)));
            engine.AddRigidBody(new PlaneBody(-Vector3.Right, new Vector3(boxSize, 0, 0)));
            engine.AddRigidBody(new PlaneBody(new Vector3(0, 0, -1), new Vector3(0, 0, boxSize)));

            int bodyCount = 5;
            for (int i = 0; i < bodyCount; i++)
            {
                engine.AddRigidBody(new SphereBody(new Vector3((i*2) + 1, 6, 2), new Vector3(i + 1f, 0, 0), 1f, radius));
            }

            for (int i = 0; i < bodyCount; i++)
            {
                engine.AddRigidBody(new SphereBody(new Vector3((i * 2) + 1, 8, 2.4f), new Vector3(i - 1f, 0, 0), 1f, radius));
            }
        }