/// <summary> /// Render a highlighting version of given node. /// </summary> /// <param name="camera"></param> /// <param name="node"></param> private void RenderNode(Camera camera, WayPoint.Node node) { bool asRoad = false; RenderSphere(camera, node.RenderPosition(asRoad), CurrentRadius(), CurrentColor()); }
/// <summary> /// Find the correct position to add a node. /// </summary> /// <param name="camera"></param> /// <param name="from"></param> /// <returns></returns> private Vector3 AddPosition(Camera camera, WayPoint.Node from) { bool asRoad = false; float height = from.RenderPosition(asRoad).Z; Vector3 hit = MouseEdit.FindAtHeight(camera, MouseInput.Position, height); return(hit); }
/// <summary> /// Drag the current node/edge/path by mouse movement. Includes raise/lower /// as well as horizontal drag. /// </summary> /// <param name="camera"></param> private void DoDrag(Camera camera) { Vector3 delta = Vector3.Zero; if (mode == Mode.Drag) { Vector3 oldPos = MouseEdit.FindAtHeight(camera, MouseInput.PrevPosition, height); Vector3 newPos = MouseEdit.FindAtHeight(camera, MouseInput.Position, height); delta = newPos - oldPos; } if (mode == Mode.Raise) { float dheight = MouseInput.Position.Y - MouseInput.PrevPosition.Y; float kUpDownSpeed = -0.002f; dheight *= kUpDownSpeed; Vector3 dragPos = camera.ActualFrom; bool asRoad = false; if (node != null) { dragPos = node.RenderPosition(asRoad); } if (edge != null) { dragPos = (edge.Node0.RenderPosition(asRoad) + edge.Node1.RenderPosition(asRoad)) * 0.5f; } float dist = Vector3.Distance(dragPos, camera.ActualFrom); dheight *= dist; delta.Z = dheight; } if ((delta != Vector3.Zero) && (Path != null)) { if (actOnPath) { MovePath(Path, delta); } else if (node != null) { MoveNode(node, delta); } else if (edge != null) { MoveEdge(edge, delta); } skeletonTimer = kSkeletonTime; } }
/// <summary> /// Find the correct position to add a node. /// </summary> /// <param name="camera"></param> /// <param name="from"></param> /// <returns></returns> private Vector3 AddPosition(Camera camera, WayPoint.Node from) { bool asRoad = false; float height = from.RenderPosition(asRoad).Z; Vector2 pos = Vector2.Zero; TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { pos = touch.position; } Vector3 hit = TouchEdit.FindAtHeight(camera, TouchInput.GetAsPoint(pos), height); return(hit); }
/// <summary> /// Find the closest edge or node that we are moused-over. /// Loops over all edges and nodes in the scene. /// </summary> /// <param name="camera"></param> private void FindOver(Camera camera) { if (!ContinueMoving) { WayPoint.Path oldPath = Path; Clear(); int pathCount = WayPoint.Paths.Count; for (int iPath = 0; iPath < pathCount; ++iPath) { WayPoint.Path path = WayPoint.Paths[iPath]; int nodeCount = path.Nodes.Count; for (int iNode = 0; iNode < nodeCount; ++iNode) { bool asRoad = false; WayPoint.Node node = path.Nodes[iNode]; Vector3 pos = node.RenderPosition(asRoad); CheckObject(camera, pos, node); } int edgeCount = path.Edges.Count; for (int iEdge = 0; iEdge < edgeCount; ++iEdge) { bool asRoad = false; WayPoint.Edge edge = path.Edges[iEdge]; Vector3 pos = (edge.Node0.RenderPosition(asRoad) + edge.Node1.RenderPosition(asRoad)) * 0.5f; CheckObject(camera, pos, edge); } } if ((oldPath != null) && (oldPath != Path)) { oldPath.ClearEdit(); } } }
/// <summary> /// Drag the current node/edge/path by mouse movement. Includes raise/lower /// as well as horizontal drag. /// </summary> /// <param name="camera"></param> private void DoDrag(Camera camera) { Vector2 pos = Vector2.Zero; Vector2 prevPos = Vector2.Zero; TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { pos = touch.position; prevPos = touch.previousPosition; } Vector3 newPosition = Vector3.Zero; if (mode == Mode.Drag) { newPosition = TouchEdit.FindAtHeight(camera, TouchInput.GetAsPoint(TouchGestureManager.Get().DragGesture.DragPosition), height); } Vector3 delta = Vector3.Zero; if (mode == Mode.Raise) { float dheight = MouseInput.Position.Y - MouseInput.PrevPosition.Y; float kUpDownSpeed = -0.002f; dheight *= kUpDownSpeed; Vector3 dragPos = camera.ActualFrom; bool asRoad = false; if (node != null) { dragPos = node.RenderPosition(asRoad); } if (edge != null) { dragPos = (edge.Node0.RenderPosition(asRoad) + edge.Node1.RenderPosition(asRoad)) * 0.5f; } float dist = Vector3.Distance(dragPos, camera.ActualFrom); dheight *= dist; delta.Z = dheight; } if (newPosition != Vector3.Zero && Path != null) { if (actOnPath) { if (node != null) { Path.Translate(newPosition - node.Position); } else if (edge != null) { Path.Translate(newPosition - edge.HandlePosition); } } else if (node != null) { node.Translate(newPosition - node.Position); } else if (edge != null) { edge.Translate(newPosition - edge.HandlePosition); } skeletonTimer = kSkeletonTime; } if ((delta != Vector3.Zero) && (Path != null)) { if (actOnPath) { MovePath(Path, delta); } else if (node != null) { MoveNode(node, delta); } else if (edge != null) { MoveEdge(edge, delta); } skeletonTimer = kSkeletonTime; } }