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); }
public static bool RaycastCylindrical(Ray ray, out float t, Vector3 torusCenter, float torusCoreRadius, float torusHrzRadius, float torusVertRadius, Quaternion torusRotation, TorusEpsilon epsilon = new TorusEpsilon()) { t = 0.0f; torusHrzRadius += epsilon.CylHrzRadius; torusVertRadius += epsilon.CylVertRadius; float cylinderRadius = torusCoreRadius + torusHrzRadius; Vector3 torusUp = torusRotation * Vector3.up; Vector3 firstPt = torusCenter - torusUp * torusVertRadius; Vector3 secondPt = torusCenter + torusUp * torusVertRadius; if (CylinderMath.Raycast(ray, out t, firstPt, secondPt, cylinderRadius)) { float torusInnerRadius = torusCoreRadius - torusHrzRadius; Vector3 intersectPt = ray.GetPoint(t); Plane torusCentralPlane = new Plane(torusUp, torusCenter); Vector3 prjIntersectPt = torusCentralPlane.ProjectPoint(intersectPt); if ((prjIntersectPt - torusCenter).magnitude >= torusInnerRadius) { return(true); } cylinderRadius = torusInnerRadius; Ray mirroredRay = ray.Mirror(intersectPt); if (CylinderMath.RaycastNoCaps(mirroredRay, out t, firstPt, secondPt, cylinderRadius)) { t = (ray.origin - mirroredRay.GetPoint(t)).magnitude; return(true); } } return(false); }
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); }
public static bool Raycast(Ray ray, out float t, Vector3 startPoint, Vector3 endPoint, SegmentEpsilon epsilon = new SegmentEpsilon()) { if (CylinderMath.Raycast(ray, out t, startPoint, endPoint, epsilon.RaycastEps)) { return(true); } if (SphereMath.Raycast(ray, out t, startPoint, epsilon.RaycastEps)) { return(true); } return(SphereMath.Raycast(ray, out t, endPoint, epsilon.RaycastEps)); }
public bool ContainsPoint(Vector3 point) { return(CylinderMath.ContainsPoint(point, _baseCenter, TopCenter, _radius, _height, _epsilon)); }
public override bool Raycast(Ray ray, out float t) { return(CylinderMath.Raycast(ray, out t, _baseCenter, TopCenter, _radius, _height, _epsilon)); }
public List <Vector3> GetTopCapExtentPoints() { return(CylinderMath.CalcExtentPoints(TopCenter, _radius, _rotation)); }
public List <Vector3> GetBottomCapExtentPoints() { return(CylinderMath.CalcExtentPoints(_baseCenter, _radius, _rotation)); }