Exemplo n.º 1
0
const Drawable *Scene::Intersect(const Ray &ray)
{
    bool hit = false;
    Vector3d closestPos = 0;
    Drawable *closest = NULL;

    for (std::vector<Drawable *>::const_iterator i = m_DrawableList.begin(); i != m_DrawableList.end(); i++) {
        Drawable *d = *i;

        Vector3d pos;
        Vector3d normal;
        if (d->Intersect(ray, pos, normal)) {
//              std::cout << "collision ray " << ray << " pos " << pos << std::endl;
            if (!hit || (pos - ray.origin).LengthSquared() < (closestPos - ray.origin).LengthSquared()) {
                closestPos = pos;
                closest = d;
            }
            hit = true;
        }
    }

    if (hit)
        return closest;

    return NULL;
}
Exemplo n.º 2
0
bool Scene::DoesIntersect(const Ray &ray)
{
    for (std::vector<Drawable *>::const_iterator i = m_DrawableList.begin(); i != m_DrawableList.end(); i++) {
        Drawable *d = *i;

        if (d->Intersect(ray)) {
            return true;
        }
    }

    return false;
}
Exemplo n.º 3
0
bool Scene::DoesIntersect(const Ray &ray, double maxDistance)
{
    for (std::vector<Drawable *>::const_iterator i = m_DrawableList.begin(); i != m_DrawableList.end(); i++) {
        Drawable *d = *i;

        Vector3d pos;
        Vector3d normal;
        if (d->Intersect(ray, pos, normal)) {
            if ((ray.origin - pos).Length() < maxDistance)
                return true;
        }
    }

    return false;
}