Пример #1
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);
        }
Пример #2
0
        public override SceneFileResult Import(string importFile)
        {
            MogitorsRoot   mogRoot = MogitorsRoot.Instance;
            MogitorsSystem system  = MogitorsSystem.Instance;

            if (importFile == "")
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName   = "";
                dlg.DefaultExt = ".mogscene";
                dlg.Filter     = "Mogitor Scene File (.mogscene)|*.mogscene";
                Nullable <bool> result = dlg.ShowDialog();
                if (result != true)
                {
                    return(SceneFileResult.Cancel);
                }
                importFile = dlg.FileName;
            }

            string filePath = system.ExtractFilePath(importFile);
            string fileName = system.ExtractFileName(importFile);

            XmlTextReader textReader = new XmlTextReader(importFile);

            system.UpdateLoadProgress(5, "Loading scene objects");

            if (!textReader.ReadToFollowing("MogitorScene"))
            {
                return(SceneFileResult.ErrParse);
            }

            // Check version
            string fileVersion = textReader.GetAttribute("Version");

            if (fileVersion != null)
            {
                if (int.Parse(fileVersion) != 1)
                {
                    return(SceneFileResult.ErrParse);
                }
            }

            // Read project options
            if (textReader.ReadToFollowing("ProjectOptions") == true)
            {
                system.UpdateLoadProgress(15, "Parsing project options");
                mogRoot.LoadProjectOptions(textReader);

                mogRoot.ProjectOptions.ProjectDir  = filePath;
                mogRoot.ProjectOptions.ProjectName = fileName;

                mogRoot.PrepareProjectResources();
            }

            //// Moves the reader back to the "MogitorScene" element node.
            //textReader.MoveToElement();

            system.UpdateLoadProgress(30, "Creating scene objects");

            // Load objects
            Mogre.NameValuePairList param = new Mogre.NameValuePairList();
            while (textReader.ReadToNextSibling("Object"))
            {
                string objectType = textReader.GetAttribute("Type");
                if (objectType == "")
                {
                    continue;
                }

                param.Clear();
                while (textReader.MoveToNextAttribute())
                {
                    param.Insert(textReader.Name, textReader.Value);
                }

                BaseEditor result = MogitorsRoot.Instance.CreateEditorObject(null, objectType, param, false, false);
            }

            mogRoot.AfterLoadScene();

            return(SceneFileResult.Ok);
        }
Пример #3
0
        public override SceneFileResult Export(bool saveAs)
        {
            MogitorsRoot   mogRoot = MogitorsRoot.Instance;
            MogitorsSystem system  = MogitorsSystem.Instance;

            ProjectOptions opt      = mogRoot.ProjectOptions;
            string         fileName = system.CombinePath(opt.ProjectDir, opt.ProjectName + ".mogscene");

            // If saveAs is true, use the MogitorsSystem Function to retrieve
            // a FileName and also copy the contents of current scene to the new location
            if (saveAs)
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName   = "";
                dlg.DefaultExt = ".mogscene";
                dlg.Filter     = "Mogitor Scene File (.mogscene)|*.mogscene";

                Nullable <bool> result = dlg.ShowDialog();
                if (result != true)
                {
                    return(SceneFileResult.Cancel);
                }

                fileName = dlg.FileName;

                string oldProjDir  = opt.ProjectDir;
                string oldProjName = opt.ProjectName;

                opt.ProjectName = system.ExtractFileName(fileName);
                opt.ProjectDir  = system.ExtractFilePath(fileName);

                mogRoot.AdjustUserResourceDirectories(oldProjDir);

                string newDir = opt.ProjectDir;

                system.MakeDirectory(newDir);
                system.CopyFilesEx(oldProjDir, newDir);

                string delFileStr = system.GetFullPath(system.CombinePath(opt.ProjectDir, oldProjName + ".mogscene"));
                system.DeleteFile(delFileStr);
            }

            XmlTextWriter textWriter = new XmlTextWriter(fileName, System.Text.Encoding.Unicode);

            textWriter.Formatting = Formatting.Indented;
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("MogitorScene");
            mogRoot.WriteProjectOptions(textWriter, true);

            ObjectVector objectList = new ObjectVector();

            for (EditorType type = 0; type < EditorType.LastEditor; ++type)
            {
                mogRoot.GetObjectList(type, objectList);
                foreach (BaseEditor obj in objectList)
                {
                    // If object does not have a parent, then it is not part of the scene
                    if (obj.Parent == null)
                    {
                        continue;
                    }

                    if (obj.IsSerializable)
                    {
                        textWriter.WriteStartElement("Object");
                        textWriter.WriteStartAttribute("Type");
                        textWriter.WriteValue(obj.ObjectTypeName);
                        textWriter.WriteEndAttribute();

                        // If obj's parent name is "" then the parent is this.rootEditor
                        if (obj.Parent.Name != "")
                        {
                            textWriter.WriteStartAttribute("ParentNode");
                            textWriter.WriteValue(obj.Parent.Name);
                            textWriter.WriteEndAttribute();
                        }
                        Mogre.NameValuePairList theList = new Mogre.NameValuePairList();
                        obj.GetObjectProperties(theList);
                        foreach (KeyValuePair <string, string> it in theList)
                        {
                            textWriter.WriteStartAttribute(it.Key);
                            textWriter.WriteValue(it.Value);
                            textWriter.WriteEndAttribute();
                        }
                        textWriter.WriteEndElement();
                    }
                    obj.OnSave();
                }
            }

            textWriter.WriteEndElement();
            textWriter.WriteEndDocument();
            textWriter.Close();

            mogRoot.IsSceneModified = false;

            if (saveAs)
            {
                mogRoot.TerminateScene();
                mogRoot.LoadScene(fileName);
            }
            return(SceneFileResult.Ok);
        }
Пример #4
0
        private void SetupMogre(string pluginFileName, string configFileName, string logFileName)
        {
            // Create the main mogre object
            this.mogreRoot = new Mogre.Root(pluginFileName);

            Mogre.LogManager.Singleton.SetLogDetail(Mogre.LoggingLevel.LL_BOREME);

            SetupMogreResources();

            SetupDirectX();

            // Initialize without creating window
            this.mogreRoot.Initialise(false);   // don't create a window

            this.mogitorsRoot = MogitorsRoot.Instance;
        }