#include "raig.h"

Raig::Raig()
{
    p = vec3(0,0,0);
    v = vec3(0,0,0);
    incrementMostreig = 0.0;
}


void Raig::calculRaig(int i, int j, double d, int tipusProj, vec3 pw, mat4 MSIV)
{

    vec3 pv;
    vec4 p0, p1, p0mon, p1mon, aux;

    p0 = vec4(0.0,0.0,0.0,1.0);
    p1 = vec4(0.0,0.0,0.0,1.0);

    pv.x = i;
    pv.y = j;

    if(tipusProj == 0 /*PARALLELA*/){
        p0.x = pw.x;
        p0.y = pw.y;
    } else /*PERSPECTIVA*/ {
        p0.x = 0;
        p0.y = 0;
    }
    p0.z = d;

    p0mon = MSIV*p0;
    p1.x = pw.x;
    p1.y = pw.y;
    p1.z = 0;
    p1mon = MSIV*p1;

    p.x = p0mon.x;
    p.y = p0mon.y;
    p.z = p0mon.z;

    aux = normalize(p1mon - p0mon);
    v.x = aux.x;
    v.y = aux.y;
    v.z = aux.z;

}

