示例#1
0
        public void TestCollisionPoint()
        {
            var repository = GetBlockRepository();
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var physics = new PhysicsEngine(world, repository);
            var entity = new TestEntity();
            entity.Position = new Vector3(0, 5, 0);
            entity.AccelerationDueToGravity = 1;
            entity.Drag = 0;
            physics.AddEntity(entity);

            world.SetBlockID(new Coordinates3D(0, 4, 0), StoneBlock.BlockID);

            // Test
            physics.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual(new Vector3(0, 4, 0), entity.CollisionPoint);
        }
示例#2
0
        public void TestGravity()
        {
            var repository = GetBlockRepository();
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var physics = new PhysicsEngine(world, repository);
            var entity = new TestEntity();
            entity.Position = new Vector3(0, 100, 0);
            entity.AccelerationDueToGravity = 1;
            entity.Drag = 0;
            physics.AddEntity(entity);

            // Test
            physics.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual(99, entity.Position.Y);

            physics.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual(97, entity.Position.Y);
        }
示例#3
0
        public void TestAdjacentFall()
        {
            // Tests an entity that falls alongside a wall

            var repository = GetBlockRepository();
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var physics = new PhysicsEngine(world, repository);
            var entity = new TestEntity();
            entity.Position = new Vector3(0, 10, 0);
            entity.AccelerationDueToGravity = 1;
            physics.AddEntity(entity);

            // Create a wall
            for (int y = 0; y < 12; y++)
                world.SetBlockID(new Coordinates3D(1, y, 0), StoneBlock.BlockID);

            // Test
            physics.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual(9, entity.Position.Y);
            Assert.IsFalse(entity.CollisionOccured);
        }
示例#4
0
        public void TestTerrainCollision()
        {
            var repository = GetBlockRepository();
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var physics = new PhysicsEngine(world, repository);
            var entity = new TestEntity();
            entity.Size = new Size(0.6, 1.8, 0.6);
            entity.Position = new Vector3(-10.9, 4, -10.9);
            entity.AccelerationDueToGravity = 1;
            physics.AddEntity(entity);

            // Test
            physics.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual(4, entity.Position.Y);

            physics.Update(TimeSpan.FromSeconds(5));

            Assert.AreEqual(4, entity.Position.Y);
        }