コード例 #1
0
        /// <summary>
        /// Finds the sector the mouse is in (or -1 if it's within the center)
        /// </summary>
        /// <returns>Index of the sector, or -1 if it's within the center.</returns>
        /// <param name="centerPosition">Center position.</param>
        static int GetIndex(Vector2 radialCenterPosition)
        {
            // Number of sectors (or slices) the circle is cut into
            int angleCount = messages.Length;

            // Convert the mouse position to scene view space
            Vector2 mousePosition = EditorHelper.ConvertMousePointPosition(Event.current.mousePosition);

            int highlightIndex = -1;             // Default to no sector matched (cancel)

            // If the mouse is far enough from the center to give a definitive result
            if (Vector2.Distance(mousePosition, radialCenterPosition) > MIN_DISTANCE)
            {
                Vector2 relativePosition = mousePosition - radialCenterPosition;
                float   angle            = Mathf.Atan2(relativePosition.x, relativePosition.y) * Mathf.Rad2Deg;
                // Make sure angle is in the 0 to 360 range, so we can easily quantize it
                if (angle < 0)
                {
                    angle += 360;
                }
                highlightIndex = Mathf.RoundToInt(angle / (360f / angleCount));

                // Loop back if the index has overflowed (as the first sector contains both 1 degree and 359 degrees)
                if (highlightIndex >= angleCount)
                {
                    highlightIndex -= angleCount;
                }
            }
            return(highlightIndex);
        }
コード例 #2
0
ファイル: SabreGraphics.cs プロジェクト: Inmigondra/Poisson
        public static void DrawMarquee(Vector2 marqueeStart, Vector2 marqueeEnd)
        {
            Vector2 point1 = EditorHelper.ConvertMousePointPosition(marqueeStart);
            Vector2 point2 = EditorHelper.ConvertMousePointPosition(marqueeEnd);

            Rect rect = new Rect(point1.x, point1.y, point2.x - point1.x, point2.y - point1.y);

            SabreCSGResources.GetSelectedBrushMaterial().SetPass(0);

            GL.PushMatrix();
            GL.LoadPixelMatrix();

            GL.Begin(GL.QUADS);
            GL.Color(new Color(0.2f, 0.3f, 0.8f, 0.3f));

            // Marquee fill (draw double sided)
            SabreGraphics.DrawScreenRectFill(rect);

            GL.End();

            // Marquee border
            GL.Begin(GL.LINES);
            GL.Color(Color.white);

            // Draw marquee box edges
            SabreGraphics.DrawScreenRectOuter(rect);

            GL.End();
            GL.PopMatrix();
        }
コード例 #3
0
ファイル: DrawEditor.cs プロジェクト: Inmigondra/Poisson
        Vector3?GetHitPoint(Vector2 currentPosition)
        {
            // Conver the mouse position into a ray to intersect with a plane in the world
            Ray currentRay = Camera.current.ScreenPointToRay(EditorHelper.ConvertMousePointPosition(currentPosition));

            // Find the currently active plane
            Plane plane = GetActivePlane();

            // If we hit the plane, return the hit point, otherwise return null
            float distance;

            if (plane.Raycast(currentRay, out distance))
            {
                Vector3 hitPoint = currentRay.GetPoint(distance);

                if (CurrentSettings.PositionSnappingEnabled)
                {
                    hitPoint = MathHelper.RoundVector3(hitPoint, CurrentSettings.PositionSnapDistance);
                }
                return(hitPoint);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        private Vector3?GetHitPoint(Vector2 currentPosition)
        {
            // Conver the mouse position into a ray to intersect with a plane in the world
            Ray currentRay = Camera.current.ScreenPointToRay(EditorHelper.ConvertMousePointPosition(currentPosition));

            // Find the currently active plane
            Plane plane = GetActivePlane();

            // If we hit the plane, return the hit point, otherwise return null
            float distance;

            if (plane.Raycast(currentRay, out distance))
            {
                Vector3 hitPoint = currentRay.GetPoint(distance);

                if (CurrentSettings.PositionSnappingEnabled)
                {
                    Polygon activePolygon = GetActivePolygon();

                    if (activePolygon != null)
                    {
                        // Rotation to go from the polygon's plane to XY plane (for sorting)
                        Quaternion cancellingRotation = Quaternion.Inverse(Quaternion.LookRotation(plane.normal));
                        Quaternion restoringRotation  = Quaternion.LookRotation(plane.normal);
                        hitPoint -= activePolygon.GetCenterPoint();
                        Vector3 localHitPoint = cancellingRotation * hitPoint;
                        // Round in local space
                        localHitPoint = MathHelper.RoundVector3(localHitPoint, CurrentSettings.PositionSnapDistance);
                        // Convert back to correct space
                        hitPoint  = restoringRotation * localHitPoint;
                        hitPoint += activePolygon.GetCenterPoint();
                    }
                    else
                    {
                        hitPoint = MathHelper.RoundVector3(hitPoint, CurrentSettings.PositionSnapDistance);
                    }
                }
                return(hitPoint);
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
        private void OnMouseMoveSelectHeight(SceneView sceneView, Event e)
        {
            Rect pixelRect = sceneView.camera.pixelRect;

            // Resize a handle
            Vector2 currentPosition = e.mousePosition;

            // Clamp the current position to the screen rect. Otherwise we get some odd problems if you carry on
            // resizing off screen.
            currentPosition.x = Mathf.Clamp(currentPosition.x, pixelRect.xMin, pixelRect.xMax);
            currentPosition.y = Mathf.Clamp(currentPosition.y, pixelRect.yMin, pixelRect.yMax);

            Vector2 lastPosition = currentPosition - e.delta;

            Ray lastRay = Camera.current.ScreenPointToRay(EditorHelper.ConvertMousePointPosition(lastPosition));

            Ray     currentRay = Camera.current.ScreenPointToRay(EditorHelper.ConvertMousePointPosition(currentPosition));
            Vector3 direction  = GetActivePlane().normal;

            Vector3 lineStart = hitPoints[0];
            Vector3 lineEnd   = hitPoints[0] + direction;

            Vector3 lastPositionWorld    = MathHelper.ClosestPointOnLine(lastRay, lineStart, lineEnd);
            Vector3 currentPositionWorld = MathHelper.ClosestPointOnLine(currentRay, lineStart, lineEnd);

            Vector3 deltaWorld = (currentPositionWorld - lastPositionWorld);

            float deltaScale   = Vector3.Dot(direction, deltaWorld);
            float snapDistance = CurrentSettings.PositionSnapDistance;

            if (CurrentSettings.PositionSnappingEnabled)
            {
                deltaScale += unroundedPrismHeight;
                float roundedDeltaScale = MathHelper.RoundFloat(deltaScale, snapDistance);

                unroundedPrismHeight = deltaScale - roundedDeltaScale;
                deltaScale           = roundedDeltaScale;
            }

            prismHeight += deltaScale;

            SceneView.RepaintAll();
        }
コード例 #6
0
 private PolygonRaycastHit?CalculateHitPolygon(Vector2 currentPosition)
 {
     if (EditorHelper.GetSceneViewCamera(SceneView.lastActiveSceneView) == EditorHelper.SceneViewCamera.Other)
     {
         // Convert the mouse position into a ray to intersect with a plane in the world
         Ray currentRay = Camera.current.ScreenPointToRay(EditorHelper.ConvertMousePointPosition(currentPosition));
         List <PolygonRaycastHit> hits = csgModel.RaycastBrushesAll(currentRay, false);
         if (hits.Count > 0)
         {
             return(hits[0]);
         }
         else
         {
             return(null);
         }
     }
     else
     {
         // If the scene view is axis-aligned iso then we don't raycast polygons
         return(null);
     }
 }
コード例 #7
0
ファイル: SabreMouse.cs プロジェクト: aydenlimyip/SHARED_SHOT
        public static bool MarqueeContainsPoint(Vector2 marqueeStart, Vector2 marqueeEnd, Vector3 screenPoint)
        {
            Vector2 point1 = EditorHelper.ConvertMousePointPosition(marqueeStart);
            Vector2 point2 = EditorHelper.ConvertMousePointPosition(marqueeEnd);

            float minX = Mathf.Min(point1.x, point2.x);
            float maxX = Mathf.Max(point1.x, point2.x);

            float minY = Mathf.Min(point1.y, point2.y);
            float maxY = Mathf.Max(point1.y, point2.y);

            if (screenPoint.z > 0 &&
                screenPoint.x > minX && screenPoint.x < maxX &&
                screenPoint.y > minY && screenPoint.y < maxY)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #8
0
        void OnMouseAction3D(SceneView sceneView, Event e)
        {
            if (primaryTargetBrush == null || CameraPanInProgress || e.button != 0)
            {
                return;
            }

            Vector2 mousePosition = e.mousePosition;

            mousePosition = EditorHelper.ConvertMousePointPosition(mousePosition);

            Ray   ray          = Camera.current.ScreenPointToRay(mousePosition);
            float bestDistance = float.PositiveInfinity;

            Polygon bestPolygon = null;

            float testDistance;

            foreach (Brush brush in targetBrushes)
            {
                List <Polygon> polygons    = brush.GenerateTransformedPolygons().ToList();
                Polygon        testPolygon = GeometryHelper.RaycastPolygons(polygons, ray, out testDistance, 0.1f);
                if (testPolygon != null && testDistance < bestDistance)
                {
                    bestDistance = testDistance;
                    bestPolygon  = testPolygon;
                }
            }

            if (bestPolygon != null)
            {
//				VisualDebug.ClearAll();
//				VisualDebug.AddPolygon(hitPolygon, Color.red);
                Vector3 hitPoint = ray.GetPoint(bestDistance);

                if (e.type == EventType.MouseDown || e.type == EventType.MouseMove)
                {
                    if (e.type == EventType.MouseMove && planeEstablished)
                    {
                        return;
                    }

                    points[0]    = hitPoint;
                    displayPoint = true;

                    if (CurrentSettings.PositionSnappingEnabled)
                    {
                        float snapDistance = CurrentSettings.PositionSnapDistance;
                        points[0] = MathHelper.RoundVector3(points[0], snapDistance);
                    }

                    points[1] = points[0];
                    points[2] = points[0];

                    isFlipped = false;
                }
                else
                {
                    points[1] = hitPoint;

                    if (CurrentSettings.PositionSnappingEnabled)
                    {
                        float snapDistance = CurrentSettings.PositionSnapDistance;
                        points[1] = MathHelper.RoundVector3(points[1], snapDistance);
                    }
                    points[2] = points[0] - bestPolygon.Plane.normal;

                    if (e.type == EventType.MouseUp)
                    {
                        planeEstablished = true;

                        if (points[1] == points[0])
                        {
                            ResetTool();
                        }
                    }
                }
                SceneView.RepaintAll();
            }
        }
コード例 #9
0
        void OnMouseActionOrthographic(SceneView sceneView, Event e)
        {
            if (primaryTargetBrush == null || CameraPanInProgress || e.button != 0)
            {
                return;
            }


            if (EditorHelper.IsMousePositionNearSceneGizmo(e.mousePosition))
            {
                return;
            }

            Vector2 mousePosition = e.mousePosition;

            mousePosition = EditorHelper.ConvertMousePointPosition(mousePosition);

            Ray ray = Camera.current.ScreenPointToRay(mousePosition);

            Plane   plane = new Plane(sceneView.camera.transform.forward, primaryTargetBrushTransform.position);
            Vector3 worldPoint;             // This is the point on the plane that is perpendicular to the camera
            float   distance = 0;

            if (plane.Raycast(ray, out distance))
            {
                worldPoint = ray.GetPoint(distance);
            }
            else
            {
                return;
            }

            if (e.type == EventType.MouseDown || e.type == EventType.MouseMove)
            {
                if (e.type == EventType.MouseMove && planeEstablished)
                {
                    return;
                }

                points[0]    = worldPoint;
                displayPoint = true;

                if (CurrentSettings.PositionSnappingEnabled)
                {
                    float snapDistance = CurrentSettings.PositionSnapDistance;
                    points[0] = MathHelper.RoundVector3(points[0], snapDistance);
                }

                points[1] = points[0];
                points[2] = points[0];

                isFlipped = false;
            }
            else
            {
                points[1] = worldPoint;

                if (CurrentSettings.PositionSnappingEnabled)
                {
                    float snapDistance = CurrentSettings.PositionSnapDistance;
                    points[1] = MathHelper.RoundVector3(points[1], snapDistance);
                }
                points[2] = points[0] + sceneView.camera.transform.forward;

                if (e.type == EventType.MouseUp)
                {
                    planeEstablished = true;

                    if (points[1] == points[0])
                    {
                        ResetTool();
                    }
                }
            }
            SceneView.RepaintAll();
        }