How to find the distance between 2 animated meshes?
How to find the distance between 2 animated meshes?
I want to know the distance between two meshes(node) so that the value is less that is the meshes come close or intersect any one mesh will be destroyed Please help me how to do this?
Re: How to find the distance between 2 animated meshes?
This would use circles arund your meshes that go around the boundingbox and the nodes collide as soon as they are closer together than that (most typical case for collisions, although sometimes people also use the inner-radius which touches only the sides of the boundingbox and not the corners):
edit: fixed missing .getLength()
Code: Select all
irr::scene::IMeshSceneNode * node1 = .... ; // replace ... by whatever method you use to get your node
irr::scene::IMeshSceneNode * node2 = .... ; // replace ... by whatever method you use to get your node
irr::f32 minRadius1 = node1->getMesh()->getBoundingBox().getExtent().getLength() * 0.5f; // maximal radius the mesh will have
irr::f32 minRadius2 = node1->getMesh()->getBoundingBox().getExtent().getLength() * 0.5f; // maximal radius the mesh will have
irr::f32 distance = node1->getAbsolutePosition().getDistanceFrom(node2->getAbsolutePosition());
if ( distance < minRadius1+minRadius2 )
{
node2->remove(); // or sometimes you just hide it with node2->setVisible(false), depends on the situation
}
edit: fixed missing .getLength()
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to find the distance between 2 animated meshes?
Code: Select all
scene::IAnimatedMeshSceneNode* node2 ;
scene::IAnimatedMeshSceneNode* node3;
node2=smgr->addAnimatedMeshSceneNode(smgr->getMesh("ninja.b3d"),0,-1);
node3=smgr->addAnimatedMeshSceneNode(smgr->getMesh("ninja.b3d"),camera,-1);
Code: Select all
f32 minRadius1 = node3->getMesh()->getBoundingBox().getExtent() * 0.5f;
f32 minRadius2 = node3->getMesh()->getBoundingBox().getExtent() * 0.5f;
f32 distance = node1->getAbsolutePosition().getDistanceFrom(node2->getAbsolutePosition());
if ( distance < minRadius1+minRadius2 )
{
node2->setVisible(false);
}
Error 3 error C2440: 'initializing' : cannot convert from 'irr::core::vector3d<T>' to 'irr::f32'
Error 4 error C2440: 'initializing' : cannot convert from 'irr::core::vector3d<T>' to 'irr::f32'
when i changed the code to below I got one more error
Code: Select all
core::vector3df minRadius1 = node3->getMesh()->getBoundingBox().getExtent() * 0.5f;
core::vector3df minRadius2 = node2->getMesh()->getBoundingBox().getExtent() * 0.5f;
f32 distance = node1->getAbsolutePosition().getDistanceFrom(node2->getAbsolutePosition());
if ( distance<(minRadius1+minRadius2))
{
node2->setVisible(false);
}
Re: How to find the distance between 2 animated meshes?
you can't compare a vector with a float. You need to get lenght from vector.
or better:
edit: look at time between 2 post XD just few seconds
Code: Select all
if(distance < (minRad1+minRad2).getLenght() )
Code: Select all
if( (distance*distance) < (minRad1+minRad2).getLenghtSQ() )
Last edited by REDDemon on Tue Apr 17, 2012 11:40 am, edited 1 time in total.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: How to find the distance between 2 animated meshes?
The documentation is not correct : "Get extent of the box (maximal distance of two points in the box). " while getExtent returns MaxEdge-MinEdge.
In pseudo code : (minRadius1+minRadius2).getLength ()
Btw for performance reasons I advise you to compare squared distances.
Edit: Reddemon beat me there ^^
In pseudo code : (minRadius1+minRadius2).getLength ()
Btw for performance reasons I advise you to compare squared distances.
Edit: Reddemon beat me there ^^
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
Re: How to find the distance between 2 animated meshes?
Ah yes sorry - I forgot the .getLength(). I've edited my code above.
And yeah, there is a possibility for optimization - but I want to keep it maximal readable for now so it's obvious why it works.
edit: IAnimatedMeshSceneNode also has a getMesh, you just have to pass your frame additionally. Although for collision it might be better using a fixed size, for example getMesh(0). Or often you use an additional (invisible) mesh for the collision geometry, or just figure out the radius in another way (try&error, or measuring your sizes in a modeling tool) and set it directly. The only reason I get the mesh there is to figure out the size and not knowing anything else about your game that is a general method that works more less well.
And yeah, there is a possibility for optimization - but I want to keep it maximal readable for now so it's obvious why it works.
edit: IAnimatedMeshSceneNode also has a getMesh, you just have to pass your frame additionally. Although for collision it might be better using a fixed size, for example getMesh(0). Or often you use an additional (invisible) mesh for the collision geometry, or just figure out the radius in another way (try&error, or measuring your sizes in a modeling tool) and set it directly. The only reason I get the mesh there is to figure out the size and not knowing anything else about your game that is a general method that works more less well.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to find the distance between 2 animated meshes?
I tried the following code which should make the node2 to be invisible/remove when node3 reaches it. but its not getting invisible/remove but the errors are cleared.
Is the position of the code between drawall correct? if yes then why am I not able to remove.
And I have a clarification,
Is it possible to do this work using any code in Irrlicht or will the physics engineshelp us to do if yes please help me to name the best with Irrlicht?
Code: Select all
smgr->drawAll();
core::vector3df minRadius1 = node3->getMesh()->getBoundingBox().getExtent() * 0.5f;
core::vector3df minRadius2 = node2->getMesh()->getBoundingBox().getExtent() * 0.5f;
f32 distance = node3->getAbsolutePosition().getDistanceFrom(node2->getAbsolutePosition());
if ((distance*distance)<(minRadius1+minRadius2).getLengthSQ())
{
node2->remove();
}
guienv->drawAll();
And I have a clarification,
Is it possible to do this work using any code in Irrlicht or will the physics engineshelp us to do if yes please help me to name the best with Irrlicht?
Re: How to find the distance between 2 animated meshes?
Sorry, that sentence makes no sense. What does "the errors are cleared" mean? Try to formulate it different.chaiein wrote: ... but its not getting invisible/remove but the errors are cleared.
My guess would be that you might get a crash soon afterward because you don't set node2 to 0 afterward (you just removed the object so now the pointer points to random memory as usual in c++) and you also don't check if node2 is valid before using it.
Also please start with my code, I have edited it yesterday. Aways get things working before you start optimizing for speed - especially when you don't understand yet what you are doing.
(minRadius1+minRadius2).getLengthSQ() is _not_ the same as minRadius1.getLengthSQ() + minRadius2.getLengthSQ() unless your boundingboxes are quadratic as the vectors are otherwise not collinear (you can always calculate the stuff through by hand with examples by the way - the calculations used in there are all visible in the source and not hard).
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to find the distance between 2 animated meshes?
Code: Select all
core::vector3df minRadius1 = node3->getMesh()->getBoundingBox().getExtent()*2.5f;
core::vector3df minRadius2 = node2->getMesh()->getBoundingBox().getExtent()*2.5f;
f32 distance = node3->getAbsolutePosition().getDistanceFrom(node2->getAbsolutePosition());
f32 temp;
temp=(minRadius1+minRadius2).getLength();
if ( distance<temp)
{
node3->setFrameLoop(134,145);
node2->setFrameLoop(166,173);
}
Thank you very much
Thank you:)
Last edited by chaiein on Wed Apr 18, 2012 9:28 am, edited 1 time in total.
Re: How to find the distance between 2 animated meshes?
You know how to use a debugger I guess? Just set a breakpoint there and check your values of minRadius1 and minRadius2 (if you use VS the debugger will give show you all those values in "locals". Maybe your meshes have a messed up boundingbox.
And no - it is still not correct - (minRadius1+minRadius2).getLength() is certainly also not the same as minRadius1.getLenght() + minRadius2.getLenght(). Just draw some vector on paper to check it. Ohterwise just use my code as I posted it instead of modifying it always without understanding what you do.
Anyway - use a debugger and check what radius you get - whatever solution you use. Maybe it's messed up. If you use my solution above you can also replace the boundingbox stuff easy by some fixed values. And also maybe just print-out distance (you can use a staticText for text-output for example).
Please don't expect we do the coding for you - this is all still _very_ trivial stuff. If you don't even try to understand what's going on there you won't make it far in your game. You need at least a rudimentary understanding of vector-math to do a 3D application. Otherwise I would recommend to start with a 2D game and go back to 3D once you got the math and have a better understanding of c++ as well.
And no - it is still not correct - (minRadius1+minRadius2).getLength() is certainly also not the same as minRadius1.getLenght() + minRadius2.getLenght(). Just draw some vector on paper to check it. Ohterwise just use my code as I posted it instead of modifying it always without understanding what you do.
Anyway - use a debugger and check what radius you get - whatever solution you use. Maybe it's messed up. If you use my solution above you can also replace the boundingbox stuff easy by some fixed values. And also maybe just print-out distance (you can use a staticText for text-output for example).
Please don't expect we do the coding for you - this is all still _very_ trivial stuff. If you don't even try to understand what's going on there you won't make it far in your game. You need at least a rudimentary understanding of vector-math to do a 3D application. Otherwise I would recommend to start with a 2D game and go back to 3D once you got the math and have a better understanding of c++ as well.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to find the distance between 2 animated meshes?
Ya I got already before I read ur previous reply similar to ur explaination .its working!! I used FrameLoop that's enough
Thank yiou
Thank yiou