Exemplo n.º 1
0
bool tri::intersect(ray & _r, float & t) {
    //calculate t first
    t = inner_product(p[0] - _r.origin, nrml) / inner_product(_r.dir, nrml);
    if (t < 0)
        return false;
    //check inside the tri
    point x = _r.get_t(t);
    vect v2_1 = p[1] - p[0];
    vect v3_2 = p[2] - p[1];
    vect v1_3 = p[0] - p[2];
    vect vx_1 = x - p[0];
    vect vx_2 = x - p[1];
    vect vx_3 = x - p[2];
    /*special judge for debug
    if(abs(x.x) > 500 || abs(x.z) > 500)
        return false;
    return true;
     */
    if (inner_product(cross_product(v2_1, vx_1), nrml) > 0
        && inner_product(cross_product(v3_2, vx_2), nrml) > 0
        && inner_product(cross_product(v1_3, vx_3), nrml) > 0) {
        return true;
    }
    return false;
}