Пример #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 }
            );
    }
Пример #2
0
    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 }
            );
    }