/// <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); } } }
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); } } } } }