Exemplo n.º 1
0
float KRViewport::coverage(const KRAABB &b) const
{
    if(!visible(b)) {
        return 0.0f; // Culled out by view frustrum
    } else {
        KRVector3 nearest_point = b.nearestPoint(getCameraPosition());
        float distance = (nearest_point - getCameraPosition()).magnitude();

        KRVector3 v = KRMat4::DotWDiv(m_matProjection, getCameraPosition() + getCameraDirection() * distance);

        float screen_depth = distance / 1000.0f;

        return KRCLAMP(1.0f - screen_depth, 0.01f, 1.0f);

        /*

        KRVector2 screen_min;
        KRVector2 screen_max;
        // Loop through all corners and transform them to screen space
        for(int i=0; i<8; i++) {
            KRVector3 screen_pos = KRMat4::DotWDiv(m_matViewProjection, KRVector3(i & 1 ? b.min.x : b.max.x, i & 2 ? b.min.y : b.max.y, i & 4 ? b.min.z : b.max.z));
            if(i==0) {
                screen_min = screen_pos.xy();
                screen_max = screen_pos.xy();
            } else {
                if(screen_pos.x < screen_min.x) screen_min.x = screen_pos.x;
                if(screen_pos.y < screen_min.y) screen_min.y = screen_pos.y;
                if(screen_pos.x > screen_max.x) screen_max.x = screen_pos.x;
                if(screen_pos.y > screen_max.y) screen_max.y = screen_pos.y;
            }
        }

        screen_min.x = KRCLAMP(screen_min.x, 0.0f, 1.0f);
        screen_min.y = KRCLAMP(screen_min.y, 0.0f, 1.0f);
        screen_max.x = KRCLAMP(screen_max.x, 0.0f, 1.0f);
        screen_max.y = KRCLAMP(screen_max.y, 0.0f, 1.0f);

        float c = (screen_max.x - screen_min.x) * (screen_max.y - screen_min.y);
        return KRCLAMP(c, 0.01f, 1.0f);
        */
    }
}
Exemplo n.º 2
0
float KRReverbZone::getContainment(const Vector3 &pos)
{
    AABB bounds = getBounds();
    if(bounds.contains(pos)) {
        Vector3 size = bounds.size();
        Vector3 diff = pos - bounds.center();
        diff = diff * 2.0f;
        diff = Vector3::Create(diff.x / size.x, diff.y / size.y, diff.z / size.z);
        float d = diff.magnitude();
        
        if(m_gradient_distance <= 0.0f) {
            // Avoid division by zero
            d = d > 1.0f ? 0.0f : 1.0f;
        } else {
            d = (1.0f - d) / m_gradient_distance;
            d = KRCLAMP(d, 0.0f, 1.0f);
        }
        return d;
        
    } else {
        return 0.0f;
    }
}
Exemplo n.º 3
0
KRVector3 KRAABB::nearestPoint(const KRVector3 & v) const
{
    return KRVector3(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z));
}