Updating the Bounding Box

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
LukeBitts
Posts: 21
Joined: Fri Apr 22, 2011 6:02 am

Updating the Bounding Box

Post by LukeBitts »

Hi everyone. I have this 3D model which works as a tile in my game, I'm moving its vertices based on a height-map and it's working like a charm. Now I'm trying to pick the tiles individually using the triangle selector. That is also working, the problem is that when I change the mesh through the mesh buffer, the bounding box is not updated and the triangle selector only counts the previous bb. I did find an updatebb method, but not on the scene node or anywhere I could understand... how can I fix this?


Thanks (:
CuteAlien
Admin
Posts: 9944
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The meshbuffer has a function called setDirty which should be called when the mesh has changed. I think that might help with the bounding-box.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
LukeBitts
Posts: 21
Joined: Fri Apr 22, 2011 6:02 am

Post by LukeBitts »

nop, I'm still getting the same error.

The moveVertex function:

Code: Select all

void moveVertex(IAnimatedMeshSceneNode* node, s32 index, f32 step) 
{ 		
	IMeshBuffer* meshBuffer = node->getMesh()->getMeshBuffer(0);
	S3DVertex* mb_vertices = (S3DVertex*)meshBuffer->getVertices();
	u16* mb_indices = meshBuffer->getIndices();
	mb_vertices[index].Pos.Y += -step;	
	meshBuffer->setDirty();
} 
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

have you tried....

Code: Select all

meshBuffer->recalculateBoundingBox ();
CuteAlien
Admin
Posts: 9944
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hm, only bounding-box updates. I see right now no way to update the triangle selector for non-animated meshes. Strange... hm, which triangle selector are you using here?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
LukeBitts
Posts: 21
Joined: Fri Apr 22, 2011 6:02 am

Post by LukeBitts »

Klunk wrote:have you tried....

Code: Select all

meshBuffer->recalculateBoundingBox ();
That did update the bounding box, but only the pink one (from setDebugDataVisible(scene::EDS_BBOX_ALL); ), I'm guessing the selector uses the white one since the selection is still based on the old bounding box.
Hm, only bounding-box updates. I see right now no way to update the triangle selector for non-animated meshes. Strange... hm, which triangle selector are you using here?
Is this what you want?

Code: Select all

ITriangleSelector* selector = 0;
selector = device->getSceneManager()->createTriangleSelector(me.getTile());
me.getTile()->setTriangleSelector(selector);
IAnimatedMeshSceneNode* selectedSceneNode = (IAnimatedMeshSceneNode*)device->getSceneManager()->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(device->getCursorControl()->getPosition()/*,IDFlag_IsPickable*/); 

This is what I mean by pink and white bounding boxes:
Image

edit: hm, now that I see it, its also updating the white bounding box, but only to the model scale, not the new vertex position... is there a way to copy the meshbuffer bounding box to the node bounding box?
LukeBitts
Posts: 21
Joined: Fri Apr 22, 2011 6:02 am

Post by LukeBitts »

yay I fixed :D

Code: Select all

note->getMesh()->getMeshBuffer(0)->recalculateBoundingBox();
core::aabbox3df box = node->getMesh()->getMeshBuffer(0)->getBoundingBox();
node->getMesh()->getMesh(0)->setBoundingBox(box);
Post Reply