Exemplo n.º 1
0
        public static bool RaycastWire(Ray ray, out float t, Vector3 circleCenter, float circleRadius, Vector3 circleNormal, CircleEpsilon epsilon = new CircleEpsilon())
        {
            t = 0.0f;
            Plane circlePlane = new Plane(circleNormal, circleCenter);

            float rayEnter;

            if (circlePlane.Raycast(ray, out rayEnter))
            {
                Vector3 intersectPt    = ray.GetPoint(rayEnter);
                float   distFromOrigin = (circleCenter - intersectPt).magnitude;

                if (distFromOrigin >= circleRadius - epsilon.WireEps &&
                    distFromOrigin <= circleRadius + epsilon.WireEps)
                {
                    t = rayEnter;
                    return(true);
                }
            }

            if (epsilon.ExtrudeEps != 0.0f)
            {
                float dot = Vector3Ex.AbsDot(ray.direction, circleNormal);
                if (dot < ExtrudeEpsThreshold.Get)
                {
                    Vector3 cylinderAxisPt0 = circleCenter - circleNormal * epsilon.ExtrudeEps;
                    Vector3 cylinderAxisPt1 = circleCenter + circleNormal * epsilon.ExtrudeEps;
                    return(CylinderMath.Raycast(ray, out t, cylinderAxisPt0, cylinderAxisPt1, circleRadius + epsilon.WireEps));
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public static bool Raycast(Ray ray, out float t, Vector3 circleCenter, float circleRadius, Vector3 circleNormal, CircleEpsilon epsilon = new CircleEpsilon())
        {
            t             = 0.0f;
            circleRadius += epsilon.RadiusEps;
            Plane circlePlane = new Plane(circleNormal, circleCenter);

            float rayEnter;

            if (circlePlane.Raycast(ray, out rayEnter) && (ray.GetPoint(rayEnter) - circleCenter).magnitude <= circleRadius)
            {
                t = rayEnter;
                return(true);
            }

            if (epsilon.ExtrudeEps != 0.0f)
            {
                float dot = Vector3Ex.AbsDot(ray.direction, circleNormal);
                if (dot < ExtrudeEpsThreshold.Get)
                {
                    Vector3 cylinderAxisPt0 = circleCenter - circleNormal * epsilon.ExtrudeEps;
                    Vector3 cylinderAxisPt1 = circleCenter + circleNormal * epsilon.ExtrudeEps;
                    return(CylinderMath.Raycast(ray, out t, cylinderAxisPt0, cylinderAxisPt1, circleRadius));
                }
            }

            return(false);
        }
Exemplo n.º 3
0
 public static bool Contains2DPoint(Vector2 point, Vector2 circleCenter, float circleRadius, CircleEpsilon epsilon = new CircleEpsilon())
 {
     circleRadius += epsilon.RadiusEps;
     return((point - circleCenter).magnitude <= circleRadius);
 }
Exemplo n.º 4
0
        public static bool Is2DPointOnBorder(Vector2 point, Vector2 circleCenter, float circleRadius, CircleEpsilon epsilon = new CircleEpsilon())
        {
            float distFromOrigin = (point - circleCenter).magnitude;

            return(distFromOrigin >= circleRadius - epsilon.WireEps &&
                   distFromOrigin <= circleRadius + epsilon.WireEps);
        }
Exemplo n.º 5
0
        public static bool Contains3DPoint(Vector3 point, bool checkOnPlane, Vector3 circleCenter, float circleRadius, Vector3 circleNormal, CircleEpsilon epsilon = new CircleEpsilon())
        {
            Plane circlePlane = new Plane(circleNormal, circleCenter);

            if (checkOnPlane && circlePlane.GetAbsDistanceToPoint(point) > epsilon.ExtrudeEps)
            {
                return(false);
            }

            circleRadius += epsilon.RadiusEps;
            point         = circlePlane.ProjectPoint(point);

            return((point - circleCenter).magnitude <= circleRadius);
        }