Exemplo n.º 1
0
        private BaseEditor GetObjectUnderMouse(Ray mouseRay, bool pickWidgets, bool pickTerrain)
        {
            Mogre.Entity        result;
            Mogre.Vector3       hitLocation   = new Mogre.Vector3();
            Mogre.RaySceneQuery raySceneQuery = MogitorsRoot.Instance.SceneManager.CreateRayQuery(new Mogre.Ray());
            BaseEditor          selected      = null;

            AxisType editorAxis = AxisType.None;

            if (pickWidgets && MogitorsRoot.Instance.PickGizmos(mouseRay, ref editorAxis))
            {
                selected   = MogitorsRoot.Instance.Selected;
                EditorAxis = editorAxis;
            }
            else
            {
                raySceneQuery.QueryMask = ~QueryFlags.Widget;
                if (MogitorsRoot.Instance.PickEntity(raySceneQuery, mouseRay, out result, hitLocation, "", -1.0f) && result.Name != "HydraxMeshEnt")
                {
                    selected = MogitorsRoot.Instance.FindObject(result.Name, 0);
                }
            }
            MogitorsRoot.Instance.SceneManager.DestroyQuery(raySceneQuery);
            return(selected);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Casts the Ray and gets hitted objects. Hitted objects returns in the list.
        /// </summary>
        /// <param name="arg">The arguments with mouse position.</param>
        /// <returns>The list with hitted objects.</returns>
        private List <MovableObject> SimpleClick(MouseEvent arg)
        {
            using (Mogre.RaySceneQuery raySceneQuery = Game.SceneManager.CreateRayQuery(new Mogre.Ray())) {
                float mouseX = (float)arg.state.X.abs / (float)arg.state.width;
                float mouseY = (float)arg.state.Y.abs / (float)arg.state.height;

                Mogre.Ray mouseRay = cameraMan.getCamera().GetCameraToViewportRay(mouseX, mouseY);
                raySceneQuery.Ray = mouseRay;
                raySceneQuery.SetSortByDistance(true);

                List <MovableObject> list = new List <MovableObject>();
                using (Mogre.RaySceneQueryResult result = raySceneQuery.Execute()) {
                    foreach (Mogre.RaySceneQueryResultEntry entry in result)
                    {
                        list.Add(entry.movable);
                    }
                }
                return(list);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Controls if the mouse is in active area and is not captured. If the left button is pressed
        /// checks if is simple click or the selection rectangle. Selets objects and reports it to GameObjectManager
        /// (OnLeftClick). Else if the right click gets object on clicked point and reports it to GameObjectManager
        /// (OnRightClick).
        /// </summary>
        /// <param Name="arg">The argument of a mouse released.</param>
        /// <param Name="id">The released button</param>
        /// <returns>Always returns true.</returns>
        public bool OnMyMouseReleased(MouseEvent arg, MouseButtonID id)
        {
            if (arg.state.Y.abs > mouseBoundY1 || arg.state.Y.abs < mouseBoundY2 || Game.MouseCaptured)
            {
                StopCameremanMove();
                return(true);
            }
            switch (id)
            {
            case MouseButtonID.MB_Left:
                bSelecting = false;
                if (isRectagularSelect)
                {
                    PerformSelection(mStart, mStop);
                    mRect.Visible      = false;
                    isRectagularSelect = false;
                }
                else
                {
                    GameObjectManager.GetInstance().OnLeftClick(SimpleClick(arg));
                }
                break;

            case MouseButtonID.MB_Right:
                Plane         plane = new Plane(Mogre.Vector3.UNIT_Y, 0);
                Mogre.Vector3 v;
                using (Mogre.RaySceneQuery raySceneQuery = Game.SceneManager.CreateRayQuery(new Mogre.Ray())) {
                    float mouseX = (float)arg.state.X.abs / (float)arg.state.width;
                    float mouseY = (float)arg.state.Y.abs / (float)arg.state.height;

                    Mogre.Ray mouseRay = cameraMan.getCamera().GetCameraToViewportRay(mouseX, mouseY);
                    v = mouseRay.GetPoint(mouseRay.Intersects(plane).second);
                }
                GameObjectManager.GetInstance().OnRightClick(v, SimpleClick(arg));
                break;
            }
            return(true);
        }