コード例 #1
0
ファイル: Octree.cpp プロジェクト: dreamsxin/nsg-library
    void Octant::Insert(SceneNode* obj)
    {
        const BoundingBox& box = obj->GetWorldBoundingBox();

        // If drawable is outside the root octant bounds, insert to root
        bool insertHere;
        if (this == root_)
            insertHere = cullingBox_.IsInside(box) != Intersection::INSIDE || CheckFit(box);
        else
            insertHere = CheckFit(box);

        if (insertHere)
        {
            Octant* oldOctant = obj->GetOctant();
            if (oldOctant != this)
            {
                // Add first, then remove, because drawable count going to zero deletes the octree branch in question
                Add(obj);
                if (oldOctant)
                    oldOctant->Remove(obj, false);
            }
        }
        else
        {
            Vector3 boxCenter = box.Center();
            unsigned x = boxCenter.x < center_.x ? 0 : 1;
            unsigned y = boxCenter.y < center_.y ? 0 : 2;
            unsigned z = boxCenter.z < center_.z ? 0 : 4;

            GetOrCreateChild(x + y + z)->Insert(obj);
        }
    }
コード例 #2
0
ファイル: sphere.cpp プロジェクト: eas/Lighting
void Tessellation(	Node& n1, Node& n2, Node& n3, Vertices& vertices, Indices& indices,
					unsigned curDepth, unsigned maxDepth )
{
	if( curDepth<maxDepth )
	{
		Node *n12 = GetOrCreateChild(n1, n2, vertices);
		Node *n23 = GetOrCreateChild(n2, n3, vertices);
		Node *n31 = GetOrCreateChild(n3, n1, vertices);
		Tessellation( n1, *n12, *n31, vertices, indices, curDepth+1, maxDepth );
		Tessellation( n2, *n23, *n12, vertices, indices, curDepth+1, maxDepth );
		Tessellation( n3, *n31, *n23, vertices, indices, curDepth+1, maxDepth );
		Tessellation( *n12, *n23, *n31, vertices, indices, curDepth+1, maxDepth );

	}
	else
	{
		indices.push_back( n1.GetIndex() );
		indices.push_back( n2.GetIndex() );
		indices.push_back( n3.GetIndex() );
	}
}