コード例 #1
0
        public void TestWorldRenderer()
        {
            var game = new LocalGame();

            var ent = new Engine.WorldRendering.Entity();

            var mBuilder = new MeshBuilder();

            mBuilder.AddSphere(12, 1);
            ent.Mesh = mBuilder.CreateMesh();

            var time = 0f;


            game
            .AddSimulator(new BasicSimulator(delegate
            {
                time           += TW.Graphics.Elapsed;
                ent.Mesh        = mesh;
                ent.WorldMatrix = Matrix.Translation(Vector3.UnitX * time);
            }))
            .AddSimulator(new WorldRenderingSimulator());



            game.Run();
        }
コード例 #2
0
        public void TestPlayerMovement()
        {
            var game = new LocalGame();

            var ent = new Engine.WorldRendering.Entity();

            ent.Mesh = mesh;

            var ent2 = new Engine.WorldRendering.Entity();

            ent2.Mesh        = mesh;
            ent2.WorldMatrix = Matrix.Translation(5, 0, 0);

            var player = new PlayerData();

            player.Entity = ent;

            player.GroundHeight   = 5;
            player.DisableGravity = true;


            game
            .AddSimulator(new LocalPlayerSimulator(player))
            .AddSimulator(new ThirdPersonCameraSimulator())
            .AddSimulator(new WorldRenderingSimulator());


            TW.Data.GetSingleton <CameraInfo>().Mode = CameraInfo.CameraMode.ThirdPerson;
            TW.Data.GetSingleton <CameraInfo>().ThirdPersonCameraTarget = player.Entity;

            game.Run();
        }
コード例 #3
0
        private void raycastEntity(Engine.WorldRendering.Entity ent, Ray ray, RaycastResult newResult)
        {
            bool abort = ent.Mesh == null;

            if (abort)
            {
                newResult.Set(null, ent);
                return;
            }

            var transformed = ray.Transform(Matrix.Invert(ent.WorldMatrix));


            //TODO: do course boundingbox check
            var bb = TW.Assets.GetBoundingBox(ent.Mesh);

            if (!transformed.xna().Intersects(bb.xna()).HasValue)
            {
                newResult.Set(null, ent);
                return;
            }



            Vector3 v1, v2, v3;
            var     distance = MeshRaycaster.RaycastMesh(ent.Mesh, transformed, out v1, out v2, out v3);


            newResult.Set(distance, ent);
            newResult.V1 = Vector3.TransformCoordinate(v1, ent.WorldMatrix);
            newResult.V2 = Vector3.TransformCoordinate(v2, ent.WorldMatrix);
            newResult.V3 = Vector3.TransformCoordinate(v3, ent.WorldMatrix);
        }
コード例 #4
0
        public void TestPointLight()
        {
            var game = EngineFactory.CreateEngine();

            game.Initialize();

            var e = new Engine.WorldRendering.Entity()
            {
                Mesh = MeshFactory.Load("Core\\TileSet\\ts001sg001")
            };

            var light = new PointLight
            {
                Position = new Vector3(-1, 0, 0)
            };
            var time = 2f;


            game.AddSimulator(new BasicSimulator(delegate
            {
                time           += TW.Graphics.Elapsed;
                light.Position  = new Vector3(-1, (float)Math.Sin(time), (float)Math.Cos(time));
                light.Size      = 10;
                light.Intensity = 2;
            }));


            game.AddSimulator(new WorldRenderingSimulator());



            game.Run();
        }
コード例 #5
0
        private BoundingBox getEntityBB(Engine.WorldRendering.Entity ent)
        {
            var bb = TW.Assets.GetBoundingBox(ent.Mesh);

            bb = bb.Transform(ent.WorldMatrix);
            return(bb);
        }
コード例 #6
0
        public void Initialize(TWEngine game)
        {
            game.AddSimulator(new PhysXSimulator());
            game.AddSimulator(new WorldRenderingSimulator());
            game.AddSimulator(new PhysXDebugRendererSimulator());


            var e = new Engine.WorldRendering.Entity
            {
                Mesh        = MeshFactory.Load("Core\\TileSet\\ts001sg001"),
                Visible     = true,
                Solid       = true,
                WorldMatrix = Matrix.Translation(0, 5, 0)
            };

            e = new Engine.WorldRendering.Entity
            {
                Mesh        = MeshFactory.Load("Core\\TileSet\\ts001sg001"),
                Visible     = true,
                Solid       = false,
                WorldMatrix = Matrix.Translation(0, 10, 0)
            };

            e = new Engine.WorldRendering.Entity
            {
                Mesh        = MeshFactory.Load("Core\\Barrel01"),
                Visible     = true,
                Solid       = true,
                Static      = false,
                WorldMatrix = Matrix.Translation(0, 20, 0)
            };
        }
コード例 #7
0
 /// <summary>
 /// Removes when necessary
 /// </summary>
 /// <param name="ent"></param>
 private void tryRemove(Engine.WorldRendering.Entity ent)
 {
     if (!addedEntities.Contains(ent))
     {
         return;
     }
     data.Grid.RemoveObject(ent, getEntityBB(ent));
     addedEntities.Remove(ent);
 }
コード例 #8
0
 /// <summary>
 /// adds when necessary
 /// </summary>
 /// <param name="ent"></param>
 private void tryAdd(Engine.WorldRendering.Entity ent)
 {
     if (!ent.Solid)
     {
         return;
     }
     if (addedEntities.Contains(ent))
     {
         return;
     }
     data.Grid.AddObject(ent, getEntityBB(ent));
     addedEntities.Add(ent);
 }
コード例 #9
0
 public void Simulate()
 {
     if (TW.Graphics.Keyboard.IsKeyPressed(SlimDX.DirectInput.Key.F))
     {
         var f = new Engine.WorldRendering.Entity
         {
             Mesh        = MeshFactory.Load("Core\\Barrel01"),
             Visible     = true,
             Solid       = true,
             Static      = false,
             WorldMatrix = Matrix.Translation(0, 20, 0)
         };
     }
 }
コード例 #10
0
        public Sphere()
        {
            ent = new Engine.WorldRendering.Entity();

            var mBuilder = new MeshBuilder();

            mBuilder.AddSphere(12, 1);
            ent.Mesh = mBuilder.CreateMesh();



            XNAGame game = new XNAGame();

            var data = ent.Mesh.GetCollisionData();


            var box = new MeshCollisionData.Box();

            box.Dimensions  = MathHelper.One.xna() * 2;
            box.Orientation = Matrix.Identity.xna();

            data.Boxes.Add(box);

            var builder = new MeshPhysicsActorBuilder(new MeshPhysicsPool());

            dEl = new MeshDynamicPhysicsElement(ent.Mesh, Matrix.Identity.xna(), builder);

            dEl.InitDynamic(TW.Physics.Scene);
            dEl.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10;


            //TODO: use the MeshP
            //var factory = new MeshPhysicsElementFactory(engine, root);
            //game.AddXNAObject(factory);



            //TODO: this update function must be called
            //game.UpdateEvent += delegate
            //{

            //        dEl.Update(root, game);

            //};
        }
コード例 #11
0
        public void TestChangeEntity()
        {
            var container = new Data.ModelContainer();

            SimpleModelObject.CurrentModelContainer = new Data.ModelContainer();

            var ent = new Engine.WorldRendering.Entity();

            ent.Mesh = new RAMMesh();

            int length;

            Data.ModelContainer.ObjectChange[] array;
            container.GetObjectChanges(out array, out length);



            Assert.AreEqual(1, length);
            Assert.AreEqual(ent, array[0].ModelObject);
        }
コード例 #12
0
        public void TestEntityVisible()
        {
            var game = EngineFactory.CreateEngine();

            game.Initialize();

            game.AddSimulator(new WorldRenderingSimulator());

            var e = new Engine.WorldRendering.Entity()
            {
                Mesh    = MeshFactory.Load("Core\\TileSet\\ts001sg001"),
                Visible = false
            };


            game.AddSimulator(new BasicSimulator(delegate
            {
            }));


            game.Run();
        }
コード例 #13
0
        public PlayerData()
        {
            Entity = new Engine.WorldRendering.Entity();

            Entity.Mesh = GetBarrelMesh(new TheWizards.OBJParser.OBJToRAMMeshConverter(new RAMTextureFactory()));
        }