Esempio n. 1
0
bool KDTree::nearestIntersection(Ray* p_ray, RayIntersection* p_intersection, KDTreeNode* p_node) {
    if(p_node == NULL || !p_ray->intersects(p_node->bbox, 0, KD_INFINITY)) {
        return false;
    }

    if(p_node->leaf) {
        for(int i = 0; i < p_node->objCount; i++) {
            return p_ray->nearestIntersection(p_node->objList, p_node->objCount, p_intersection);
        }
    }

    RayIntersection intersection1;
    RayIntersection intersection2;
    RayIntersection intersection;

    bool intersects1 = nearestIntersection(p_ray, &intersection1, p_node->child1);
    bool intersects2 = nearestIntersection(p_ray, &intersection2, p_node->child2);

    if(!intersects1 && !intersects2) {
        return false;
    }

    if(!intersects1) {
        intersection = intersection2;
    } else if(!intersects2) {
        intersection = intersection1;
    } else if(intersection1.dist < intersection2.dist) {
        intersection = intersection1;
    } else {
        intersection = intersection2;
    }

    p_intersection->dist = intersection.dist;
    p_intersection->normal = intersection.normal;
    p_intersection->object = intersection.object;
    p_intersection->point = intersection.point;
    p_intersection->uv = intersection.uv;

    return true;
}
Esempio n. 2
0
//*****************************************************************************
//  METHOD: rspfEllipsoid::nearestIntersection
//  
//*****************************************************************************
bool rspfEllipsoid::nearestIntersection(const rspfEcefRay &ray,
                                         rspfEcefPoint& rtnPt) const
{
   return nearestIntersection(ray, 0.0, rtnPt);
}
Esempio n. 3
0
bool KDTree::nearestIntersection(Ray* p_ray, RayIntersection* p_intersection) {
    return nearestIntersection(p_ray, p_intersection, root);
}