(c++) Mouse collision with overlaping bounding box

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Pazystamo
Posts: 115
Joined: Sat Dec 03, 2005 5:56 pm
Location: Lithuania
Contact:

(c++) Mouse collision with overlaping bounding box

Post by Pazystamo »

If you are using bounding box for collision and need to know whitch node is selected, then part of that node is overlaped with another box, then use idBitMask. For storing all nodes you can use structure inside array, so you need array index, to get node.
Small example where to use it: lets say you have some table game with cubes and some constructions where all that cubes are attached (bounding box are overlaped). So you can't select your cube with mouse, because constructions bounding box is bigger and overlap cube.
How to solve it? Use getSceneNodeFromCameraBB and set the right idBitMask. idBitMask is s32, so you can have 32 different groups of nodes (1,2,4,8,16,32....2147483648). Lets say i need 500 cubes, so i set cubes id from 512 to 1012 and use getSceneNodeFromCameraBB(camera,512) to sort cubes nodes. 512 in binary is 100000000 and max in this group can be 1023 - binary 111111111. Mask 512 meens that at least one 1 bit in mask match with node id bit. So nodes id's from 512 to 1023 first binary digit is 1 and match mask.

Code: Select all

node1->setID(512);
node2->setID(5);
...................
selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(cam,512);
//now you can select only node1, but not node2.
You can call getSceneNodeFromCameraBB multiple times with diferent mask to get others nodes!

p.s. sorry for mistakes ;)

Edit: for binary understanding try free Biscope, just set 32 bit, enter decimal number and you get binary.
My project in forum- ATMOsphere - new dynamic sky dome for Irrlicht
Post Reply