Esempio n. 1
0
        public static bool SetupWorkPlane(Camera camera, Vector3 worldCenterPoint, Vector3 worldDirection, ref CSGPlane workPlane)
        {
            if (camera == null || !camera)
            {
                return(false);
            }

            if (camera.orthographic)
            {
                CSGGrid.ForceGrid = false;
                workPlane         = CSGGrid.CurrentWorkGridPlane;
                return(true);
            }

            var normal = worldDirection;

            /*
             * if (YMoveModeActive)
             * {
             *      var forward = camera.transform.forward;
             *      Vector3 tangent, binormal;
             *      GeometryUtility.CalculateTangents(normal, out tangent, out binormal);
             *      if (Mathf.Abs(Vector3.Dot(forward, tangent)) > Mathf.Abs(Vector3.Dot(forward, binormal)))
             *              normal = tangent;
             *      else
             *              normal = binormal;
             * }*/

            workPlane = new CSGPlane(GridUtility.CleanNormal(normal), worldCenterPoint);
            return(CSGGrid.SetForcedGrid(camera, workPlane));
        }
Esempio n. 2
0
        public static bool SetupRayWorkPlane(Vector3 worldOrigin, Vector3 worldDirection, ref CSGPlane outWorkPlane)
        {
            var camera = Camera.current;

            if (camera == null || !camera)
            {
                return(false);
            }

            Vector3 tangent, normal;
            var     cameraBackwards      = -camera.transform.forward;
            var     closestAxisForward   = GeometryUtility.SnapToClosestAxis(cameraBackwards);
            var     closestAxisDirection = GeometryUtility.SnapToClosestAxis(worldDirection);

            if (Vector3.Dot(closestAxisForward, closestAxisDirection) != 0)
            {
                float dot1 = Mathf.Abs(Vector3.Dot(cameraBackwards, MathConstants.rightVector3));
                float dot2 = Mathf.Abs(Vector3.Dot(cameraBackwards, MathConstants.upVector3));
                float dot3 = Mathf.Abs(Vector3.Dot(cameraBackwards, MathConstants.forwardVector3));
                if (dot1 < dot2)
                {
                    if (dot1 < dot3)
                    {
                        tangent = MathConstants.rightVector3;
                    }
                    else
                    {
                        tangent = MathConstants.forwardVector3;
                    }
                }
                else
                {
                    if (dot2 < dot3)
                    {
                        tangent = MathConstants.upVector3;
                    }
                    else
                    {
                        tangent = MathConstants.forwardVector3;
                    }
                }
            }
            else
            {
                tangent = Vector3.Cross(worldDirection, closestAxisForward);
            }

            if (!camera.orthographic)
            {
                normal = Vector3.Cross(worldDirection, tangent);
            }
            else
            {
                normal = cameraBackwards;
            }

            outWorkPlane = new CSGPlane(GridUtility.CleanNormal(normal), worldOrigin);

            return(CSGGrid.SetForcedGrid(outWorkPlane));
        }