first off keep up the good work! irrlicht is wonderful.
now then, my question is what's the best way to get a vector3df representing the position of intersection between a 3d vector and the 'world'? i was hoping i could do something like this:
---
vector3df starting_point;
vector3df some_vector;
vector3df intersection_pos = smgr->getSceneCollisionManager()->getIntersectionPoint(starting_point,some_vector);
---
and intersection_pos would be the nearest point of intersection starting from starting_point and going in the direction of some_vector with any triangle in the world (under the root scene node i guess)
the nearest function i can find is smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, intersection, tri), which requires a triangle selector which holds the triangle i would be interested in intersecting with.. this would be fine if my world was a single node like a quake2 map in the tutorial, but my world is made up of many many IAnimatedMeshSceneNodes.
my first thought was that i could use getSceneNodeFromRayBB.. but it only returns the node, not the position of intersection. is there a way to add another parameter which will return intersection as well?
my second thought was that i would have to add a triangle selector for each node (let's say 50 nodes) and then add each triangle selector to the metatriangleselector (which from what i read in the forums isn't working at the moment). is this correct? can i not just grab the RootSceneNode and use that?
is there a better way to do this? is there another way to do this?
intersection point between ray and world
-
- Posts: 271
- Joined: Sat Aug 23, 2003 5:52 pm
- Location: Hurricane Central, Florida
you want collision detection with every object right? You should make a triangle selector for every node and add it to a metaTriangleSelector which will then be the only one added to the camera. But the metaTriangleSelector has problems and you'll have to fix the engine code to make it work right. Check out the posts about it in the adv. forum.
brute force
this works.. but i doubt that it is the correct way of doing it
Code: Select all
core::vector3df MySceneCollisionManager::getIntersectionPositionFromScreenCoordinatesBB(core::position2d<s32> pos, s32 idBitMask)
{
if (!SceneManager || !Driver)
return core::vector3df(-1,-1,-1);
const scene::SViewFrustrum* f =
SceneManager->getActiveCamera()->getViewFrustrum();
core::vector3df farLeftUp = f->getFarLeftUp();
core::vector3df lefttoright = f->getFarRightUp() - farLeftUp;
core::vector3df uptodown = f->getFarLeftDown() - farLeftUp;
core::dimension2d<s32> screenSize = Driver->getScreenSize();
f32 dx = pos.X / (f32)screenSize.Width;
f32 dy = pos.Y / (f32)screenSize.Height;
core::vector3df end = farLeftUp + (lefttoright * dx) + (uptodown * dy);
core::line3d<f32> line;
line.start = f->cameraPosition;//camera->getPosition();
line.end = line.start +(end - line.start).normalize() * 1000.0f;
core::vector3df intersection;
core::triangle3df tri;
scene::ITriangleSelector* wselector = NULL;
//now check *every* node and see if it intersects with the ray (this might be too slow?)
const core::list<ISceneNode*>& children = SceneManager->getRootSceneNode()->getChildren();
core::list<ISceneNode*>::Iterator it = children.begin();
for (; it != children.end(); ++it)
{
ISceneNode* current = *it;
if (current->isVisible()) {
wselector = SceneManager->createTriangleSelectorFromBoundingBox(current);
if (SceneManager->getSceneCollisionManager()->getCollisionPoint(line, wselector, intersection, tri))
return intersection;
}
}
return end;
}