Jump to content
  • Advertisement
Sign in to follow this  

Problem with Bounding Box for more than one model

This topic is 3097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay. Im using DirectX. I got the bounding box workong fine for one model. Basically i have a class called meshLoader that loads in a model. Then i have two classes, enemyShip and spaceShip, both inherited from meshModel. meshModel has all the code to do with drawing and the bounding box that is the same for both. So i load up a 2 meshes and make an instance of both spaceShip and enemyShip. The problem im having is that the bounding box that is for my spaceShip, is being drawn around my enemy ship and i cant see why. Im using a fx file t odo the drawing of the box. so in a setup function at the start, after ive created both instances i have theSpaceShip->CreateFX(); theSpaceShip->initBoundingBox(); In the main loop i call a mehtod to draw the ships, same for both ships, just using different matrices.
void spaceShip::updateMatrices()
	D3DXMatrixTranslation(&spaceShipPosMat, spaceShipPos.x, spaceShipPos.y, spaceShipPos.z);//Translates spaceShip to coordinates defined.
	D3DXMatrixScaling(&spaceShipScale, 0.10f,0.10f,0.10f);//Scales the spaceShip to defined size.
	worldMat = spaceShipScale*rotationMat*initialRotationMat*spaceShipPosMat;

void spaceShip::showShip()

Then i draw the bounding box

void drawBBox(D3DXMATRIX View, D3DXMATRIX projection)
	theSpaceShip->drawBBox(View, projection);

	enemyShip1->drawBBox(View, projection);

void meshModel::setupBBox()

	Device->CreateVertexDeclaration(decl, &vertexDeclaration);
	//bounds[0] = bBox.getBounds();

	float halfWidth = 0.0f;
	D3DXVECTOR3 maxBound = bBox.getMaxBound();
	D3DXVECTOR3 minBound = bBox.getMinBound();

	D3DXVECTOR3 points[18];
	//Is the first line not just minbound.x, minbound.y, minbound.z
	points[0] = D3DXVECTOR3(minBound.x, minBound.y, minBound.z);
	points[1] = D3DXVECTOR3(minBound.x, minBound.y, maxBound.z);
	points[2] = D3DXVECTOR3(maxBound.x, minBound.y, maxBound.z);
	points[3] = D3DXVECTOR3(maxBound.x, minBound.y, minBound.z);
	points[4] = D3DXVECTOR3(minBound.x, minBound.y, minBound.z);

	points[5] = D3DXVECTOR3(minBound.x, maxBound.y, minBound.z);
	points[6] = D3DXVECTOR3(minBound.x, maxBound.y, maxBound.z);
	points[7] = D3DXVECTOR3(maxBound.x, maxBound.y, maxBound.z);
	points[8] = D3DXVECTOR3(maxBound.x, maxBound.y, minBound.z);
	points[9] = D3DXVECTOR3(minBound.x, maxBound.y, minBound.z);

	points[10] = D3DXVECTOR3(minBound.x, minBound.y, minBound.z);
	points[11] = D3DXVECTOR3(minBound.x, maxBound.y, minBound.z);
	points[12] = D3DXVECTOR3(maxBound.x, minBound.y, minBound.z);
	points[13] = D3DXVECTOR3(maxBound.x, maxBound.y, minBound.z);
	points[14] = D3DXVECTOR3(maxBound.x, minBound.y, maxBound.z);
	points[15] = D3DXVECTOR3(maxBound.x, maxBound.y, maxBound.z);
	points[16] = D3DXVECTOR3(minBound.x, minBound.y, maxBound.z);
	points[17] = D3DXVECTOR3(minBound.x, maxBound.y, maxBound.z);

	Device->CreateVertexBuffer( 18 * sizeof(D3DXVECTOR3), 0, 0,D3DPOOL_MANAGED,&pVB, NULL );
	VOID* pVertices;
	pVB->Lock( 0, 18*sizeof(D3DXVECTOR3), (void**)&pVertices, 0 );
	memcpy( pVertices, points, 18*sizeof(D3DXVECTOR3));


void meshModel::drawBBox(D3DXMATRIX View, D3DXMATRIX proj, D3DXMATRIX spaceShipScale, D3DXMATRIX spaceShipPosMat)
	Device->SetStreamSource( 0, pVB, 0, sizeof(D3DXVECTOR3) );			

	D3DXVECTOR4 col = D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f);

	mFX->SetValue(mhColour,&(col) ,sizeof(D3DXVECTOR4));

	UINT passes = 1;
	Device->DrawPrimitive(D3DPT_LINESTRIP, 0, 4);
	Device->DrawPrimitive(D3DPT_LINESTRIP, 5, 4);
	Device->DrawPrimitive(D3DPT_LINESTRIP, 10, 4);
But for some reason, the bounding box of the spaceShip is being drawn around the enemy. Its strange aswell, cos when i rotate the player spaceship the bounding box is rotating. So its just the position that is wrong.

Share this post

Link to post
Share on other sites
Make sure you have updated original bounding box with world matrix of instanced objects.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!