AABB closest distance

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.

AABB closest distance

Postby en51nm » Tue May 29, 2012 2:51 pm

I'm trying to figure out how to get the separation distance between two AABB. I've had a go at implementing something, but haven't been very successfull.

A method that works, but it slows my frame rate down to 15fps :-(

cpp Code: Select all
 
//Get separation distance
vector3d<f32> edges1[8];
vector3d<f32> edges2[8];
Sobj1.irr_node->getTransformedBoundingBox().getEdges(edges1);
Sobj2.irr_node->getTransformedBoundingBox().getEdges(edges2);
 
vector3d<f32> SepDist;
vector3d<f32> dist;
//X
dist.X = abs(Sobj2.irr_node->getTransformedBoundingBox().getCenter().X - Sobj1.irr_node->getTransformedBoundingBox().getCenter().X);
SepDist.X = dist.X - (((abs(edges1[4].X-edges1[0].X))/2.0)+((abs(edges2[4].X-edges2[0].X))/2.0));
//Y
dist.Y = abs(Sobj2.irr_node->getTransformedBoundingBox().getCenter().Y - Sobj1.irr_node->getTransformedBoundingBox().getCenter().Y);
SepDist.Y = dist.Y - (((abs(edges1[1].Y-edges1[0].Y))/2.0)+((abs(edges2[1].Y-edges2[0].Y))/2.0));
//Z
dist.Z = abs(Sobj2.irr_node->getTransformedBoundingBox().getCenter().Z - Sobj1.irr_node->getTransformedBoundingBox().getCenter().Z);
SepDist.Z = dist.Z - (((abs(edges1[2].Z-edges1[0].Z))/2.0)+((abs(edges2[2].Z-edges2[0].Z))/2.0));
 


There must be a quicker way!! (any ideas?)

Also - I'm having trouble displaying this information on the screen due to (I think) typecasting issues, how do you display a vector3d<f32> in the GUI?
en51nm
 
Posts: 26
Joined: Thu May 17, 2012 7:31 pm

Re: AABB closest distance

Postby CuteAlien » Tue May 29, 2012 3:41 pm

Can't help with separation distance (don't know if you solution works, but I see nothing in there which should be too slow - you could do a lot of that before it should affect the framerate seriously).

For printing a vector just writing it's x,y and z component into a string and display that (you can either use functions like sprintf or irr::string has a number to string conversion in it's string-constructor).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5396
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: AABB closest distance

Postby Mel » Tue May 29, 2012 3:45 pm

That cannot drop your performance to 15 fps!... unless you are doing it many times like an aabb collision testing with 1000 boxes against other 1000 boxes, and even like that, a performance drop of such characteristics is something unexpected. Still, Irrlicht has also built in vector operations, so there is no need to perform all those tests separatedly,

like:

vector2d<f32> distanceVector = box1.getCenter() - box2.getCenter();
f32 distance = distanceVector.getLength();
http://santiagong.daportfolio.com/
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
User avatar
Mel
Competition winner
 
Posts: 1788
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: AABB closest distance

Postby en51nm » Tue May 29, 2012 4:15 pm

weird... it seems to be working fine now, although my fps stay at 60. I don't remember setting a flag to sync my fps to my monitors refresh rate...? Is that even possible?
en51nm
 
Posts: 26
Joined: Thu May 17, 2012 7:31 pm

Re: AABB closest distance

Postby CuteAlien » Tue May 29, 2012 6:35 pm

Yes, that's called Vsync and can be passed with SIrrlichtCreationParameters. But it's disabled by default so it shouldn't be set unless it's explicitely done.

Maybe it can also be set in your graphic-card directly to enforce this (I think the nvidia tool has some setting for that).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5396
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: AABB closest distance

Postby zerochen » Tue May 29, 2012 7:02 pm

yes and it is also passed by the createDevice method

cpp Code: Select all
irr::createDevice       (       video::E_DRIVER_TYPE    deviceType = video::EDT_SOFTWARE,
                const core::dimension2d< u32 > &        windowSize = (core::dimension2d< u32 >(640, 480)),
                u32     bits = 16,
                bool    fullscreen = false,
                bool    stencilbuffer = false,
                [b]bool         vsync = false,[/b]
                IEventReceiver *        receiver = 0     
        )      
zerochen
 
Posts: 200
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 0 guests