summing bounding boxes
-
- Posts: 83
- Joined: Wed Apr 26, 2006 10:07 pm
- Location: Vienna
summing bounding boxes
Hi!
I thing almost everyone here already knows that I want to load an md3 model into my game ^^
Now I encountered the following problem:
an md3 model consists of three md3 files.
now I want to calculate a boundingbox over ALL THREE MESHES!
so I want to sum all the three boundingboxes to a single new one!
I already tried to use the method aabbox3d<T>::addInternalBox() but that function does not take into account that these meshes are not at the same point! so it makes just a bounding box for all three meshes as if they were all at point (0,0,0)
can anyone tell me how to achieve my task?
I thing almost everyone here already knows that I want to load an md3 model into my game ^^
Now I encountered the following problem:
an md3 model consists of three md3 files.
now I want to calculate a boundingbox over ALL THREE MESHES!
so I want to sum all the three boundingboxes to a single new one!
I already tried to use the method aabbox3d<T>::addInternalBox() but that function does not take into account that these meshes are not at the same point! so it makes just a bounding box for all three meshes as if they were all at point (0,0,0)
can anyone tell me how to achieve my task?
I'm assuming that you're loading each md3 model into a seperate ISceneNode derived class... the scene node stores a bounding box that is in local coordinates. If you want the bounding box in world coordinates, then you have to specifically ask for that.
Also, don't forget that the box is initialized so that the world origin [coordinate 0, 0, 0] is already in the box. If you want a box that just includes your nodes, you must initialize the box properly.
Travis
Code: Select all
box.addInternalBox(node->getTransformedBoundingBox());
Travis
-
- Posts: 83
- Joined: Wed Apr 26, 2006 10:07 pm
- Location: Vienna
hmmm
I already tried to do it like this:
and like this
I already tried to do it like this:
Code: Select all
aabbox3d<f32> meshBox1 = md31->getBoundingBox();
aabbox3d<f32> meshBox2 = node2->getTransformedBoundingBox();
aabbox3d<f32> meshBox3 = node3->getTransformedBoundingBox();
meshBox1.addInternalBox(meshBox2);
meshBox1.addInternalBox(meshBox3);
vector3df size = meshBox1.getExtent();
Code: Select all
aabbox3d<f32> meshBox1 = node1->getTransformedBoundingBox();
aabbox3d<f32> meshBox2 = node2->getTransformedBoundingBox();
aabbox3d<f32> meshBox3 = node3->getTransformedBoundingBox();
meshBox1.addInternalBox(meshBox2);
meshBox1.addInternalBox(meshBox3);
vector3df size = meshBox1.getExtent();
-
- Posts: 83
- Joined: Wed Apr 26, 2006 10:07 pm
- Location: Vienna
Works just fine for me...
Code: Select all
// add a few dwarfs at random positions
core::array<scene::ISceneNode*> dwarfs;
u32 d;
for (d = 0; d < 4; ++d)
{
const core::vector3df origin(rand() % 60, rand() % 60, rand() % 60);
const f32 radius = (30.f * rand() / RAND_MAX);
const f32 velocity = (.01f * rand() / RAND_MAX);
scene::ISceneNode* dwarf = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/dwarf.x"));
dwarf->setMaterialFlag(video::EMF_LIGHTING, false);
// move this dwarf in a unique circle
scene::ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(origin, radius, velocity);
dwarf->addAnimator(anim);
anim->drop();
// show the bounding box of the dwarf
dwarf->setDebugDataVisible(true);
dwarfs.push_back(dwarf);
}
Code: Select all
if (dwarfs.size())
{
core::aabbox3df bbox = dwarfs[0]->getTransformedBoundingBox();
u32 d;
for (d = 1; d < dwarfs.size(); ++d)
bbox.addInternalBox(dwarfs[d]->getTransformedBoundingBox());
core::matrix4 identity;
video::SMaterial material;
material.Lighting = false;
driver->setTransform(video::ETS_WORLD, identity);
driver->setMaterial(material);
driver->draw3DBox(bbox);
}
-
- Posts: 83
- Joined: Wed Apr 26, 2006 10:07 pm
- Location: Vienna
-
- Posts: 83
- Joined: Wed Apr 26, 2006 10:07 pm
- Location: Vienna
ok
now i found out that summing the boxes was not the problem:
the problem is, that I need to get a bounding box that covers all three meshes of my model
and then transfer it back to the "root point" (vector3df(0,0,0))
afterwards I need to get the size of the box as a vector
and THEN I can use it properly to make a NewtonCollision geometry....
but I just have no idea how I can translate the calculated bountingbox back to the origin (0,0,0)
any ideas?
now i found out that summing the boxes was not the problem:
the problem is, that I need to get a bounding box that covers all three meshes of my model
and then transfer it back to the "root point" (vector3df(0,0,0))
afterwards I need to get the size of the box as a vector
and THEN I can use it properly to make a NewtonCollision geometry....
but I just have no idea how I can translate the calculated bountingbox back to the origin (0,0,0)
any ideas?
-
- Posts: 83
- Joined: Wed Apr 26, 2006 10:07 pm
- Location: Vienna
ok!
now I found out that it was not the bounding boxes!
the problem was, that I added the torso and the head mesh to the legs, so the middle of the "motherscenenode" was not the middle of all three meshes, but the middle of the legs mesh of course.
so I had to make a new empty scene node and make this the parent for all three other ones. then I had to move all the three meshes so that the middle of the total model was in the origin...
and now it works...
it is just a pity that if you use the method node->getTransferredBoundingBox(), you always get the boudning box for the mesh at it*s actual animation state.
I would appreciate if threr was a node->getTransferredBoundingBox(node->getMesh()->getMesh(0));, so you can chose which animation frame of the mesh is chosen for calculating the transferred bounding box....
now I found out that it was not the bounding boxes!
the problem was, that I added the torso and the head mesh to the legs, so the middle of the "motherscenenode" was not the middle of all three meshes, but the middle of the legs mesh of course.
so I had to make a new empty scene node and make this the parent for all three other ones. then I had to move all the three meshes so that the middle of the total model was in the origin...
and now it works...
it is just a pity that if you use the method node->getTransferredBoundingBox(), you always get the boudning box for the mesh at it*s actual animation state.
I would appreciate if threr was a node->getTransferredBoundingBox(node->getMesh()->getMesh(0));, so you can chose which animation frame of the mesh is chosen for calculating the transferred bounding box....
Just keep a pointer to the IAnimatedMesh, or add an accessor for the IAnimatedMesh held by the CAnimatedMeshSceneNode. Then you'd be able to do something like this...
Code: Select all
core::aabbox3df mbox = node->getAnimatedMesh()->getMesh(0)->getBoundingBox();
node->getAbsoluteTransformation().transformBox(mbox);
box.addInternalBox( mbox );
-
- Posts: 83
- Joined: Wed Apr 26, 2006 10:07 pm
- Location: Vienna