Non-axis aligned bounding box? RENAMED for more accuracy

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
TCNJ
Posts: 9
Joined: Sun Mar 30, 2008 3:27 pm

Non-axis aligned bounding box? RENAMED for more accuracy

Post by TCNJ »

I'm trying to place several boxes around models that I have placed in Irredit. For some reason however the box doesn't seem to be rotated correctly with regards to the cube that it is based off of.

Code: Select all

	ISceneNode *cube1 = smgr->addCubeSceneNode(10, 0, -1, core::vector3df(-1424, -65, 1475), core::vector3df(0, -46, 0), core::vector3df(160, 116, 160));
	core::aabbox3df studentCenter = cube1->getBoundingBox();
	cube1->getAbsoluteTransformation().transformBoxEx(studentCenter);
	cube1->setVisible(false);
The cube itself is placed correctly but the box is not.

Thanks for any help.
Last edited by TCNJ on Mon Apr 14, 2008 3:14 pm, edited 1 time in total.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Can you be clearer about what the problem is? It reads like you think the bounding box should be rotated. Um, no; aabbs are Axis Aligned.

Apologies if I've misinterpreted.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
TCNJ
Posts: 9
Joined: Sun Mar 30, 2008 3:27 pm

Post by TCNJ »

Yes that is what I was trying to do. For some reason I never put the aa together. Is there any way to create a create bounding box that is not axis aligned. Sorry for the confusion.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

There's no direct support for that. AABBs represent the baseline behaviour, and anything more complex than that becomes increasingly an application-specific issue.

If you explain what is it that you need the boxes for, then we can probably suggest a solution.

For example, if it's a ray/box collision, then what you'll generally do is to transform the ray by the inverse of the node's transformation, to put the ray into object space, then test it against the AABB.

If you want to do OBB (Object (space) Bounding Box) vs OBB tests, you can transform the vertices of one box, then do collision checks between the boxes, likely by doing plane/point tests on the faces.

It really depends on what you need them for though.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
TCNJ
Posts: 9
Joined: Sun Mar 30, 2008 3:27 pm

Post by TCNJ »

What I was trying to use them for was to test when the camera's position is within the box. The boxes are meant to be placed around a number of building models and when the user is near to them a description is displayed in a text node.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I am such a liar that I may need to a fire extinguisher to quench the raging blaze in my pants.

You can just call ISceneNode::getTransformedBoundingBox() to get a world space bounding box, then test that against your camera position. I keep forgetting about that method. :oops:

Code: Select all


#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

#pragma comment(lib, "Irrlicht.lib")

int main()
{
   IrrlichtDevice* device = createDevice( EDT_OPENGL, core::dimension2d<s32>(640, 480), 32);

   if (device == 0)
      return 1; // could not create selected driver.

   video::IVideoDriver* driver = device->getVideoDriver();
   scene::ISceneManager* smgr = device->getSceneManager();

   scene::IAnimatedMeshSceneNode * sydney
        = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/sydney.md2"));

   if (!sydney)
        return 1;

    sydney->setPosition(vector3df(0, -20, 40));
   sydney->setMaterialFlag(video::EMF_LIGHTING, false);
   sydney->setMD2Animation(scene::EMAT_STAND);
   sydney->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
    sydney->setDebugDataVisible(true);


   scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
   device->getCursorControl()->setVisible(false);

   while(device->run())
   {
        // Rotate the mesh node
        f32 rotation = sydney->getRotation().X - 0.1f;
        if(rotation >= 360.f)
            rotation -= 360.f;
        sydney->setRotation(vector3df(rotation, 0, 0));
        sydney->updateAbsolutePosition();

        if(sydney->getTransformedBoundingBox().isPointInside(camera->getAbsolutePosition()))
            device->setWindowCaption(L"Inside");
        else
            device->setWindowCaption(L"Outside");

      driver->beginScene(true, true, video::SColor(255,113,113,133));
      smgr->drawAll();
      driver->endScene();
   }

   device->drop();
   
   return 0;
}
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply