public void RayOut(Vector3 origin, Vector3 direction, int currentLinePosition)
    {
        RaycastHit hit;
        Ray        ray = new Ray();

        ray.origin    = origin;
        ray.direction = direction;

        lr.SetPosition(currentLinePosition++, ray.origin);

        if (Physics.Raycast(ray, out hit, 100.0f))
        {
            if (hit.transform.gameObject.tag == "Material")
            {
                RefractableMaterial rm = hit.transform.gameObject.GetComponent <RefractableMaterial>();

                lr.positionCount = currentLinePosition + 4;

                degrees1 = 180 - Vector3.SignedAngle(ray.direction, hit.normal, Vector3.up);
                degrees2 = toDegrees(snellCalculator(lm.rm.GetIndexOfRefraction(), rm.GetIndexOfRefraction(), degrees1));

                rm.text.text =
                    "θ1: " + String.Format("{0:0.000}", degrees1) + "\n" +
                    "θ2: " + String.Format("{0:0.000}", degrees2);

                // render line from laser to point of contact with material
                lr.SetPosition(currentLinePosition++, hit.point);

                RaycastHit hitExit;
                Ray        rayExit = new Ray();

                rayExit.origin    = hit.point - ((Quaternion.AngleAxis(degrees2, Vector3.up) * hit.normal).normalized * 1.5f);
                rayExit.direction = (Quaternion.AngleAxis(degrees2, Vector3.up) * hit.normal).normalized;

                if (Physics.Raycast(rayExit, out hitExit, 10.0f))
                {
                    if (hitExit.transform == hit.transform)
                    {
                        degrees1 = 180 - Vector3.SignedAngle(rayExit.direction, hitExit.normal, Vector3.up);
                        degrees2 = toDegrees(snellCalculator(rm.GetIndexOfRefraction(), lm.rm.GetIndexOfRefraction(), degrees1));

                        // render line from contact point to exit point
                        lr.SetPosition(currentLinePosition++, hitExit.point);

                        RayOut(hitExit.point, direction, currentLinePosition);
                    }
                }
            }
        }
        else
        {
            lr.SetPosition(currentLinePosition, origin + (direction * 100.0f));
        }
    }
Exemplo n.º 2
0
    /*
     * when a new custom index of refraction is entered
     */
    public string NewIndex(RefractableMaterial rm, string input)
    {
        float newRefraction = CheckFieldInputs(input, 0.0f, 10.0f);

        rm.SetCustomRefraction(newRefraction);

        return("" + rm.GetIndexOfRefraction());
    }
Exemplo n.º 3
0
    /*
     * enable UI components for refractable material objects
     */
    public void RunRMUIComponents()
    {
        ShowToggle(false);
        ShowIndexComponents(true);

        objText.text = "Refractable Material";

        RefractableMaterial rm = lm.obj.GetComponent <RefractableMaterial>();

        indexesMenu.value = rm.GetPresetIndex();

        if (indexesMenu.value != (int)RefractableMaterial.IndexesOfRefraction.CUSTOM)
        {
            refractionField.text    = "" + rm.GetIndexOfRefraction();
            refractionField.enabled = false;
        }
        else
        {
            refractionField.enabled = true;
        }
    }