Example #1
0
        private bool GetMouseRay(Vector2 point, out Ray ray)
        {
            if (this.activeCamera == null)
            {
                ray = new Mogre.Ray();
                return(false);
            }

            float width  = this.handle.ActualWidth;
            float height = this.handle.ActualHeight;

            ray = ActiveCamera.Camera.GetCameraToViewportRay(point.x / width, point.y / height);
            return(true);
        }
Example #2
0
        public bool PickGizmos(Mogre.Ray ray, ref AxisType axis)
        {
            if (this.gizmoEntities[0] == null || !this.gizmoEntities[0].IsVisible())
            {
                return(false);
            }

            float closesDistance = -1.0f;

            for (int widx = 0; widx < 3; ++widx)
            {
                // get the entity to check
                Mogre.Entity entity = this.gizmoEntities[widx];

                var hit = Mogre.Math.Intersects(ray, entity.GetWorldBoundingBox());
                if (!hit.first)
                {
                    continue;
                }

                bool newClosestFound = FindNewClosest(ray, ref closesDistance, entity);

                // if we found a new closest raycast for this object, update the
                // closestResult befor moving on to the next object
                if (newClosestFound)
                {
                    switch (widx)
                    {
                    case 0:
                        axis = AxisType.X;
                        break;

                    case 1:
                        axis = AxisType.Y;
                        break;

                    case 2:
                        axis = AxisType.Z;
                        break;
                    }
                }
            }

            return(closesDistance >= 0.0f);
        }
Example #3
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);
            }
        }
Example #4
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);
        }
Example #5
0
        private bool GetMouseRay(Vector2 point, out Ray ray)
        {
            if (this.activeCamera == null)
            {
                ray = new Mogre.Ray();
                return false;
            }

            float width = this.handle.ActualWidth;
            float height = this.handle.ActualHeight;
            ray = ActiveCamera.Camera.GetCameraToViewportRay(point.x / width, point.y / height);
            return true;
        }