Пример #1
0
        protected override void OnCopyTo(ShapeInfo target)
        {
            base.OnCopyTo(target);
            LoopShapeInfo c = target as LoopShapeInfo;

            c.vertices = this.vertices != null ? (Vector2[])this.vertices.Clone() : null;
        }
        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.SnapToUserGuides & UserGuideType.Position) != UserGuideType.None)
            {
                localPos = this.EditingUserGuide.SnapPosition(localPos);
            }

            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
            }
        }
 public SelLoopShape(LoopShapeInfo shape)
     : base(shape)
 {
     this.loop = shape;
     this.UpdateLoopStats();
 }
Пример #4
0
        private void DrawShapeOutline(Canvas canvas, Transform transform, LoopShapeInfo shape)
        {
            Vector3 pos = transform.Pos;
            float angle = transform.Angle;
            float scale = transform.Scale;

            if (this.wrapTexture)
            {
                Rect pointBoundingRect = shape.Vertices.BoundingBox();
                canvas.State.TextureCoordinateRect = new Rect(
                    pointBoundingRect.W / canvas.State.TextureBaseSize.X,
                    pointBoundingRect.H / canvas.State.TextureBaseSize.Y);
            }
            canvas.State.TransformAngle = angle;
            canvas.State.TransformScale = new Vector2(scale, scale);
            canvas.FillPolygonOutline(shape.Vertices, this.outlineWidth, pos.X, pos.Y, pos.Z);
        }
Пример #5
0
        private void DrawShapeArea(Canvas canvas, Transform transform, LoopShapeInfo shape)
        {
            // LoopShapes don't have an area. Do nothing here, unless explicitly specified
            if (!this.fillHollowShapes) return;

            Vector3 pos = transform.Pos;
            float angle = transform.Angle;
            float scale = transform.Scale;

            if (this.wrapTexture)
            {
                Rect pointBoundingRect = shape.Vertices.BoundingBox();
                canvas.State.TextureCoordinateRect = new Rect(
                    pointBoundingRect.W / canvas.State.TextureBaseSize.X,
                    pointBoundingRect.H / canvas.State.TextureBaseSize.Y);
            }
            canvas.State.TransformAngle = angle;
            canvas.State.TransformScale = new Vector2(scale, scale);
            canvas.FillPolygon(shape.Vertices, pos.X, pos.Y, pos.Z);
        }
 public RigidBodyEditorSelLoopShape(LoopShapeInfo shape)
     : base(shape)
 {
 }
Пример #7
0
 private void DrawShapeArea(Canvas canvas, Transform transform, LoopShapeInfo shape)
 {
     // LoopShapes don't have an area. Do nothing here.
 }