Ejemplo n.º 1
0
void ISpatial_DB::_insert(ISpatial_NODE* N, Fvector& n_C, float n_R)
{
    //*** we are assured that object lives inside our node
    float n_vR = 2 * n_R;
    VERIFY(N);
    VERIFY(verify_sp(rt_insert_object, n_C, n_vR));

    // we have to make sure we aren't the leaf node
    if (n_R <= c_spatial_min)
    {
        // this is leaf node
        N->_insert(rt_insert_object);
        rt_insert_object->spatial.node_center.set(n_C);
        rt_insert_object->spatial.node_radius = n_vR; // vR
        return;
    }

    // we have to check if it can be putted further down
    float s_R = rt_insert_object->spatial.sphere.R; // spatial bounds
    float c_R = n_R / 2; // children bounds
    if (s_R < c_R)
    {
        // object can be pushed further down - select "octant", calc node position
        Fvector& s_C = rt_insert_object->spatial.sphere.P;
        u32 octant = _octant(n_C, s_C);
        Fvector c_C;
        c_C.mad(n_C, c_spatial_offset[octant], c_R);
        VERIFY(octant == _octant(n_C, c_C)); // check table assosiations
        ISpatial_NODE*& chield = N->children[octant];

        if (0 == chield)
        {
            chield = _node_create();
            VERIFY(chield);
            chield->_init(N);
            VERIFY(chield);
        }
        VERIFY(chield);
        _insert(chield, c_C, c_R);
        VERIFY(chield);
    }
    else
    {
        // we have to "own" this object (potentially it can be putted down sometimes...)
        N->_insert(rt_insert_object);
        rt_insert_object->spatial.node_center.set(n_C);
        rt_insert_object->spatial.node_radius = n_vR;
    }
}
Ejemplo n.º 2
0
void			ISpatial_DB::initialize(Fbox& BB)
{
	if (0==m_root)			
	{
		// initialize
		Fvector bbc,bbd;
		BB.get_CD				(bbc,bbd);

		bbc.set					(0,0,0);			// generic
		bbd.set					(1024,1024,1024);	// generic

		allocator_pool.reserve	(128);
		m_center.set			(bbc);
		m_bounds				= _max(_max(bbd.x,bbd.y),bbd.z);
		rt_insert_object		= NULL;
		if (0==m_root)	m_root	= _node_create();
		m_root->_init			(NULL);
	}
}