protected void PositionRays() { // Here we calculate where a ray parallel to the axis meets the mirror Vector3 mirrorCenter = Mirror.GetCenter(); Vector3 parallelDirection = Mirror.transform.localPosition - Target.transform.localPosition; parallelDirection.y = 0; Vector3 parallelHit = GetSphereLineIntersection(Mirror.Radius, mirrorCenter, OriginPoint, parallelDirection)[1]; Vector3 focalPoint = Mirror.GetFocalPoint(); ParallelRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { OriginPoint, parallelHit, 2f * parallelHit - focalPoint } ); Vector3 centerHit = GetSphereLineIntersection(Mirror.Radius, mirrorCenter, OriginPoint, mirrorCenter - OriginPoint)[1]; CenterRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { OriginPoint, centerHit } ); // Here we calculate the intersection between the rays so as to place the virtual image ConvergentPoint = CalculateLinesIntersection( parallelHit, Mirror.GetFocalPoint(), OriginPoint, mirrorCenter ); float virtualImgHeight = ConvergentPoint.y - mirrorCenter.y; // And now we calculate the points for the ray projecting to the focal point Vector3 focalDirection = Mirror.GetFocalPoint() - OriginPoint; Vector3 focalHit = GetSphereLineIntersection(Mirror.Radius, mirrorCenter, OriginPoint, focalDirection)[1]; FocalRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { OriginPoint, focalHit, 1.5f * (focalHit - ConvergentPoint) + focalHit } ); // Now the virtual rays ParallelVirtualRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { parallelHit, focalPoint } ); CenterVirtualRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { centerHit, mirrorCenter } ); FocalVirtualRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { focalHit, focalHit + parallelDirection } ); }
public void PositionRaysForFarPosition() { // Here we calculate where a ray parallel to the axis meets the mirror Vector3 mirrorCenter = Mirror.GetCenter(); Vector3 parallelDirection = Mirror.transform.position - Target.transform.position; parallelDirection.y = 0; Vector3 parallelHit = GetSphereLineIntersection(Mirror.Radius, mirrorCenter, FarOriginPoint, parallelDirection)[0]; Vector3 focalDirection = Mirror.GetFocalPoint() - FarOriginPoint; Vector3 focalHit = GetSphereLineIntersection(Mirror.Radius, mirrorCenter, FarOriginPoint, focalDirection)[0]; // Here we calculate the intersection between the rays so as to place the virtual image ConvergingPoint = CalculateLinesIntersection( parallelHit, Mirror.GetFocalPoint(), focalHit, focalHit + parallelDirection ); // And now we set the rays points ParallelRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { FarOriginPoint, parallelHit, 1.3f * (ConvergingPoint - parallelHit) + parallelHit } ); Vector3 centerHit = GetSphereLineIntersection(Mirror.Radius, mirrorCenter, FarOriginPoint, FarOriginPoint - mirrorCenter)[0]; CenterRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { FarOriginPoint, ConvergingPoint } ); FocalRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { FarOriginPoint, focalHit, 1.3f * (ConvergingPoint - focalHit) + focalHit } ); ParallelVirtualRay.SetActive(false); FocalVirtualRay.SetActive(false); }