Thanks, CuteAlien, I should have compiled that first.
anandh wrote:Thx for all your reply.Its working fine.One more problem.
Assuming that passing the ray in some direction.it crossing 2 nodes
1. Wall
2. Player (Player is behind the wall)
The selectedNode returned is Player.How to pick the node that is first in that path.
Assuming that the wall is part of a larger world scene, then...
[Short answer]
See example 07.Collision. After doing all of the above, also do this:
Code: Select all
scene::ITriangleSelector* yourWorldSelector = 0;
selector = smgr->createOctTreeTriangleSelector(yourWorldMesh->getMesh(0), yourWorldSceneNode, 128);
...
core::vector3df intersection;
core::triangle3df tri;
if (smgr->getSceneCollisionManager()->getCollisionPoint(core::line3d<f32>(BotNode->getPosition(), target ), yourWorldSelector, intersection, tri))
{
// If the distance to 'intersection' is less than the distance to the
// scene node returned by getSceneNodeFromRayBB(), then the
// wall is nearer than the scene node
}
[Long explanation]
Remember that so far we're talking about doing bounding box collisions. If that wall is part of a large world scene, then you're not checking for intersection with the wall, but with the whole world. As the line will presumably start inside the world, it will always hit it. That's not useful information. The reason that the world isn't always selected is that getSceneNodeFromRayBB() treats the distance to each scene node box as the distance from the line start to the nearest edge,
even if the line starts inside the box. It should perhaps check if the line starts inside the box and treat that as a distance of 0, but it doesn't, and that wouldn't help here anyway, as we can't use a line/box check on the world anyway.
What we have to do is to perform an actual line/triangle collision with the world, and therefore the wall, and see if that collision is closer than the nearest scene node collision. If it is, then there's a part of the world in the way.
[Towards A Better Solution]
Lobby bitplane, hybrid, and/or niko to incorporate
this patch which introduces a new method, getSceneNodeAndCollisionPointFromRay() which will do accurate ray/triangle collision checking on the entire scene, including on animated meshes, as well as an updated collision example demonstrating it which will hopefully make questions like this redundant.