コード例 #1
0
ファイル: PathTool.cs プロジェクト: lulzzz/3DpointCloud
        /// <summary>
        /// Operations to perform on MouseMove:
        ///     If we're moving a waypoint, update the waypoint location (for rendering) to the mouse location
        ///     Otherwise, don't do anything
        /// </summary>
        /// <param name="r"></param>
        /// <param name="e"></param>
        #region Operations to perform on MouseMove
        public void OnMouseMove(Renderer r, MouseEventArgs e)
        {
            mousePoint = new PointF(e.X, e.Y);
            PointF p = r.ScreenToWorld(e.Location);

            if (shouldMove == true)
            {
                foreach (WaypointRenderer wp in newPath.WaypointList)
                {
                    if (movePointWP.Equals(wp))
                    {
                        WaypointRenderer mouseWP = wp;
                        mouseWP.X = p.X;
                        mouseWP.Y = p.Y;
                        clonePathWP.AddWaypoint(mouseWP);
                        movePointWP = mouseWP;
                    }
                    else
                    {
                        clonePathWP.AddWaypoint(wp);
                    }
                }
                newPath     = clonePathWP;
                clonePathWP = new PathToRobotRenderer();
            }
        }
コード例 #2
0
    void Update()
    {
        if (!waypointRenderer)
        {
            waypointRenderer = GetComponent <WaypointRenderer>();
        }
        else
        {
            waypointRenderer.FindLineRenderer();
            waypointRenderer.InitalizeLists();
            waypointRenderer.FindChildrenAndWaypointAnchors();
            waypointRenderer.DrawQuadraticCurve();
        }

        if (!trackManager)
        {
            trackManager = GameObject.Find("TrackManager").GetComponent <TrackManager>();
        }
        else
        {
            trackManager.FindWayPoints();
            trackManager.LightRangeUpdate();
            trackManager.WaypointSoundLevel();
            //trackManager.AddSound();
        }
    }
コード例 #3
0
ファイル: PathTool.cs プロジェクト: lulzzz/3DpointCloud
        /// <summary>
        /// Draw the waypoints & path (circles & lines)
        /// </summary>
        /// <param name="r"></param>
        #region path drawing code

        public void Draw(Renderer r)
        {
            //if only one waypoint, draw the waypoint
            if (newPath.WaypointList.Count == 1 && shouldDraw)
            {
                WaypointRenderer wpFirst   = newPath.WaypointList[0];
                PointF           drawPoint = new PointF((float)wpFirst.X, (float)wpFirst.Y);
                GLUtility.DrawCircle(new GLPen(wpFirst.Color, 1.0f), drawPoint, 0.2f);
                if (!shouldMove && tempActive)
                {
                    GLUtility.DrawLine(new GLPen(Color.LawnGreen, 1.0f), drawPoint, r.ScreenToWorld(mousePoint));
                }
            }

            // if more than one waypoint, draw waypoints and connect subsequent waypoints with a line
            else if (newPath.WaypointList.Count > 1 && shouldDraw)
            {
                WaypointRenderer wpLast = newPath.WaypointList.First();

                foreach (WaypointRenderer wp in newPath.WaypointList)
                {
                    PointF pathPoint = new PointF((float)wp.X, (float)wp.Y);

                    if (shouldMove && wp.Equals(movePointWP))
                    {
                        GLUtility.DrawCircle(new GLPen(Color.Red, 1.0f), pathPoint, 0.2f);
                    }
                    else
                    {
                        GLUtility.DrawCircle(new GLPen(wp.Color, 1.0f), pathPoint, 0.2f);
                    }
                    if (!wp.Equals(newPath.WaypointList.First()))
                    {
                        PointF dummyLast = new PointF((float)wpLast.X, (float)wpLast.Y);
                        GLUtility.DrawLine(new GLPen(newPath.Color, 1.0f), dummyLast, pathPoint);
                    }
                    wpLast = wp;
                }
                // if we are not moving a waypoint, draw a light green line between last waypoint and current mouse location
                if (!shouldMove && tempActive)
                {
                    PointF dummyLast = new PointF((float)wpLast.X, (float)wpLast.Y);
                    GLUtility.DrawLine(new GLPen(Color.LawnGreen, 1.0f), dummyLast, r.ScreenToWorld(mousePoint));
                }
            }

            if (newPath.WaypointList.Count > 0)
            {
                foreach (ISelectable selectable in r.Selectables)
                {
                    PointF        dummyFirst = new PointF();
                    RobotRenderer robot      = selectable as RobotRenderer;
                    if (robot == null)
                    {
                        continue;
                    }
                    else if (robot.IsSelected)
                    {
                        Polygon p = robot.GetBoundingPolygon();
                        if (p.points.Count > 0)
                        {
                            dummyFirst = new PointF((float)newPath.WaypointList[0].X, (float)newPath.WaypointList[0].Y);
                            GLUtility.DrawLine(new GLPen(Color.Green, 1.0f), p.Center.ToPointF(), dummyFirst);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: PathTool.cs プロジェクト: lulzzz/3DpointCloud
        /// <summary>
        /// Operations to perform on MouseDown (takes: Renderer r, MouseEventArgs e)
        ///     On single left click:
        ///         - If not on an existing waypoint, make a new waypoint & execute pathPointAdded event
        ///         - If on an existing waypoint, change shouldMove to true and keep track of waypoint to move
        ///     On double left click:
        ///         - Send path (execute ToolCompleted event) and clear renderer
        ///     On single right click:
        ///         - If on an existing waypoint, delete the waypoint
        ///     On double right click:
        ///         - delete and clear the entire path
        /// </summary>
        /// <param name="r"></param>
        /// <param name="e"></param>
        #region Operations to perform on MouseDown
        public void OnMouseDown(Renderer r, MouseEventArgs e)
        {
            #region Left Click
            //check that button was a left click
            PointF p = r.ScreenToWorld(e.Location);
            if (e.Button == MouseButtons.Left)
            {
                //PointF p = r.ScreenToWorld(e.Location);

                if ((newVersion == true) && (tempActive == true))                 // (new version)
                {
                    if (modeNewWaypoint == true)
                    {
                        if (newPath.WaypointList.Count > 0)
                        {
                            if (!defaultMode.Equals("Send path"))
                            {
                                defaultMode = "Send path";
                                if (UpdateDefault != null)
                                {
                                    UpdateDefault(this, new EventArgs());
                                }
                            }
                            if (modeMoveWaypoint == true)
                            {
                                foreach (WaypointRenderer wp in newPath.WaypointList)
                                {
                                    // move an existing waypoint if we click sufficiently close to it
                                    if ((p.X - wp.X < 0.25) && (p.Y - wp.Y < 0.25) &&
                                        (p.X - wp.X > -0.25) && (p.Y - wp.Y > -0.25))
                                    {
                                        shouldMove      = true;
                                        movePointWP     = wp;
                                        origMovePointWP = wp;
                                        currentCursor   = Cursors.Hand;
                                        myToolManager.SelectTool.TempDeactivate();
                                        if (GestureExpData != null)
                                        {
                                            GestureExpData(this, new GestureExpHRIEventArgs("Tool:PathTool|left click down|move waypoint from|" + e.X + "|" + e.Y + "|(screen)|" + p.X + "|" + p.Y + "|(world)"));
                                        }
                                        break;
                                        //Tool: SelectTool, mode: Select/Deselect, activated using context menu
                                    }
                                }
                            }
                        }
                        if (((newPath.WaypointList.Count > 0) && (shouldMove == false)) || (newPath.WaypointList.Count == 0))
                        {
                            WaypointRenderer newPoint = new WaypointRenderer();

                            if (newPath.WaypointList.Count > 0)
                            {
                                if (GestureExpData != null)
                                {
                                    GestureExpData(this, new GestureExpHRIEventArgs("Tool:PathTool|left click down|add waypoint|" + e.X + "|" + e.Y + "|(screen)|" + p.X + "|" + p.Y + "|(world)"));
                                }
                            }
                            else
                            {
                                if (GestureExpData != null)
                                {
                                    GestureExpData(this, new GestureExpHRIEventArgs("Tool:PathTool|left click down|new path|" + e.X + "|" + e.Y + "|(screen)|" + p.X + "|" + p.Y + "|(world)"));
                                }
                            }
                            newPoint.X = p.X;
                            newPoint.Y = p.Y;
                            newPath.AddWaypoint(newPoint);

                            modeMoveWaypoint = true;
                            if (!defaultMode.Equals("Send path"))
                            {
                                defaultMode = "Send path";
                                if (UpdateDefault != null)
                                {
                                    UpdateDefault(this, new EventArgs());
                                }
                            }
                        }
                        shouldDraw = true;
                    }
                    else if (modeDeleteWaypoint == true)
                    {
                        if (newPath.WaypointList.Count > 0)
                        {
                            foreach (WaypointRenderer wp in newPath.WaypointList)
                            {
                                // if right click is sufficiently close to an existing waypoint, delete it and excecute pathPointRemoved event
                                Vector2 v = new Vector2((float)wp.X, (float)wp.Y);
                                if (!((wp.X - p.X > -.25) && (wp.Y - p.Y > -.25) &&
                                      (wp.X - p.X < .25) && (wp.Y - p.Y < .25)))
                                {
                                    clonePathWP.AddWaypoint(wp);
                                }
                            }
                            newPath = clonePathWP;
                            if (GestureExpData != null)
                            {
                                GestureExpData(this, new GestureExpHRIEventArgs("Tool:PathTool|left click down|delete waypoint|" + e.X + "|" + e.Y + "|(screen)|" + p.X + "|" + p.Y + "|(world)"));
                            }
                            clonePathWP = new PathToRobotRenderer();
                        }
                        if (newPath.WaypointList.Count == 0)
                        {
                            //defaultMode = "Add new waypoint";
                            //modeDeleteWaypoint = false;
                            //modeNewWaypoint = true;
                            if (UpdateDefault != null)
                            {
                                UpdateDefault(this, new EventArgs());
                            }
                        }
                    }
                }
            }
            #endregion

            if (e.Button == MouseButtons.Right)
            {
                //if (GestureExpData != null)
                //    GestureExpData(this, new GestureExpPathToolEventArgs("Tool:PathTool    right click   ---     " + e.X + " " + e.Y + " (screen)    " + p.X + " " + p.Y + " (world)"));
            }
        }