3d picking
3d picking
Hi im currently trying to make an editor for my game and have come to the point where I would like to place models at a specific spot on my map, however I cannot seem to figure out how to get the entity picked and also is there a way to get the x,y,z of where the mouse clicked?
-
- Posts: 9
- Joined: Fri Feb 03, 2006 2:06 pm
- Location: Wales
In my editor, I pick the scene nodes using code like this:
where you set cursorpos to the cursor position (duh) and get back the nearest node to the active camera, under these coords.
This does a collision test with the bounding box of each scene node, unfortunately there's a tiny bug in 0.14 so you may need to patch the engine to get the collision test to work properly -
in aabbox3d.h, line 136 should read :
I just use the node position for xyz, although I suppose you could do a more accurate hit test using ISceneCollisionManager::getCollisionPoint(...) like in the Collision sample.
I made a camera scene node that works a bit like the editor in the Torque game engine, with node selection, dragging etc. You can get the code here (CCameraEditorSceneNode.zip) if it's any help
Code: Select all
ISceneManager* smgr = device->getSceneManager();
ISceneNode* node=smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(cursorpos, 0);
This does a collision test with the bounding box of each scene node, unfortunately there's a tiny bug in 0.14 so you may need to patch the engine to get the collision test to work properly -
in aabbox3d.h, line 136 should read :
Code: Select all
const vector3d<T> e = getExtent() * (T)0.5;
I made a camera scene node that works a bit like the editor in the Torque game engine, with node selection, dragging etc. You can get the code here (CCameraEditorSceneNode.zip) if it's any help
-
- Posts: 9
- Joined: Fri Feb 03, 2006 2:06 pm
- Location: Wales
-
- Posts: 230
- Joined: Mon Oct 10, 2005 2:24 am