Exemple #1
0
        protected override void OnCollectStateDrawcalls(Canvas canvas)
        {
            base.OnCollectStateDrawcalls(canvas);

            GameObject selGameObj   = this.selectedBody != null ? this.selectedBody.GameObj : null;
            Transform  selTransform = selGameObj != null ? selGameObj.Transform : null;

            if (selTransform == null)
            {
                return;
            }

            if (this.mouseState == CursorState.CreatePolygon)
            {
                SelPolyShape selPolyShape = this.allObjSel.OfType <SelPolyShape>().FirstOrDefault();
                if (selPolyShape != null)
                {
                    PolyShapeInfo polyShape      = selPolyShape.ActualObject as PolyShapeInfo;
                    Vector2       lockedPos      = this.createPolyIndex > 0 ? polyShape.Vertices[this.createPolyIndex - 1] : Vector2.Zero;
                    Vector3       lockedPosWorld = selTransform.GetWorldPoint(new Vector3(lockedPos));
                    this.DrawLockedAxes(canvas, lockedPosWorld.X, lockedPosWorld.Y, lockedPosWorld.Z, polyShape.AABB.BoundingRadius * 4);
                }
            }
            else if (this.mouseState == CursorState.CreateLoop)
            {
                SelLoopShape selLoopShape = this.allObjSel.OfType <SelLoopShape>().FirstOrDefault();
                if (selLoopShape != null)
                {
                    LoopShapeInfo loopShape      = selLoopShape.ActualObject as LoopShapeInfo;
                    Vector2       lockedPos      = this.createPolyIndex > 0 ? loopShape.Vertices[this.createPolyIndex - 1] : Vector2.Zero;
                    Vector3       lockedPosWorld = selTransform.GetWorldPoint(new Vector3(lockedPos));
                    this.DrawLockedAxes(canvas, lockedPosWorld.X, lockedPosWorld.Y, lockedPosWorld.Z, loopShape.AABB.BoundingRadius * 4);
                }
            }
        }
Exemple #2
0
        protected override string UpdateActionText()
        {
            Vector2 vertex = Vector2.Zero;

            if (this.mouseState == CursorState.CreatePolygon || this.mouseState == CursorState.CreateLoop)
            {
                Point        mousePos     = this.PointToClient(Cursor.Position);
                GameObject   selGameObj   = this.selectedBody != null ? this.selectedBody.GameObj : null;
                Transform    selTransform = selGameObj != null ? selGameObj.Transform : null;
                SelPolyShape selPolyShape = this.allObjSel.OfType <SelPolyShape>().FirstOrDefault();
                SelLoopShape selLoopShape = this.allObjSel.OfType <SelLoopShape>().FirstOrDefault();
                bool         hasData      = false;
                if (selPolyShape != null)
                {
                    PolyShapeInfo polyShape = selPolyShape.ActualObject as PolyShapeInfo;
                    vertex  = polyShape.Vertices[this.createPolyIndex];
                    hasData = true;
                }
                else if (selLoopShape != null)
                {
                    LoopShapeInfo loopShape = selLoopShape.ActualObject as LoopShapeInfo;
                    vertex  = loopShape.Vertices[this.createPolyIndex];
                    hasData = true;
                }
                else if (selTransform != null)
                {
                    Vector3 spaceCoord = this.GetSpaceCoord(new Vector3(mousePos.X, mousePos.Y, selTransform.Pos.Z));
                    vertex  = selTransform.GetLocalPoint(spaceCoord).Xy;
                    hasData = true;
                }

                if (hasData)
                {
                    return
                        (string.Format("Vertex X:{0,9:0.00}/n", vertex.X) +
                         string.Format("Vertex Y:{0,9:0.00}", vertex.Y));
                }
            }
            return(base.UpdateActionText());
        }
Exemple #3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            Transform selTransform = this.selectedBody != null && this.selectedBody.GameObj != null ? this.selectedBody.GameObj.Transform : null;
            Vector3   spaceCoord   = selTransform != null?this.GetSpaceCoord(new Vector3(e.X, e.Y, selTransform.Pos.Z)) : Vector3.Zero;

            Vector2 localPos = selTransform != null?selTransform.GetLocalPoint(spaceCoord).Xy : Vector2.Zero;

            if (this.mouseState != CursorState.Normal)
            {
                this.UpdateCursorImage();
            }

            if (this.mouseState == CursorState.CreatePolygon && this.allObjSel.Any(sel => sel is SelPolyShape))
            {
                SelPolyShape   selPolyShape = this.allObjSel.OfType <SelPolyShape>().First();
                PolyShapeInfo  polyShape    = selPolyShape.ActualObject as PolyShapeInfo;
                List <Vector2> vertices     = polyShape.Vertices.ToList();
                Vector2        lockedPos    = this.createPolyIndex > 0 ? vertices[this.createPolyIndex - 1] : Vector2.Zero;
                MathF.TransformCoord(ref lockedPos.X, ref lockedPos.Y, selTransform.Angle);
                MathF.TransformCoord(ref localPos.X, ref localPos.Y, selTransform.Angle);
                localPos = this.ApplyAxisLock(localPos, lockedPos);
                MathF.TransformCoord(ref localPos.X, ref localPos.Y, -selTransform.Angle);

                vertices[this.createPolyIndex] = localPos;

                polyShape.Vertices = vertices.ToArray();
                selPolyShape.UpdatePolyStats();

                // Update the body directly after modifying it
                this.selectedBody.SynchronizeBodyShape();

                DualityEditorApp.NotifyObjPropChanged(this,
                                                      new ObjectSelection(this.selectedBody),
                                                      ReflectionInfo.Property_RigidBody_Shapes);
            }
            else if (this.mouseState == CursorState.CreateLoop && this.allObjSel.Any(sel => sel is SelLoopShape))
            {
                SelLoopShape   selPolyShape = this.allObjSel.OfType <SelLoopShape>().First();
                LoopShapeInfo  polyShape    = selPolyShape.ActualObject as LoopShapeInfo;
                List <Vector2> vertices     = polyShape.Vertices.ToList();
                Vector2        lockedPos    = this.createPolyIndex > 0 ? vertices[this.createPolyIndex - 1] : Vector2.Zero;
                MathF.TransformCoord(ref lockedPos.X, ref lockedPos.Y, selTransform.Angle);
                MathF.TransformCoord(ref localPos.X, ref localPos.Y, selTransform.Angle);
                localPos = this.ApplyAxisLock(localPos, lockedPos);
                MathF.TransformCoord(ref localPos.X, ref localPos.Y, -selTransform.Angle);

                vertices[this.createPolyIndex] = localPos;

                polyShape.Vertices = vertices.ToArray();
                selPolyShape.UpdateLoopStats();

                // Update the body directly after modifying it
                this.selectedBody.SynchronizeBodyShape();

                DualityEditorApp.NotifyObjPropChanged(this,
                                                      new ObjectSelection(this.selectedBody),
                                                      ReflectionInfo.Property_RigidBody_Shapes);
            }
        }
Exemple #4
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            GameObject selGameObj   = this.selectedBody != null ? this.selectedBody.GameObj : null;
            Transform  selTransform = selGameObj != null ? selGameObj.Transform : null;

            if (selTransform == null)
            {
                return;
            }

            Vector3 spaceCoord = this.GetSpaceCoord(new Vector3(e.X, e.Y, selTransform.Pos.Z));
            Vector2 localPos   = selTransform.GetLocalPoint(spaceCoord).Xy;

            if (this.mouseState == CursorState.CreateCircle)
            {
                #region CreateCircle
                if (e.Button == MouseButtons.Left)
                {
                    CircleShapeInfo newShape = new CircleShapeInfo(1.0f, localPos, 1.0f);

                    UndoRedoManager.BeginMacro();
                    UndoRedoManager.Do(new CreateRigidBodyShapeAction(this.selectedBody, newShape));

                    this.createAction = true;
                    this.LeaveCursorState();
                    this.SelectObjects(new[] { SelShape.Create(newShape) });
                    this.BeginAction(ObjectAction.Scale);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    this.LeaveCursorState();
                }
                #endregion
            }
            else if (this.mouseState == CursorState.CreatePolygon)
            {
                #region CreatePolygon
                if (e.Button == MouseButtons.Left)
                {
                    bool success = false;
                    if (!this.allObjSel.Any(sel => sel is SelPolyShape))
                    {
                        PolyShapeInfo newShape = new PolyShapeInfo(new Vector2[] { localPos, localPos, localPos }, 1.0f);
                        UndoRedoManager.Do(new CreateRigidBodyShapeAction(this.selectedBody, newShape));
                        this.SelectObjects(new[] { SelShape.Create(newShape) });
                        this.createPolyIndex++;
                    }
                    else
                    {
                        SelPolyShape  selPolyShape = this.allObjSel.OfType <SelPolyShape>().First();
                        PolyShapeInfo polyShape    = selPolyShape.ActualObject as PolyShapeInfo;
                        if (this.createPolyIndex <= 2 || MathF.IsPolygonConvex(polyShape.Vertices))
                        {
                            Vector2 lockedPos = this.createPolyIndex > 0 ? polyShape.Vertices[this.createPolyIndex - 1] : Vector2.Zero;
                            MathF.TransformCoord(ref lockedPos.X, ref lockedPos.Y, selTransform.Angle);
                            MathF.TransformCoord(ref localPos.X, ref localPos.Y, selTransform.Angle);
                            localPos = this.ApplyAxisLock(localPos, lockedPos);
                            MathF.TransformCoord(ref localPos.X, ref localPos.Y, -selTransform.Angle);

                            if (polyShape.Vertices.Length < PolyShapeInfo.MaxVertices)
                            {
                                List <Vector2> vertices = polyShape.Vertices.ToList();

                                vertices[this.createPolyIndex] = localPos;
                                if (this.createPolyIndex >= vertices.Count - 1)
                                {
                                    vertices.Add(localPos);
                                }

                                polyShape.Vertices = vertices.ToArray();
                                selPolyShape.UpdatePolyStats();
                                this.createPolyIndex++;
                            }
                            else
                            {
                                Vector2[] vertices = polyShape.Vertices;

                                vertices[this.createPolyIndex] = localPos;
                                polyShape.Vertices             = vertices;
                                selPolyShape.UpdatePolyStats();

                                this.LeaveCursorState();
                            }
                        }
                    }

                    if (success)
                    {
                        DualityEditorApp.NotifyObjPropChanged(this,
                                                              new ObjectSelection(this.selectedBody),
                                                              ReflectionInfo.Property_RigidBody_Shapes);
                    }
                }
                else if (e.Button == MouseButtons.Right)
                {
                    if (this.allObjSel.Any(sel => sel is SelPolyShape))
                    {
                        SelPolyShape   selPolyShape = this.allObjSel.OfType <SelPolyShape>().First();
                        PolyShapeInfo  polyShape    = selPolyShape.ActualObject as PolyShapeInfo;
                        List <Vector2> vertices     = polyShape.Vertices.ToList();

                        vertices.RemoveAt(this.createPolyIndex);
                        if (vertices.Count < 3 || this.createPolyIndex < 2)
                        {
                            this.DeleteObjects(new SelPolyShape[] { selPolyShape });
                        }
                        else
                        {
                            polyShape.Vertices = vertices.ToArray();
                            selPolyShape.UpdatePolyStats();
                        }

                        DualityEditorApp.NotifyObjPropChanged(this,
                                                              new ObjectSelection(this.selectedBody),
                                                              ReflectionInfo.Property_RigidBody_Shapes);
                    }

                    this.LeaveCursorState();
                }
                #endregion
            }
            else if (this.mouseState == CursorState.CreateLoop)
            {
                #region CreateLoop
                if (e.Button == MouseButtons.Left)
                {
                    bool success = false;
                    if (!this.allObjSel.Any(sel => sel is SelLoopShape))
                    {
                        LoopShapeInfo newShape = new LoopShapeInfo(new Vector2[] { localPos, localPos + Vector2.UnitX, localPos + Vector2.One });
                        UndoRedoManager.Do(new CreateRigidBodyShapeAction(this.selectedBody, newShape));
                        this.SelectObjects(new[] { SelShape.Create(newShape) });
                        success = true;
                    }
                    else
                    {
                        SelLoopShape   selPolyShape = this.allObjSel.OfType <SelLoopShape>().First();
                        LoopShapeInfo  polyShape    = selPolyShape.ActualObject as LoopShapeInfo;
                        List <Vector2> vertices     = polyShape.Vertices.ToList();
                        Vector2        lockedPos    = this.createPolyIndex > 0 ? vertices[this.createPolyIndex - 1] : Vector2.Zero;
                        MathF.TransformCoord(ref lockedPos.X, ref lockedPos.Y, selTransform.Angle);
                        MathF.TransformCoord(ref localPos.X, ref localPos.Y, selTransform.Angle);
                        localPos = this.ApplyAxisLock(localPos, lockedPos);
                        MathF.TransformCoord(ref localPos.X, ref localPos.Y, -selTransform.Angle);

                        vertices[this.createPolyIndex] = localPos;
                        if (this.createPolyIndex >= vertices.Count - 1)
                        {
                            vertices.Add(localPos);
                        }

                        polyShape.Vertices = vertices.ToArray();
                        selPolyShape.UpdateLoopStats();
                        success = true;
                    }

                    if (success)
                    {
                        this.createPolyIndex++;
                        DualityEditorApp.NotifyObjPropChanged(this,
                                                              new ObjectSelection(this.selectedBody),
                                                              ReflectionInfo.Property_RigidBody_Shapes);
                    }
                }
                else if (e.Button == MouseButtons.Right)
                {
                    if (this.allObjSel.Any(sel => sel is SelLoopShape))
                    {
                        SelLoopShape   selPolyShape = this.allObjSel.OfType <SelLoopShape>().First();
                        LoopShapeInfo  polyShape    = selPolyShape.ActualObject as LoopShapeInfo;
                        List <Vector2> vertices     = polyShape.Vertices.ToList();

                        vertices.RemoveAt(this.createPolyIndex);
                        if (vertices.Count < 3 || this.createPolyIndex < 2)
                        {
                            this.DeleteObjects(new SelLoopShape[] { selPolyShape });
                        }
                        else
                        {
                            polyShape.Vertices = vertices.ToArray();
                            selPolyShape.UpdateLoopStats();
                        }

                        DualityEditorApp.NotifyObjPropChanged(this,
                                                              new ObjectSelection(this.selectedBody),
                                                              ReflectionInfo.Property_RigidBody_Shapes);
                    }

                    this.LeaveCursorState();
                }
                #endregion
            }
            //else if (this.mouseState == CursorState.CreateEdge)
            //{
            //    #region CreateEdge
            //    if (e.Button == MouseButtons.Left)
            //    {
            //        bool success = false;
            //        if (!this.allObjSel.Any(sel => sel is SelEdgeShape))
            //        {
            //            EdgeShapeInfo newShape = new EdgeShapeInfo(localPos, localPos + Vector2.UnitX);

            //            this.selectedCollider.AddShape(newShape);
            //            this.SelectObjects(new[] { SelShape.Create(newShape) });
            //            success = true;
            //        }
            //        else
            //        {
            //            SelEdgeShape selEdgeShape = this.allObjSel.OfType<SelEdgeShape>().First();
            //            EdgeShapeInfo edgeShape = selEdgeShape.ActualObject as EdgeShapeInfo;

            //            switch (this.createPolyIndex)
            //            {
            //                case 0:	edgeShape.VertexStart = localPos;	break;
            //                case 1:	edgeShape.VertexEnd = localPos;		break;
            //            }

            //            selEdgeShape.UpdateEdgeStats();
            //            success = true;
            //        }

            //        if (success)
            //        {
            //            this.createPolyIndex++;
            //            DualityEditorApp.NotifyObjPropChanged(this,
            //                new ObjectSelection(this.selectedCollider),
            //                ReflectionInfo.Property_RigidBody_Shapes);

            //            if (this.createPolyIndex >= 2)
            //                this.LeaveCursorState();
            //        }
            //    }
            //    else if (e.Button == MouseButtons.Right)
            //    {
            //        if (this.allObjSel.Any(sel => sel is SelEdgeShape))
            //        {
            //            SelEdgeShape selEdgeShape = this.allObjSel.OfType<SelEdgeShape>().First();
            //            EdgeShapeInfo edgeShape = selEdgeShape.ActualObject as EdgeShapeInfo;

            //            if (this.createPolyIndex < 1)
            //                this.DeleteObjects(new SelEdgeShape[] { selEdgeShape });
            //            else
            //                selEdgeShape.UpdateEdgeStats();

            //            DualityEditorApp.NotifyObjPropChanged(this,
            //                new ObjectSelection(this.selectedCollider),
            //                ReflectionInfo.Property_RigidBody_Shapes);
            //        }

            //        this.LeaveCursorState();
            //    }
            //    #endregion
            //}
        }