Angle AngleOfCamera(Camera cam)
    {
        Vector3         pillarToPoint       = cam.transform.position - transform.position;
        PolarCoordinate polar               = PolarCoordinate.CartesianToPolar(pillarToPoint);
        PolarCoordinate dimensionShiftPolar = PolarCoordinate.CartesianToPolar(pillar.DimensionShiftVector);

        return(dimensionShiftPolar.angle - polar.angle);
    }
Example #2
0
        Angle GetAngleOfMouse()
        {
            SuperspectiveRaycast raycast = Interact.instance.GetRaycastHits();
            Vector3 mouseLocation        = raycast.hitObject ? raycast.firstObjectHit.point : raycast.finalPosition;
            Vector3 localMouseLocation   = transform.InverseTransformPoint(mouseLocation);

            return(PolarCoordinate.CartesianToPolar(localMouseLocation).angle);
        }
        private void RecalculateOnOffPositions(ObscurePillar unused)
        {
            if (ObscurePillar.activePillar == null)
            {
                onAngle = null; offAngle = null;
                return;
            }

            Vector3[] bounds  = new Vector3[] { thisRenderer.GetRendererBounds().min, thisRenderer.GetRendererBounds().max };
            Vector3[] corners = new Vector3[] {
                new Vector3(bounds[0].x, bounds[0].y, bounds[0].z),
                new Vector3(bounds[0].x, bounds[0].y, bounds[1].z),
                new Vector3(bounds[0].x, bounds[1].y, bounds[0].z),
                new Vector3(bounds[0].x, bounds[1].y, bounds[1].z),
                new Vector3(bounds[1].x, bounds[0].y, bounds[0].z),
                new Vector3(bounds[1].x, bounds[0].y, bounds[1].z),
                new Vector3(bounds[1].x, bounds[1].y, bounds[0].z),
                new Vector3(bounds[1].x, bounds[1].y, bounds[1].z)
            };

            Vector3 centerOfObject = thisRenderer.GetRendererBounds().center;
            Angle   baseAngle      = PolarCoordinate.CartesianToPolar(centerOfObject - ObscurePillar.activePillar.transform.position).angle;

            onAngle  = Angle.Radians(baseAngle.radians + .001f);
            offAngle = Angle.Radians(baseAngle.radians);
            foreach (var corner in corners)
            {
                PolarCoordinate cornerPolar = PolarCoordinate.CartesianToPolar(corner - ObscurePillar.activePillar.transform.position);
                if (!Angle.IsAngleBetween(cornerPolar.angle, offAngle, onAngle))
                {
                    Angle replaceOn  = Angle.AngleBetween(cornerPolar.angle, offAngle);
                    Angle replaceOff = Angle.AngleBetween(cornerPolar.angle, onAngle);
                    if (replaceOn.radians > replaceOff.radians)
                    {
                        onAngle = cornerPolar.angle;
                    }
                    else
                    {
                        offAngle = cornerPolar.angle;
                    }
                }
            }
            onAngle.Reverse();
            offAngle.Reverse();
        }
Example #4
0
            public int Compare(Vector3 a, Vector3 b)
            {
                Vector3 projA = Vector3.ProjectOnPlane(a, normal);
                Vector3 projB = Vector3.ProjectOnPlane(b, normal);
                Vector3 projX = Vector3.ProjectOnPlane(Vector3.right, normal);
                Vector3 projY = Vector3.Cross(normal, projX);

                Vector2 a2D = new Vector2(Vector3.Dot(projA, projX), Vector3.Dot(projA, projY));
                Vector2 b2D = new Vector2(Vector3.Dot(projB, projX), Vector3.Dot(projB, projY));

                PolarCoordinate aPolar = PolarCoordinate.CartesianToPolar(new Vector3(a2D.x, 0, a2D.y));
                PolarCoordinate bPolar = PolarCoordinate.CartesianToPolar(new Vector3(b2D.x, 0, b2D.y));

                if (aPolar.angle.radians == bPolar.angle.radians)
                {
                    return(0);
                }
                else
                {
                    return((aPolar.angle.radians > bPolar.angle.radians) ? 1 : -1);
                }
            }
        private PolarCoordinate CameraToPillar()
        {
            Vector3 pillarToCamera = mainCamera.transform.position - bottomOfPillar;

            return(PolarCoordinate.CartesianToPolar(pillarToCamera));
        }