public void PositionRays() { Vector3 planeNormal = Lens.GetPlaneNormal(); Vector3 lensPosition = Lens.transform.localPosition; Vector3 parallelDirection = lensPosition - Target.transform.localPosition; parallelDirection.y = 0; Vector3 parallelHit = GetPlaneLineIntersection(planeNormal, lensPosition, OriginPoint, parallelDirection); Vector3 focusDirection = Lens.GetFocusPosition() - OriginPoint; Vector3 focusHit = GetPlaneLineIntersection(planeNormal, lensPosition, OriginPoint, focusDirection); ConvergingPoint = CalculateLinesIntersection( parallelHit, Lens.GetAntiFocusPosition(), focusHit, focusHit + parallelDirection ); ParallelRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { OriginPoint, parallelHit, 0.5f * (parallelHit - Lens.GetAntiFocusPosition()) + parallelHit } ); FocalRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { OriginPoint, focusHit, focusHit + parallelDirection * 0.5f } ); ParallelVirtualRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { focusHit, focusHit - parallelDirection } ); AntifocalVirtualRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { parallelHit, Lens.GetAntiFocusPosition() } ); }
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 PositionRaysForNearPosition() { // 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, NearOriginPoint, parallelDirection)[0]; Vector3 focalDirection = Mirror.GetFocalPoint() - NearOriginPoint; Vector3 focalHit = GetSphereLineIntersection(Mirror.Radius, mirrorCenter, NearOriginPoint, focalDirection)[1]; // 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[] { NearOriginPoint, parallelHit, Mirror.GetFocalPoint() } ); CenterRay.SetActive(false); FocalRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { NearOriginPoint, focalHit, focalHit - parallelDirection } ); ParallelVirtualRay.SetActive(true); ParallelVirtualRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { parallelHit, ConvergingPoint } ); Vector3 centerHit = GetSphereLineIntersection( Mirror.Radius, mirrorCenter, NearOriginPoint, mirrorCenter )[1]; FocalVirtualRay.SetActive(true); FocalVirtualRay.GetComponent <TubeRenderer>().SetPositions( new Vector3[] { focalHit, focalHit + parallelDirection } ); }