Exemplo n.º 1
0
	bool VoxelWorldOctTree::SubDivideBound(const math::AABBox& bound, math::AABBox Bounds[8])
	{
		/*
		z
		-|-x     
		0 - (-x, +y, +z)
		1 - (+x, +y, +z)
		2 - (-x, +y, -z)
		3 - (+x, +y, -z)

		4 - (-x, -y, +z)
		5 - (+x, -y, +z)
		6 - (-x, -y, -z)
		7 - (+x, -y, -z)
		*/

		if(bound.IsValid() == false)
			return false;

		const math::Vector3& center = bound.GetCenter();
		const math::Vector3& max_coord = bound.GetMaxCoord();
		const math::Vector3& min_coord = bound.GetMinCoord();


		Bounds[0].Make(math::Vector3(min_coord.x, center.y, center.z), math::Vector3(center.x, max_coord.y, max_coord.z));
		Bounds[1].Make(math::Vector3(center.x, center.y, center.z), math::Vector3(max_coord.x, max_coord.y, max_coord.z));
		Bounds[2].Make(math::Vector3(min_coord.x, center.y, min_coord.z), math::Vector3(center.x, max_coord.y, center.z));
		Bounds[3].Make(math::Vector3(center.x, center.y, min_coord.z), math::Vector3(max_coord.x, max_coord.y, center.z));

		Bounds[4].Make(math::Vector3(min_coord.x, min_coord.y, center.z), math::Vector3(center.x, center.y, max_coord.z));
		Bounds[5].Make(math::Vector3(center.x, min_coord.y, center.z), math::Vector3(max_coord.x, center.y, max_coord.z));
		Bounds[6].Make(math::Vector3(min_coord.x, min_coord.y, min_coord.z), math::Vector3(center.x, center.y, center.z));
		Bounds[7].Make(math::Vector3(center.x, min_coord.y, min_coord.z),math::Vector3(max_coord.x, center.y, center.z));

		return true;
	}
Exemplo n.º 2
0
bool ViewFrustum::IntersectBox(const math::AABBox& box) const
{
    int vec_in_cnt;
    int plane_in_cnt = 0;

    math::Vector3 min = box.GetMinCoord();
    math::Vector3 max = box.GetMaxCoord();

    for( int p = 0; p < 6; p++ )
    {
        vec_in_cnt = 0;
        if( m_planes[p].a * min.x +
                m_planes[p].b * min.y +
                m_planes[p].c * min.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;
        if( m_planes[p].a * max.x +
                m_planes[p].b * min.y +
                m_planes[p].c * min.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;
        if( m_planes[p].a * max.x +
                m_planes[p].b * max.y +
                m_planes[p].c * min.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;
        if( m_planes[p].a * min.x +
                m_planes[p].b * max.y +
                m_planes[p].c * min.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;
        if( m_planes[p].a * min.x +
                m_planes[p].b * min.y +
                m_planes[p].c * max.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;
        if( m_planes[p].a * max.x +
                m_planes[p].b * min.y +
                m_planes[p].c * max.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;
        if( m_planes[p].a * max.x +
                m_planes[p].b * max.y +
                m_planes[p].c * max.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;
        if( m_planes[p].a * min.x +
                m_planes[p].b * max.y +
                m_planes[p].c * max.z +
                m_planes[p].d > 0)
            vec_in_cnt ++;

        if (vec_in_cnt == 0)
            return false;

        if (vec_in_cnt == 8)
            plane_in_cnt++;
    }

    return true;
    //return (plane_in_cnt == 6) ? 2 : 1;
}