コード例 #1
0
ファイル: Program.cs プロジェクト: Keldyn/BattleOfTheClans
        public override void Init()
        {
            Content.ContentPath = "../WorkingDirectory/Data";
            Content.ContentCachePath = "Cache/";
            Meshes.Load(Device);

            scene = new WorldScene(this);
            scene.Camera = new WalkaroundCamera(this, (float x, float y) =>
            {
                return 0;
            }) { Speed = 20, ZFar = 1000 };
            plane = Meshes.PositionTexcoord(Device, Meshes.IndexedPlane(-0.5f, -0.5f, 1, 1));

            navMeshEditor = new Editor.WorldEditor.NavMeshEditor(this, scene, (Point p, out Vector3 w) => { return CalcMouseWorldPos(p, scene.Camera, out w); }, plane);
            navMeshEditor.Active = true;
            navMeshEditor.LoadNavMesh(navMesh = new Common.Pathing.NavMesh());
            scene.Add(new WorldEntity()
            {
                Model = new Model
                {
                    Mesh = plane,
                    Texture = text = content.Get<Texture>("grid.tga"),
                    World = Matrix.Scaling(100, 100, 0)
                }
            });
        }
コード例 #2
0
        public void Render(Graphics.BoundingVolumesRenderer bvRenderer,
                           View view,
                           Scene scene,
                           Common.Pathing.NavMesh navMesh,
                           int activeFrame)
        {
            if (Settings.VisualBoundings)
            {
                foreach (var v in scene.AllEntities)
                {
                    if (v.ActiveInMain == activeFrame)
                    {
                        bvRenderer.Draw(Matrix.Identity,
                                        v.VisibilityWorldBounding,
                                        Color.Orange);
                    }
                }
            }

            if (Settings.PhysicsBoundings)
            {
                bvRenderer.DrawFullChains = Settings.PhysicsBoundingsFullChains;
                foreach (var v in scene.AllEntities)
                {
                    if (v is Client.Game.Map.GameEntity &&
                        v.ActiveInMain == activeFrame &&
                        (!Settings.PhysicsBoundingsHideGround || !(v is Client.Game.Map.GroundPiece)))
                    {
                        bvRenderer.Draw(Matrix.Identity,
                                        ((Client.Game.Map.GameEntity)v).PhysicsLocalBounding != null ?
                                        Common.Boundings.Transform(((Client.Game.Map.GameEntity)v).PhysicsLocalBounding, v.WorldMatrix)
                            : null,
                                        Color.Blue);
                    }
                }
                bvRenderer.DrawFullChains = true;
            }

            if (Settings.PathMesh)
            {
                bvRenderer.Draw(Matrix.Identity, navMesh.BoundingRegion, Color.White);
            }

            if (Settings.AggroRange)
            {
                foreach (var v in scene.AllEntities)
                {
                    if (v.ActiveInMain == activeFrame && v is Map.NPC)
                    {
                        view.DrawCircle(scene.Camera, Matrix.Identity,
                                        ((Map.NPC)v).Position, ((Map.NPC)v).InRangeRadius, 12, Color.Red);
                    }
                }
            }
        }
コード例 #3
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene        = new Scene();
            scene.View   = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position    = new Vector3(-5, 5, 5),
                ZFar        = 200,
                AspectRatio = AspectRatio
            };
            BinaryFormatter b        = new BinaryFormatter();
            string          filename = "../../navmesh";

            Common.Pathing.NavMesh navmesh;
            if (File.Exists(filename))
            {
                FileStream f = new FileStream(filename, FileMode.Open);
                try
                {
                    navmesh = (Common.Pathing.NavMesh)b.Deserialize(f);
                }
                catch (Exception e)
                {
                    navmesh = new Common.Pathing.NavMesh();
                    System.Windows.Forms.MessageBox.Show(e.ToString());
                }
            }
            else
            {
                navmesh = new Common.Pathing.NavMesh();
            }

            editor = new Graphics.Editors.BoundingRegionEditor(this,
                                                               new Graphics.WorldViewProbe(this, scene.Camera));
            editor.Region  = navmesh.BoundingRegion;
            editorRenderer = new Graphics.Editors.BoundingRegionEditor.Renderer9(editor)
            {
                StateManager = new Device9StateManager(Device9),
                Camera       = scene.Camera
            };
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera       = (LookatCartesianCamera)scene.Camera,
                InputHandler = editor
            };
        }
コード例 #4
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(-5, 5, 5),
                ZFar = 200,
                AspectRatio = AspectRatio
            };
            BinaryFormatter b = new BinaryFormatter();
            string filename = "../../navmesh";
            Common.Pathing.NavMesh navmesh;
            if (File.Exists(filename))
            {
                FileStream f = new FileStream(filename, FileMode.Open);
                try
                {
                    navmesh = (Common.Pathing.NavMesh)b.Deserialize(f);
                }
                catch (Exception e)
                {
                    navmesh = new Common.Pathing.NavMesh();
                    System.Windows.Forms.MessageBox.Show(e.ToString());
                }
            }
            else
                navmesh = new Common.Pathing.NavMesh();

            editor = new Graphics.Editors.BoundingRegionEditor(this,
                new Graphics.WorldViewProbe(this, scene.Camera));
            editor.Region = navmesh.BoundingRegion;
            editorRenderer = new Graphics.Editors.BoundingRegionEditor.Renderer9(editor)
            {
                StateManager = new Device9StateManager(Device9),
                Camera = scene.Camera
            };
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = editor
            };
        }
コード例 #5
0
        public void LoadNavMesh(String filename)
        {
            if (!File.Exists(filename))
            {
                return;
            }

            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            FileStream f = new FileStream(filename, FileMode.Open);

            navMesh = new Common.Pathing.NavMesh();
            navMesh.BoundingRegion = (Common.Bounding.Region)b.Deserialize(f);
            editor.Region          = navMesh.BoundingRegion;
            if (motionSimulation is Common.Motion.ThreadSimulationProxy)
            {
                ((Common.Motion.Simulation)((Common.Motion.ThreadSimulationProxy)motionSimulation).InnerSimulation).NavMesh = navMesh;
            }
            else
            {
                ((Common.Motion.Simulation)motionSimulation).NavMesh = navMesh;
            }
        }
コード例 #6
0
        public void LoadNavMesh(Common.Pathing.NavMesh navMesh)
        {
            hasChanged = false;
            this.navMesh = navMesh;
            if (navMesh.Nodes == null) return;
            Dictionary<Vector3, Vertex> posToVertex = new Dictionary<Vector3,Vertex>();
            Dictionary<Common.Pathing.NavMesh.Node, Face> nodeToFace = new Dictionary<Common.Pathing.NavMesh.Node, Face>();
            for(int i=0; i < navMesh.Nodes.Length; i++)
            {
                var node = navMesh.Nodes[i];
                foreach (Vector3 v in node.polygon)
                {
                    if (!posToVertex.ContainsKey(v))
                    {
                        Vertex ve;
                        scene.Add(ve = new Vertex(this)
                        {
                            Model = vertexModel,
                            Translation = v,
                            IsVisible = Display
                        });
                        vertices.Add(ve);
                        posToVertex.Add(v, ve);
                    }
                }
                Face face = new Face(this)
                {
                    Model = new Model
                    {
                        Mesh = Meshes.PositionTexcoord(view.Device, Meshes.IndexedTriangle(
                            node.polygon[0], node.polygon[1], node.polygon[2])),
                            Texture = view.content.Get<Texture>("white1.png")
                    },
                    IsVisible = false,
                    Vertices = new Vertex[] { posToVertex[node.polygon[0]], posToVertex[node.polygon[1]], posToVertex[node.polygon[2]] },
                    Id = i
                };
                posToVertex[node.polygon[0]].Faces.Add(face);
                posToVertex[node.polygon[1]].Faces.Add(face);
                posToVertex[node.polygon[2]].Faces.Add(face);
                scene.Add(face);
                faces.Add(face);
                nodeToFace.Add(node, face);
            }

            foreach (var node in navMesh.Nodes)
            {
                foreach (Common.Pathing.NavMesh.Edge edge in node.Edges.Values)
                {
                    Face left = nodeToFace[edge.Left];
                    Face right = nodeToFace[edge.Right];
                    if (!left.ContainsEdgeTo(right) && !right.ContainsEdgeTo(left))
                    {
                        int index = 0;
                        while (left.Vertices[index].Translation != edge.PointA) index++;
                        left.Edges.Add(new Edge
                        {
                            Left = left,
                            Right = right,
                            LeftIndex = index
                        });
                    }
                }
            }
        }
コード例 #7
0
        public override void Init()
        {
            if (DesignMode)
            {
                return;
            }

            Content.ContentPath = "Data";

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

            scene.Camera = new LookatCartesianCamera()
            {
                Lookat      = Vector3.Zero,
                Position    = new Vector3(-15, 15, 15),
                FOV         = 0.5f,
                ZFar        = 400,
                AspectRatio = AspectRatio
            };

            renderer = new Graphics.Renderer.Renderer(Device9)
            {
                Scene        = scene,
                Settings     = new Graphics.Renderer.Settings(),
                StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9)
            };
            renderer.Initialize(this);
            sceneQuadtree          = new Common.Quadtree <Entity>(10);
            sbau                   = new SceneBVHAutoSyncer(scene, sceneQuadtree);
            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene    = scene
            };
            sceneRendererConnector.Initialize();

            navMesh = new Common.Pathing.NavMesh();

            worldViewProbe = new Graphics.WorldViewProbe(this, scene.Camera);
            editor         = new Graphics.Editors.BoundingRegionEditor(this, worldViewProbe);
            editor.Region  = navMesh.BoundingRegion;

            editorRenderer = new Graphics.Editors.BoundingRegionEditor.Renderer9(editor)
            {
                StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9),
                Camera       = scene.Camera
            };
            InputHandler = editor;
            inputHandlers.Add(editor);
            inputHandlers.Add(new WalkaroundCameraInputHandler
            {
                Camera       = (LookatCartesianCamera)scene.Camera,
                InputHandler = new InteractiveSceneManager {
                    Scene = scene
                },
                //FilteredMessages = new MessageType[] { }
            });

            var sim = new Common.Motion.Simulation(navMesh);

            ((Common.Motion.Simulation)sim).SetHeightMap(new float[][] { new float[] { 0.5f } }, new Vector2(400, 400), new Vector2(-200, -200));
            motionSimulation = sim;
            //motionSimulation = new Common.Motion.ThreadSimulationProxy(sim);

            var ground = CreateBlock(new Vector3(-200, -200, -0.5f), new Vector3(400, 400, 1), "Models/GroundTextures/Grass1.png");

            scene.Add(ground);
            motionSimulation.Insert(ground.MotionObject);

            npc = CreateNPC(new Vector2(-2, -2));
            scene.Add(npc);
            motionSimulation.Insert(npc.MotionObject);
            ((Common.IMotion.IUnit)npc.MotionObject).VelocityImpulse(new Vector3(0, 0, 0.1f));
            ((Common.IMotion.INPC)npc.MotionObject).Weight = 10000000f;
            AddCreatedGridEvent(npc);
            //((Common.Motion.NPC)npc.MotionObject).DebugSolidAsARock = true;


            int     amount = 25;
            Vector2 offset = new Vector2(-4, -4);

            for (int i = 0; i < amount; i++)
            {
                int x = i / (int)System.Math.Sqrt(amount);
                int y = i % (int)System.Math.Sqrt(amount);
                var n = CreateNPC(new Vector2(x, y));
                pursuers.Add(n);
                scene.Add(n);
                motionSimulation.Insert(n.MotionObject);
                ((Common.IMotion.IUnit)n.MotionObject).VelocityImpulse(new Vector3(0, 0, 0.1f));
                AddCreatedGridEvent(n);
            }
        }