Пример #1
0
 /// <summary>
 /// Method to draw map and all its contents
 /// </summary>
 /// <param name="gfxDevice">Graphics device instance</param>
 /// <param name="projection">projection matrix</param>
 /// <param name="view">view matrix</param>
 /// <param name="lightsSetup">lights setup array as required by all static objects</param>
 /// <param name="fogColor">fog color as a vector3</param>
 /// <param name="fogSetup">fog setup as required by all static objects</param>
 /// <param name="basicEffect">basic effect class to enable primative drawing</param>
 /// <param name="camPos">camera position (note: N O T the focus point - used to translate the skybox when its drawn)</param>
 public static void DrawMap(GraphicsDevice gfxDevice, Matrix projection, ContentManager contentMgr, Matrix view, Vector3[] lightsSetup, Vector3 fogColor, int[] fogSetup, BasicEffect basicEffect, Vector3 camPos)
 {
     //Draw skybox
     if (skyBoxDrawer != null)
         skyBoxDrawer.Draw(view, projection, gfxDevice);
     //Draw all objects:
     foreach (Object item in BBNMap.content.Values)
     {
         if (shouldDrawPathNodeConnections)
             if (item is Node)
             {
                 for (int i = 0; i < (item as Node).getEdgeCount(); ++i) // draw all edges
                 {
                     Edge e = (item as Node).getEdge(i);
                     Algorithms.Draw3DLine(Color.Red, e.node1.Position, e.node2.Position, basicEffect, gfxDevice, projection, view, Matrix.Identity);
                 }
             }
         if (item is Drawer)
             (item as Drawer).Draw(view, projection, lightsSetup, fogColor, fogSetup);
         else if (item is Marker)
         {
             Drawer dTemp = new Drawer((item as Marker).Position, contentMgr,true);
             dTemp.addAttribute("modelName", MODEL_USED_FOR_MAP_EDITOR);
             dTemp.addAttribute("x", Convert.ToString((item as Marker).Position.X));
             dTemp.addAttribute("y", Convert.ToString((item as Marker).Position.Y));
             dTemp.addAttribute("z", Convert.ToString((item as Marker).Position.Z));
             dTemp.addAttribute("scaleX", "0.25");
             dTemp.addAttribute("scaleY", "0.25");
             dTemp.addAttribute("scaleZ", "0.25");
             dTemp.addAttribute("yaw", "0");
             dTemp.addAttribute("pitch", "0");
             dTemp.addAttribute("roll", "0");
             dTemp.onAttributeChange();
             dTemp.update(new KeyboardState(), new GamePadState(), new GamePadState());
             dTemp.Draw(view, projection, lightsSetup, fogColor, fogSetup);
         }
     }
 }
Пример #2
0
 private void scrMainLayout_Panel2_MouseDown(object sender, MouseEventArgs e)
 {
     scrMainLayout.Panel2.Focus();
     if (e.Button == MouseButtons.Right)
         oldCursorPos = e.Location;
     else if (e.Button == MouseButtons.Left && !(yDown || rDown || pDown)) //checks if the user has selected one of the movement axis
     {
         oldCursorPos = e.Location;
         if (cbxMapItems.SelectedIndex >= 0)
         {
             if (Algorithms.clickedNearRay(e.X, e.Y, this.xArrowBottom, this.xArrowTop))
                 selectedXMoveLine = true;
             else if (Algorithms.clickedNearRay(e.X, e.Y, this.yArrowBottom, this.yArrowTop))
                 selectedYMoveLine = true;
             else if (Algorithms.clickedNearRay(e.X, e.Y, this.zArrowBottom, this.zArrowTop))
                 selectedZMoveLine = true;
         }
         if (!(selectedXMoveLine || selectedYMoveLine || selectedZMoveLine)) //otherwise check if the user selected some object
         {
             Vector3 vNear = gfxDevice.Viewport.Unproject(new Vector3(e.X, e.Y, 0f),
                 projection, view, Matrix.CreateTranslation(0,0,0));
             Vector3 vFar = gfxDevice.Viewport.Unproject(new Vector3(e.X, e.Y, this.farClip),
                 projection, view, Matrix.CreateTranslation(0, 0, 0));
             float minDist = 0;
             Drawer closestObj = null;
             foreach (Object item in BBNMap.content.Values)
             {
                 if (item is Drawer)
                 {
                     float dist = 0;
                     if (CollisionDetectionHelper.rayIntersect(vNear, vFar, (item as Drawer).model, (item as Drawer).world, out dist))
                         if (closestObj == null || dist < minDist)
                         {
                             minDist = dist;
                             closestObj = (item as Drawer);
                         }
                 }
                 else if (item is Marker)
                 {
                     float dist = 0;
                     Drawer tempD = new Drawer((item as Marker).Position, contentMgr,true);
                     tempD.addAttribute("modelName", BBNMap.MODEL_USED_FOR_MAP_EDITOR);
                     tempD.itemClassName = (item as Marker).className;
                     tempD.setNewId((item as Marker).id);
                     tempD.addAttribute("x", Convert.ToString((item as Marker).Position.X));
                     tempD.addAttribute("y", Convert.ToString((item as Marker).Position.Y));
                     tempD.addAttribute("z", Convert.ToString((item as Marker).Position.Z));
                     tempD.addAttribute("scaleX", "0.25");
                     tempD.addAttribute("scaleY", "0.25");
                     tempD.addAttribute("scaleZ", "0.25");
                     tempD.addAttribute("yaw", "0");
                     tempD.addAttribute("pitch", "0");
                     tempD.addAttribute("roll", "0");
                     tempD.onAttributeChange();
                     tempD.update(new KeyboardState(), new GamePadState(), new GamePadState());
                     if (CollisionDetectionHelper.rayIntersect(vNear, vFar, tempD.model, tempD.world, out dist))
                         if (closestObj == null || dist < minDist)
                         {
                             minDist = dist;
                             closestObj = tempD;
                         }
                 }
             }
             //get the closest object (first in depth sort):
             if (closestObj != null)
             {
                 //connect path nodes (if "c" is held down and a path node is selected then connect it to the node the user clicked on if it is another path node):
                 if (closestObj.itemClassName == "PathNode" && cDown)
                 {
                     Object item = BBNMap.content[cbxMapItems.SelectedItem.ToString().Split(':')[0].Trim()];
                     Node picked = BBNMap.content[closestObj.id] as Node;
                     bool found = false;
                     for (int i = 0; i < (item as Node).getEdgeCount(); ++i)
                     {
                         Edge edge = (item as Node).getEdge(i);
                         if (edge.node1 == picked || edge.node2 == picked)
                         {
                             (item as Node).disconnectFromNode(picked);
                             found = true;
                             break;
                         }
                     }
                     if (!found && closestObj.id != (item as Node).id)
                         (item as Node).connectToNode(picked, 0);
                 }
                 else if (!cDown) //otherwise simply select object
                 {
                     foreach (object o in cbxMapItems.Items)
                         if (o.ToString().Split(':')[0].Trim() == closestObj.id)
                             cbxMapItems.SelectedItem = o;
                     this.updateProperties(closestObj.id);
                 }
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Method to load a map
        /// </summary>
        /// <param name="filename">file name of map</param>
        /// <param name="contentMgr">content manager instance</param>
        /// <param name="gfxDevice">graphics device instance</param>
        public static void loadMap(String filename, ContentManager contentMgr, GraphicsDevice gfxDevice)
        {
            XmlReader reader = XmlReader.Create(filename);
            XPathDocument docNav = new XPathDocument(reader);
            XPathNavigator nav = docNav.CreateNavigator();
            XmlNamespaceManager nsmanager = new XmlNamespaceManager(nav.NameTable);
            XPathNodeIterator iter;
            XPathNavigator mapIter = nav.SelectSingleNode("/Map");
            mapRadius = Convert.ToSingle(mapIter.GetAttribute("mapRadius", nsmanager.DefaultNamespace));

            XPathNavigator skyboxIter = nav.SelectSingleNode("/Map/Skybox");
            String texName = skyboxIter.GetAttribute("texture", nsmanager.DefaultNamespace);
            skyBoxRepeat = Convert.ToSingle(skyboxIter.GetAttribute("repeat", nsmanager.DefaultNamespace));
            SetUpSkyBox(gfxDevice, contentMgr, texName, Convert.ToString(skyBoxRepeat));
            //Now read in path nodes:
            iter = nav.Select("/Map/Marker[@className!='SpawnPoint' and @className!='PlayerSpawnPoint']");
            while (iter.MoveNext())
            {
                Node n = new Node();
                readMarkerData(contentMgr, reader, docNav, nav, nsmanager, iter, n);
                content.Add(n.id, n);
            }
            //Read spawnpoints:
            iter = nav.Select("/Map/Marker[@className='SpawnPoint']");
            while (iter.MoveNext())
            {
                SpawnPoint n = new SpawnPoint();
                readMarkerData(contentMgr, reader, docNav, nav, nsmanager, iter, n);
                content.Add(n.id, n);
            }
            //Read player spawnpoints:
            iter = nav.Select("/Map/Marker[@className='PlayerSpawnPoint']");
            while (iter.MoveNext())
            {
                SpawnPoint n = new PlayerSpawnPoint();
                readMarkerData(contentMgr, reader, docNav, nav, nsmanager, iter, n);
                content.Add(n.id, n);
            }
            //Now read other content:
            iter = nav.Select("/Map/ContentItem");
            while (iter.MoveNext())
            {
                Drawer n = new Drawer(false);
                n.contentLoader = contentMgr;
                readObjectData(contentMgr, reader, docNav, nav, nsmanager, iter, n);
            }
            List<Edge> edgeList = new List<Edge>();
            List<float> edgeDistances = new List<float>();
            iter = nav.Select("/Map/PathEdge");
            while (iter.MoveNext())
            {
                float weight = Convert.ToSingle(iter.Current.GetAttribute("weight", nsmanager.DefaultNamespace));
                float distance = Convert.ToSingle(iter.Current.GetAttribute("distance", nsmanager.DefaultNamespace));
                String firstId = iter.Current.SelectSingleNode("firstNodeId").Value;
                String secondId = iter.Current.SelectSingleNode("secondNodeId").Value;
                Node first = null, second = null;
                foreach (Object item in content.Values)
                    if (item is Node)
                    {
                        if ((item as Marker).id == firstId)
                            first = item as Node;
                        else if ((item as Marker).id == secondId)
                            second = item as Node;
                        if (first != null && second != null)
                            break;
                    }
                edgeList.Add(new Edge(first, second, weight));
                edgeDistances.Add(distance);
            }
            //Connect nodes:
            for (int i = 0; i < edgeList.Count; i++)
            {
                Edge item = edgeList.ElementAt(i);
                float distance = edgeDistances.ElementAt(i);
                item.node1.connectToNode(item.node2, item.weight, distance);
            }
            reader.Close();
        }
Пример #4
0
 //After the user clicks on the toolbox:
 private void tvwToolbox_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (e.Node.Nodes.Count != 0)
         tvwToolbox.SelectedNode = null;
     else
     {
         MapContent newItem = null;
         foreach (ToolboxItem item in ToolboxLoader.toolboxContent)
             if (item.name == tvwToolbox.SelectedNode.Text)
             {
                 newItem = new Drawer(cameraFocus,this.contentMgr,false);
                 newItem.copyPropertiesFromToolboxTemplate(item); //copy default attributes
                 newItem.setAttribute("x", Convert.ToString(cameraFocus.X));
                 newItem.setAttribute("y", Convert.ToString(cameraFocus.Y));
                 newItem.setAttribute("z", Convert.ToString(cameraFocus.Z));
                 break;
             }
         this.cbxMapItems.SelectedIndex = this.cbxMapItems.Items.Add(newItem.id + " : " + newItem.itemClassName);
         updateProperties(newItem.id);
         tvwToolbox.SelectedNode = null;
     }
     enableCorrectControls();
 }