Ejemplo n.º 1
0
bool Frustum::IntersectsBox(const AlignedBox& box, bool precise) const
{
    MATH_FUNCTION_TIMER();

    if ( fabs((box.maximum - box.minimum).Length()) < LinearIntersectionError )
    {
        return IntersectsPoint( box.Center() );
    }
    else
    {
        f32 m, n;
        Vector3 c = box.Center();
        Vector3 d = box.maximum - c;

        for (i32 i=0; i<6; i++)
        {
            const Plane& p = (*this)[i];

            m = (c.x * p.A()) + (c.y * p.B()) + (c.z * p.C()) + p.D();
            n = (d.x * abs(p.A())) + (d.y * abs(p.B())) + (d.z * abs(p.C()));

            if (m + n < 0)
            {
                return false;
            }
        }

        if ( precise )
        {
#pragma TODO("This precise test should be using separated axis testing instead of triangle decimation")
            V_Vector3 vertices;
            vertices.reserve(8);
            box.GetVertices(vertices);

            V_Vector3 triangleList;
            triangleList.reserve(36);
            AlignedBox::GetTriangulated(vertices, triangleList);

            for ( int i=0; i<36; i+=3 )
            {
                if ( IntersectsTriangle( triangleList[i], triangleList[i+1], triangleList[i+2] ) )
                {
                    return true;
                }
            }

            return false;
        }
    }

    return true;
}
Ejemplo n.º 2
0
bool FrustumPickVisitor::AddHitBox(const AlignedBox& box)
{
	// allocate a hit
	PickHit* hit = AddHit();

	// our intersection point is the center point (HACK)
	Vector3 intersection (box.Center());

	// transform values into world space
	m_CurrentWorldTransform.TransformVertex(intersection);

	// set intersection in world space (we use FLT_MAX for the distance since the distance is spacial)
	if (!HasFlags(PickFlags::IgnoreIntersection))
	{
		hit->SetIntersection(intersection);
	}

	return true;
}
Ejemplo n.º 3
0
void Camera::Frame(const AlignedBox& box)
{
    SetPivot(box.Center());
    SetOffset((box.maximum - box.minimum).Length());
    Update(true);
}