public void Initialize(GameObject target, ConcaveMirrorBehaviour mirror) { this.Target = target; this.Mirror = mirror; ParallelRay = CreateRay("Parallel Ray"); CenterRay = CreateRay("Center Ray"); CenterRay.SetActive(false); // Es medio confuso mostrarlo FocalRay = CreateRay("Focal Ray"); ParallelVirtualRay = CreateVirtualRay("Parallel Virtual Ray"); FocalVirtualRay = CreateVirtualRay("Focal Virtual Ray"); PositionRaysForFarPosition(); }
public void Initialize(GameObject target, ConvexMirrorBehaviour mirror) { this.Target = target; this.Mirror = mirror; ParallelRay = CreateRay("Parallel Ray"); CenterRay = CreateRay("Center Ray"); CenterRay.SetActive(false); FocalRay = CreateRay("Focal Ray"); ParallelVirtualRay = CreateVirtualRay("Parallel Virtual Ray"); CenterVirtualRay = CreateVirtualRay("Center Virtual Ray"); CenterVirtualRay.SetActive(false); FocalVirtualRay = CreateVirtualRay("Focal Virtual Ray"); PositionRays(); }
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 } ); }