Exemple #1
0
    public void PositionRaysForFarPosition()
    {
        Vector3 planeNormal  = Lens.GetPlaneNormal();
        Vector3 lensPosition = Lens.transform.localPosition;

        Vector3 parallelDirection = lensPosition - Target.transform.localPosition;

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

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

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

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

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

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

        ParallelVirtualRay.SetActive(false);
        AntiFocalVirtualRay.SetActive(false);
        CenterVirtualRay.SetActive(false);
    }
Exemple #2
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 }
            );
    }
Exemple #3
0
    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();
    }