예제 #1
0
        private MotionEntity CreateUnit(Vector2 position)
        {
            Vector3 translation = Common.Math.ToVector3(position);
            var     unit        = new MotionEntity
            {
                MainGraphic = new MetaModel
                {
                    SkinnedMesh = new SkinnedMeshFromFile("Models/Units/Brute1.x"),
                    Texture     = new TextureFromFile("Models/Units/Brute1.png"),
                    World       = SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Scaling(0.1f, 0.1f, 0.1f),
                    IsBillboard = false,
                },
                //Animation = "idle1",
                //AnimationLoop = true,
                Translation = translation
            };

            unit.MotionObject = new Common.Motion.Unit()
            {
                LocalBounding = new Common.Bounding.Cylinder(Vector3.Zero, 1.2f, 0.5f),
                Position      = translation
            };
            unit.VisibilityLocalBounding = unit.MotionObject.LocalBounding;
            return(unit);
        }
예제 #2
0
        private void InsertBulletMark(Vector3 position)
        {
            var me = new MotionEntity
            {
                MainGraphic = new MetaModel
                {
                    XMesh = new MeshFromFile("pebble3.x"),
                    //Texture = new TextureFromFile("pebble3.png"),
                    Texture = new TextureConcretizer {
                        TextureDescription = new global::Graphics.Software.Textures.SingleColorTexture(Color.Red)
                    },
                    World = SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Scaling(0.05f, 0.05f, 0.05f),
                },
                //Animation = "idle1",
                //AnimationLoop = true,
                Expires    = true,
                TimeToLive = 1f,
            };

            me.MotionObject = new Common.Motion.Object
            {
                LocalBounding = Vector3.Zero,
                Position      = position,
            };
            scene.Add(me);
        }
예제 #3
0
        private MotionEntity CreateBullet(Vector3 position, float speed, float orientation, Vector3 acceleration)
        {
            var velocity = new Vector3(
                speed * (float)Math.Cos(orientation),
                speed * (float)Math.Sin(orientation),
                0);
            var me = new MotionEntity
            {
                MainGraphic = new MetaModel
                {
                    SkinnedMesh = new SkinnedMeshFromFile("fireball1.x"),
                    Texture     = new TextureFromFile("fireball1.png"),
                    World       = SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Scaling(0.02f, 0.07f, 0.02f),
                    HasAlpha    = true,
                    Opacity     = 1.0f
                },
                //Animation = "idle1",
                //AnimationLoop = true,
                Expires    = true,
                TimeToLive = 40f
            };

            me.MotionObject = new Common.Motion.Projectile
            {
                Acceleration = acceleration,
                Rotation     = Quaternion.RotationAxis(Vector3.UnitZ, orientation),
                Position     = position,
                Velocity     = velocity,
                //LocalBounding = position
            };
            ((Common.Motion.Projectile)me.MotionObject).HitsObject += ((sender, e) =>
            {
                var o = e.IObject;
                InsertBulletMark(o.Position + new Vector3(0, 0, 2));
                if (!(o is Common.Motion.Unit))
                {
                    me.Remove();
                }
                else
                {
                    unitsHitLastShot++;
                }
            });
            return(me);
        }
예제 #4
0
        private MotionEntity CreateBlock(Vector3 position, Vector3 boxSize)
        {
            var block = new MotionEntity
            {
                MainGraphic = new MetaModel
                {
                    XMesh = new MeshConcretize
                    {
                        MeshDescription = new Graphics.Software.Meshes.BoxMesh
                        {
                            Min = new Vector3(-boxSize.X / 2f, -boxSize.Y / 2f, 0),
                            Max = new Vector3(boxSize.X / 2f, boxSize.Y / 2f, boxSize.Z),
                        },
                        Layout = Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                    },
                    Texture = new TextureFromFile("Models/GroundTextures/Grass1.png"),
                },
                Translation = position
            };

            block.MotionObject = new Common.Motion.Static()
            {
                Position      = position,
                LocalBounding = new Common.Bounding.Chain
                {
                    Shallow   = true,
                    Boundings = new object[]
                    {
                        new MetaBoundingBox {
                            Mesh = ((MetaModel)block.MainGraphic).XMesh
                        },
                        new BoundingMetaMesh
                        {
                            Mesh           = ((MetaModel)block.MainGraphic).XMesh,
                            Transformation = Matrix.Identity
                        }
                    }
                }
                //LocalBounding = new BoundingMetaMesh
                //{
                //    Mesh = ((MetaModel)block.MainGraphic).XMesh
                //}
            };
            return(block);
        }
예제 #5
0
 private void InsertBulletMark(Vector3 position)
 {
     var me = new MotionEntity
     {
         MainGraphic = new MetaModel
         {
             XMesh = new MeshFromFile("pebble3.x"),
             //Texture = new TextureFromFile("pebble3.png"),
             Texture = new TextureConcretizer { TextureDescription = new global::Graphics.Software.Textures.SingleColorTexture(Color.Red) },
             World = SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Scaling(0.05f, 0.05f, 0.05f),
         },
         //Animation = "idle1",
         //AnimationLoop = true,
         Expires = true,
         TimeToLive = 1f,
     };
     me.MotionObject = new Common.Motion.Object
     {
         LocalBounding = Vector3.Zero,
         Position = position,
     };
     scene.Add(me);
 }
예제 #6
0
 private MotionEntity CreateUnit(Vector2 position)
 {
     Vector3 translation = Common.Math.ToVector3(position);
     var unit = new MotionEntity
     {
         MainGraphic = new MetaModel
         {
             SkinnedMesh = new SkinnedMeshFromFile("Models/Units/Brute1.x"),
             Texture = new TextureFromFile("Models/Units/Brute1.png"),
             World = SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Scaling(0.1f, 0.1f, 0.1f),
             IsBillboard = false,
         },
         //Animation = "idle1",
         //AnimationLoop = true,
         Translation = translation
     };
     unit.MotionObject = new Common.Motion.Unit()
     {
         LocalBounding = new Common.Bounding.Cylinder(Vector3.Zero, 1.2f, 0.5f),
         Position = translation
     };
     unit.VisibilityLocalBounding = unit.MotionObject.LocalBounding;
     return unit;
 }
예제 #7
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;

            scene.Camera = new LookatCartesianCamera()
            {
                Lookat = new Vector3(size.Width / 2f, size.Height / 2f, 0),
                Position = new Vector3(10, 10, 10),
                FOV = 0.5f,
                ZFar = 100,
                AspectRatio = AspectRatio
            };

            viewport = new Graphics.GraphicsDevice.Viewport(Device9.Viewport);

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = new InteractiveSceneManager { Scene = scene },
            };

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            //renderer = new Graphics.DummyRenderer.Renderer { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene = scene
            };
            sceneRendererConnector.Initialize();

            motionSimulation = new Common.Motion.Simulation();

            scene.EntityAdded += new Action<Entity>(scene_EntityAdded);
            scene.EntityRemoved += new Action<Entity>(scene_EntityRemoved);

            var sim = (Common.Motion.Simulation)motionSimulation;

            npcs = new List<Common.IMotion.INPC>();
            Vector2 startingPosition = new Vector2(size.Width / 2f, size.Height / 2f);
            CreateGround(true);
            scene.Add(controlledUnit = CreateUnit(startingPosition));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(2, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(-4, 2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(4, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(7, -1)), new Vector3(1, 1, 1.5f)));
            //scene.Add(CreateNPC(startingPosition + new Vector2(3, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(3, -1)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-5, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-2, 1)));
            Vector2 unitGroupStartingPosition = startingPosition + new Vector2(3, 3);
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    scene.Add(CreateNPC(unitGroupStartingPosition + new Vector2(x, y)));
                }
            }

            BulletCreation = (() =>
            {
                scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                    bulletSpeed,
                    controlledUnit.MotionObject.Rotation.Angle,
                    bulletAcceleration));
            });

            foreach (var npc in npcs)
                npc.Pursue(controlledUnit.MotionObject, 1f);
        }
예제 #8
0
 private MotionEntity CreateBullet(Vector3 position, float speed, float orientation, Vector3 acceleration)
 {
     var velocity = new Vector3(
         speed * (float)Math.Cos(orientation),
         speed * (float)Math.Sin(orientation),
         0);
     var me = new MotionEntity
     {
         MainGraphic = new MetaModel
         {
             SkinnedMesh = new SkinnedMeshFromFile("fireball1.x"),
             Texture = new TextureFromFile("fireball1.png"),
             World = SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Scaling(0.02f, 0.07f, 0.02f),
             HasAlpha = true,
             Opacity = 1.0f
         },
         //Animation = "idle1",
         //AnimationLoop = true,
         Expires = true,
         TimeToLive = 40f
     };
     me.MotionObject = new Common.Motion.Projectile
     {
         Acceleration = acceleration,
         Rotation = Quaternion.RotationAxis(Vector3.UnitZ, orientation),
         Position = position,
         Velocity = velocity,
         //LocalBounding = position
     };
     ((Common.Motion.Projectile)me.MotionObject).HitsObject += ((sender, e) =>
         {
             var o = e.IObject;
             InsertBulletMark(o.Position + new Vector3(0, 0, 2));
             if (!(o is Common.Motion.Unit))
                 me.Remove();
             else
                 unitsHitLastShot++;
         });
     return me;
 }
예제 #9
0
 private MotionEntity CreateBlock(Vector3 position, Vector3 boxSize)
 {
     var block = new MotionEntity
     {
         MainGraphic = new MetaModel
         {
             XMesh = new MeshConcretize
             {
                 MeshDescription = new Graphics.Software.Meshes.BoxMesh
                 {
                     Min = new Vector3(-boxSize.X / 2f, -boxSize.Y / 2f, 0),
                     Max = new Vector3(boxSize.X / 2f, boxSize.Y / 2f, boxSize.Z),
                 },
                 Layout = Graphics.Software.Vertex.PositionNormalTexcoord.Instance
             },
             Texture = new TextureFromFile("Models/GroundTextures/Grass1.png"),
         },
         Translation = position
     };
     block.MotionObject = new Common.Motion.Static()
     {
         Position = position,
         LocalBounding = new Common.Bounding.Chain
         {
             Shallow = true,
             Boundings = new object[]
             {
                 new MetaBoundingBox { Mesh = ((MetaModel)block.MainGraphic).XMesh },
                 new BoundingMetaMesh
                 {
                     Mesh = ((MetaModel)block.MainGraphic).XMesh,
                     Transformation = Matrix.Identity
                 }
             }
         }
         //LocalBounding = new BoundingMetaMesh
         //{
         //    Mesh = ((MetaModel)block.MainGraphic).XMesh
         //}
     };
     return block;
 }