Esempio n. 1
0
    public List <Vector2> OnLightHit(LightType type, float intensity, Vector2 origin, Vector2 destination, Vector2 direction, Collider2D collider, Vector2 normal, float refractiveIndex = 1)
    {
        List <Vector2> laterPoints = new List <Vector2>();
        //laterPoints.Add(destination);
        Vector2 incomingDirection = destination - origin;
        // Amount of incoming vector in the direction of the normal
        Vector2 projection = Vector2.Dot(normal.normalized, incomingDirection) * normal.normalized;

        // Amount of incoming vector perpendicular to normal
        Vector2 perpendicular = incomingDirection - projection;

        // float signedAngleOfIncidence = Vector2.SignedAngle(projection.normalized, incomingDirection.normalized) * Mathf.Deg2Rad;
        // float angleOfIncidence = Mathf.Abs(signedAngleOfIncidence);

        // float angleOfRefraction = Mathf.Asin(refractiveIndex / this.refractiveIndex * Mathf.Sin(angleOfIncidence));
        // n1 sin (t1) = n2 sin (t2)

        Vector2 nextDirection = projection + refractiveIndex / this.refractiveIndex * perpendicular;

        laterPoints.AddRange(LightSim.EmitLight(type, Mathf.Max(intensity, 0), destination, nextDirection, this.refractiveIndex));

        //laterPoints.Add(destination);
        //laterPoints.Add(nextDestination);
        return(laterPoints);
    }
Esempio n. 2
0
    public List <Vector2> OnLightHit(LightType type, float intensity, Vector2 origin, Vector2 destination, Vector2 direction, Collider2D collider, Vector2 normal, float refractiveIndex)
    {
        List <Vector2> laterPoints = new List <Vector2>();

        //laterPoints.Add(destination);
        Vector2 incomingDirection = destination - origin;

        laterPoints.AddRange(LightSim.EmitLight(type, Mathf.Max(intensity, 0), destination, incomingDirection.normalized, refractiveIndex));


        //laterPoints.Add(destination);
        //laterPoints.Add(nextDestination);
        return(laterPoints);
    }
    public List <Vector2> OnLightHit(LightType type, float intensity, Vector2 origin, Vector2 destination, Vector2 direction, Collider2D collider, Vector2 normal, float refractiveIndex)
    {
        List <Vector2> laterPoints = new List <Vector2>();
        //laterPoints.Add(destination);
        Vector2 incomingDirection = destination - origin;
        // Vector2 vectorToOrigin = origin - destination;
        Vector2 projection      = Vector2.Dot(normal.normalized, incomingDirection) * normal.normalized;
        Vector2 nextDestination = destination + incomingDirection - (2 * projection);

        laterPoints.AddRange(LightSim.EmitLightTowards(type, Mathf.Max(intensity, 0), destination, nextDestination));
        // Vector3[] debugPoints = new Vector3[] {
        //     destination.ToVector3(),
        //     nextDestination.ToVector3()
        // };
        //laterPoints.Add(destination);
        //laterPoints.Add(nextDestination);
        return(laterPoints);
    }