コード例 #1
0
        public virtual void DeleteSelectedObject(bool silent)
        {
            BaseEditor selected = MogitorsRoot.Instance.Selected;

            if (selected == null || !selected.Supports(EditFlags.CanDelete))
            {
                return;
            }

            bool cont = false;

            if (!silent)
            {
                string strWarn;
                if (selected.IsNodeType)
                {
                    strWarn = "Are you sure want to delete " + selected.Name + " and all of its children?";
                }
                else if (selected.EditorType == EditorType.Multisel)
                {
                    strWarn = "Are you sure want to delete all selected objects?";
                }
                else
                {
                    strWarn = "Are you sure want to delete " + selected.Name + "?";
                }

                if (MogitorsSystem.Instance.DisplayMessageDialog(strWarn, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    cont = true;
                }
            }
            else
            {
                cont = true;
            }

            if (!cont)
            {
                return;
            }

            BaseEditor delEd = selected;

            if (delEd.EditorType == EditorType.Multisel)
            {
                throw new System.NotImplementedException("Delete MultiSelEditor");
            }
            else
            {
                MogitorsRoot.Instance.DestroyEditorObject(delEd, true);
            }

            EditorAxis = AxisType.None;
        }
コード例 #2
0
        public virtual void OnMouseMove(Vector2 point, MouseDevice mouseDevice, bool imitate)
        {
            this.lastMouseDevice = mouseDevice;

            if (isSettingPos)
            {
                isSettingPos   = false;
                this.lastMouse = point;
                return;
            }

            float deltaX = (point.x - lastMouse.x) * 0.5f;
            float deltaY = (point.y - lastMouse.y) * 0.5f;

            MogitorsRoot mogRoot  = MogitorsRoot.Instance;
            BaseEditor   selected = mogRoot.Selected;

            Ray mouseRay;

            if (!imitate)
            {
                if (mouseDevice.MiddleButton == MouseButtonState.Pressed)
                {
                    Vector3 vPos   = ActiveCamera.DerivedPosition;
                    Vector3 vDelta = new Vector3(deltaX * CameraSpeed / 3.0f, -deltaY * CameraSpeed / 3.0f, 0);
                    ActiveCamera.DerivedPosition = (vPos + (ActiveCamera.DerivedOrientation * vDelta));
                    this.newCamPosition          = Vector3.ZERO;
                    MogitorsSystem.Instance.ShowMouseCursor(false);

                    point.x -= (deltaX * 2.0f);
                    point.y -= (deltaY * 2.0f);

                    isSettingPos = true;
                    MogitorsSystem.Instance.SetMousePosition(point + new Vector2(this.handle.ActualLeft, this.handle.ActualTop));
                }
                else if (mouseDevice.RightButton == MouseButtonState.Pressed)
                {
                    ActiveCamera.Yaw(new Degree(-deltaX / 4.0f));
                    ActiveCamera.Pitch(new Degree(-deltaY / 4.0f));
                    MogitorsSystem.Instance.ShowMouseCursor(false);

                    point.x -= (deltaX * 2.0f);
                    point.y -= (deltaY * 2.0f);

                    isSettingPos = true;
                    MogitorsSystem.Instance.SetMousePosition(point + new Vector2(this.handle.ActualLeft, this.handle.ActualTop));

                    if (!GetMouseRay(point, out mouseRay))
                    {
                        return;
                    }

                    if (mogRoot.Selected != null)
                    {
                        this.lastUsedPlane = MogitorsRoot.Instance.FindGizmoTranslationPlane(mouseRay, EditorAxis);
                    }
                }
            }

            if (!GetMouseRay(point, out mouseRay))
            {
                return;
            }

            if (EditorTool != EditorTools.Rotate || selected == null)
            {
                this.lastMouse = point;
            }

            if (selected != null)
            {
                if (EditorAxis == AxisType.None)
                {
                    AxisType axis = AxisType.None;
                    mogRoot.PickGizmos(mouseRay, ref axis);
                    mogRoot.HighlightGizmo(axis);
                }
                else
                {
                    mogRoot.HighlightGizmo(EditorAxis);
                }
            }

            if (isEditing && selected != null)
            {
                if ((EditorTool == EditorTools.Move) && selected.Supports(EditFlags.CanMove))
                {
                    Vector3 vNewPos = Vector3.ZERO;

                    vNewPos = mogRoot.GetGizmoIntersect(mouseRay, this.lastUsedPlane, EditorAxis, this.lastDerivedPosition);
                    vNewPos = vNewPos - this.last3DDelta + this.lastDerivedPosition;

                    selected.DerivedPosition = vNewPos;
                }
                else if ((EditorTool == EditorTools.Scale) && selected.Supports(EditFlags.CanScale))
                {
                    Vector3 vNewDist = mogRoot.GetGizmoIntersect(mouseRay, this.lastUsedPlane, EditorAxis, this.lastDerivedPosition);
                    Vector3 vScale   = this.lastScale;
                    float   fNewDist = vNewDist.Length;
                    float   fLength  = this.last3DDelta.Length;

                    if ((int)(EditorAxis & AxisType.X) != 0)
                    {
                        vScale.x *= (fNewDist / fLength);
                    }
                    if ((int)(EditorAxis & AxisType.Y) != 0)
                    {
                        vScale.y *= (fNewDist / fLength);
                    }
                    if ((int)(EditorAxis & AxisType.Z) != 0)
                    {
                        vScale.z *= (fNewDist / fLength);
                    }

                    PropertyInfo prop = selected.GetType().GetProperty("Scale");
                    if (prop != null)
                    {
                        prop.SetValue(selected, vScale, null);
                    }
                }
                else if ((EditorTool == EditorTools.Rotate) && selected.Supports(EditFlags.CanRotate))
                {
                    Quaternion q1 = this.lastDerivedOrient;

                    switch (EditorAxis)
                    {
                    case AxisType.X:
                        q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(1, 0, 0));
                        break;

                    case AxisType.Y:
                        q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(0, 1, 0));
                        break;

                    case AxisType.Z:
                        q1 = q1 * new Quaternion(new Degree(-deltaY), new Vector3(0, 0, 1));
                        break;
                    }

                    selected.DerivedOrientation = q1;
                }
            }

            HighlightObjectAtPosition(mouseRay);
        }