Sign in to follow this  
TWild

D3DXComputeBoundingBox problem

Recommended Posts

I have a cube built manually in code (below). After building the VB, I compute the bounding box. When I run my code, I expect that m_boxMin should = {-50, -50, -50} and that m_boxMax should = {50, 50, 50}. But, the results I am getting is m_boxMin = {-50, -50, -50} and m_boxMax = {3.45679e+031, 50, 3.45819e+031}. Does anyone see what I'm missing or what I'm doing wrong?
// Create Vertex buffer
	if(FAILED(m_pD3DDevice->CreateVertexBuffer(sizeof(CubeVertex) * 36, 0, CubeVertex::FVF,
		D3DPOOL_DEFAULT, &m_pVB, NULL))){
		//	m_App->AppError(true, "Error creating vertex buffer!");
	}

		CubeVertex* vertices = 0;
	m_pVB->Lock(0, 0, (void**)&vertices, 0);
	
	// front
	vertices[0]  = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 0.0f, 1.0f );
	vertices[1]  = CubeVertex( -50.0f,  50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 0.0f, 0.0f );
	vertices[2]  = CubeVertex(  50.0f,  50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 1.0f, 0.0f );
	vertices[3]  = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 0.0f, 1.0f );
	vertices[4]  = CubeVertex(  50.0f,  50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 1.0f, 0.0f );
	vertices[5]  = CubeVertex(  50.0f, -50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 1.0f, 1.0f );

	// back
	vertices[6]  = CubeVertex(  50.0f, -50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 1.0f, 1.0f );
	vertices[7]  = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 1.0f, 0.0f );
	vertices[8]  = CubeVertex( -50.0f, -50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 0.0f, 1.0f );
	vertices[9]  = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 1.0f, 0.0f );
	vertices[10] = CubeVertex( -50.0f,  50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 0.0f, 0.0f );
	vertices[11] = CubeVertex( -50.0f, -50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 0.0f, 1.0f );

	// left
	vertices[12] = CubeVertex( -50.0f, -50.0f, -50.0f, -1.0f,  0.0f,  0.0f, 1.0f, 1.0f );
	vertices[13] = CubeVertex( -50.0f,  50.0f,  50.0f, -1.0f,  0.0f,  0.0f, 0.0f, 0.0f );
	vertices[14] = CubeVertex( -50.0f,  50.0f, -50.0f, -1.0f,  0.0f,  0.0f, 1.0f, 0.0f );
	vertices[15] = CubeVertex( -50.0f, -50.0f, -50.0f, -1.0f,  0.0f,  0.0f, 1.0f, 1.0f );
	vertices[16] = CubeVertex( -50.0f, -50.0f,  50.0f, -1.0f,  0.0f,  0.0f, 0.0f, 1.0f );
	vertices[17] = CubeVertex( -50.0f,  50.0f,  50.0f, -1.0f,  0.0f,  0.0f, 0.0f, 0.0f );

	// right
	vertices[18] = CubeVertex(  50.0f,  50.0f,  50.0f,  1.0f,  0.0f,  0.0f, 0.0f, 0.0f );
	vertices[19] = CubeVertex(  50.0f, -50.0f,  50.0f,  1.0f,  0.0f,  0.0f, 0.0f, 1.0f );
	vertices[20] = CubeVertex(  50.0f, -50.0f, -50.0f,  1.0f,  0.0f,  0.0f, 1.0f, 1.0f );
	vertices[21] = CubeVertex(  50.0f,  50.0f, -50.0f,  1.0f,  0.0f,  0.0f, 1.0f, 0.0f );
	vertices[22] = CubeVertex(  50.0f,  50.0f,  50.0f,  1.0f,  0.0f,  0.0f, 0.0f, 0.0f );
	vertices[23] = CubeVertex(  50.0f, -50.0f, -50.0f,  1.0f,  0.0f,  0.0f, 1.0f, 1.0f ); 

	// top
	vertices[24] = CubeVertex( -50.0f,  50.0f, -50.0f,  0.0f,  1.0f,  0.0f, 0.0f, 1.0f );
	vertices[25] = CubeVertex( -50.0f,  50.0f,  50.0f,  0.0f,  1.0f,  0.0f, 0.0f, 0.0f );
	vertices[26] = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  1.0f,  0.0f, 1.0f, 0.0f );
	vertices[27] = CubeVertex( -50.0f,  50.0f, -50.0f,  0.0f,  1.0f,  0.0f, 0.0f, 1.0f );
	vertices[28] = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  1.0f,  0.0f, 1.0f ,0.0f );
	vertices[29] = CubeVertex(  50.0f,  50.0f, -50.0f,  0.0f,  1.0f,  0.0f, 1.0f, 1.0f );

	// bottom
	vertices[30] = CubeVertex(  50.0f, -50.0f, -50.0f,  0.0f, -1.0f,  0.0f, 1.0f, 1.0f );
	vertices[31] = CubeVertex(  50.0f, -50.0f,  50.0f,  0.0f, -1.0f,  0.0f, 1.0f, 0.0f );
	vertices[32] = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f, -1.0f,  0.0f, 0.0f, 1.0f );
	vertices[33] = CubeVertex(  50.0f, -50.0f,  50.0f,  0.0f, -1.0f,  0.0f, 1.0f, 0.0f );
	vertices[34] = CubeVertex( -50.0f, -50.0f,  50.0f,  0.0f, -1.0f,  0.0f, 0.0f, 0.0f );
	vertices[35] = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f, -1.0f,  0.0f, 0.0f, 1.0f );

	m_pVB->Unlock();

Computing bounding box:
D3DXComputeBoundingBox((D3DXVECTOR3*)m_pVB, 36, sizeof(CubeVertex), &m_boxMin, &m_boxMax)

Share this post


Link to post
Share on other sites
You seem to be casting a pointer to a Vertex Buffer to a pointer to an array of D3DXVECTOR3s.

Try locking the vertex buffer with Read-Only, and passing the pointer you get from the lock operation as the first argument in the function.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
You seem to be casting a pointer to a Vertex Buffer to a pointer to an array of D3DXVECTOR3s.

Try locking the vertex buffer with Read-Only, and passing the pointer you get from the lock operation as the first argument in the function.

Hope this helps.


Thanks for the reply. I'm writing directly to the locked vertex buffer, so I can't lock it with read-only.

Share this post


Link to post
Share on other sites
Sorry, I guess I wasn't clear enough:
D3DXComputeBoundingBox((D3DXVECTOR3*)m_pVB, 36, sizeof(CubeVertex), &m_boxMin, &m_boxMax)
bold section seems like a bad idea.

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
Sorry, I guess I wasn't clear enough:
D3DXComputeBoundingBox((D3DXVECTOR3*)m_pVB, 36, sizeof(CubeVertex), &m_boxMin, &m_boxMax)
bold section seems like a bad idea.


Thanks a lot, I changed "m_pVB" to "vertices" and it worked perfectly.

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