Example #1
0
    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 }
            );
    }
Example #2
0
    public void PositionRaysForNearPosition()
    {
        Vector3 planeNormal  = Lens.GetPlaneNormal();
        Vector3 lensPosition = Lens.transform.localPosition;

        Vector3 parallelDirection = lensPosition - Target.transform.localPosition;

        parallelDirection.y = 0;
        Vector3 parallelHit = GetPlaneLineIntersection(planeNormal, lensPosition, NearOriginPoint, parallelDirection);

        Vector3 antifocusDirection = Lens.GetAntiFocusPosition() - NearOriginPoint;
        Vector3 antifocusHit       = GetPlaneLineIntersection(planeNormal, lensPosition, NearOriginPoint, antifocusDirection);

        ConvergingPoint = CalculateLinesIntersection(
            parallelHit, Lens.GetFocusPosition(), antifocusHit, antifocusHit + parallelDirection
            );


        ParallelRay.GetComponent <TubeRenderer>().SetPositions(
            new Vector3[] { NearOriginPoint, parallelHit, Lens.GetFocusPosition() }
            );

        CenterRay.GetComponent <TubeRenderer>().SetPositions(
            new Vector3[] { NearOriginPoint, lensPosition }
            );

        AntiFocalRay.GetComponent <TubeRenderer>().SetPositions(
            new Vector3[] { NearOriginPoint, antifocusHit, antifocusHit + parallelDirection * 0.5f }
            );

        ParallelVirtualRay.SetActive(true);
        AntiFocalVirtualRay.SetActive(true);
        CenterVirtualRay.SetActive(true);

        ParallelVirtualRay.GetComponent <TubeRenderer>().SetPositions(
            new Vector3[] { antifocusHit, ConvergingPoint }
            );

        AntiFocalVirtualRay.GetComponent <TubeRenderer>().SetPositions(
            new Vector3[] { parallelHit, ConvergingPoint }
            );

        CenterVirtualRay.GetComponent <TubeRenderer>().SetPositions(
            new Vector3[] { NearOriginPoint, ConvergingPoint }
            );
    }