Sign in to follow this  
Bouteille51

AABB tree : separating vertices

Recommended Posts

Hi all, I'm working on an AABB Tree so I want to separate my vertex buffer (D3DXVECTOR3 *) in 2 parts. One with Vertex > to the middle of the axis choosen, other with vertex < to the middle of this axis. I've written this but it doesn't seem to work (I got bad boxes), if you see something wrong, please tell me what since i'm getting mad :) thanx
D3DXVECTOR3 pVertex1[MAXVERTICES];
D3DXVECTOR3 pVertex2[MAXVERTICES];
int IndexVertex1=0,IndexVertex2=0;


for(i=0;i<nbVertices-3;i++)
{

	if ((i%3)==0)
	{
			
		CentreFace[0] = (Vertex[i].x + Vertex[i+1].x + Vertex[i+2].x) / 3.0f;
		CentreFace[1] = (Vertex[i].y + Vertex[i+1].y + Vertex[i+2].y) / 3.0f;
		CentreFace[2] = (Vertex[i].z + Vertex[i+1].z + Vertex[i+2].z) / 3.0f;
				
		// Axelong is the axis choosen for separation
		// LongueurAxes are the middle of axes
		// CentreFace is the center of the current face
		if (CentreFace[AxeLong] <= LongueurAxes[AxeLong]) //fSplit
		{
			//Store the verts to the left.
			pVertex2[IndexVertex2++]=Vertex[i];
			pVertex2[IndexVertex2++]=Vertex[i+1];
			pVertex2[IndexVertex2++]=Vertex[i+2];
		}
		else
		{
			//Store the verts to the right.
			pVertex1[IndexVertex1++]=Vertex[i];
			pVertex1[IndexVertex1++]=Vertex[i+1];
			pVertex1[IndexVertex1++]=Vertex[i+2];
		}

	}

}

Edited by Coder: Use source tags. Check GDNet Forums FAQ [Edited by - Coder on August 18, 2004 10:31:15 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this