Page 1 of 1
Range Finding To Wall
Posted: Wed Jun 18, 2008 2:18 pm
by cp51
Hi,
Ive been looking all over for a way of doing this, but i cant seem to find anything.
I have a node in a map(the quake2 map that comes with the download) I need to find the distance from the node to the wall in front of it. Eventually I will have to find the distance to walls around the node, but ill start with just one for now. Im new to irrlicht and I really have no idea how to go about doing this. If the wall was another node, I could get it done, but since it is the map I dont know where to go or what to use.
example:
Code: Select all
Wall
------------------------------------
^
|
|
| distance
|
|
_______
| |
| Node|
|_______|
any help would be greatly appreciated,
thank you.
Posted: Wed Jun 18, 2008 2:31 pm
by TomiZ
You should read collisions tutorial.
To find distance you can create vector from you node. Set it's length to "infinity", change direction and find point, where it hit wall.
Posted: Wed Jun 18, 2008 2:42 pm
by renegadeandy
could you not just send out a ray and then get the point of intersection with the wall.
Once you have intersection deduct the z value of the vector from your current z value position, boom, thats your distance?
Posted: Wed Jun 18, 2008 3:40 pm
by rogerborg
Specifically, what you're looking for is example 07.Collision/main.cpp
The significant code is:
Code: Select all
selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
...
core::line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;
core::vector3df intersection;
core::triangle3df tri;
if (smgr->getSceneCollisionManager()->getCollisionPoint(
line, selector, intersection, tri))
{
// Then you'll need the distance, which is just...
f32 distance = (intersection - line.start).getLength();
}
However, instead of creating the line from the camera position, create it from the node's position. You'll need to determine a direction as well. If you assume that "in front of" is dependent of the node's rotation, and +Z is forwards, then this will get you a direction vector (and the line to use in the collision check):
Code: Select all
core::matrix4 nodeMatrix = node->getAbsoluteTransformation();
core::vector3df forwards(0, 0, 1000);
nodeMatrix.rotateVect(forwards);
core::line3d<f32> line;
line.start = node->getAbsolutePosition();
line.end = line.start + forwards;
Posted: Thu Jun 19, 2008 4:11 am
by BlindSide
I would place a core::line3df along the parameter of the wall, and then use the "getClosestPoint()" method to find the closest point on the wall.
Posted: Thu Jun 19, 2008 10:13 am
by rogerborg
"the wall"? Which wall?
Posted: Thu Jun 19, 2008 3:44 pm
by cp51
Hey all,
thanks a lot. I was picking through the collision tutorial, but i guess i missed that, or i had no idea what it did. Thanks for pointing it out. Ill go have a look and give it a shot.
thanks a lot.
Posted: Thu Jun 19, 2008 6:45 pm
by rogerborg
No problem. Collision detection can be tricksy, so give us a shout if you run into problems.
Posted: Fri Jun 20, 2008 2:43 am
by merovingian
cp51, what you're trying to do is similar to something rogerborg helped me with a couple of months ago. See here:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=26765
I use getIntersectionWithLimitedLine() for the triangles in the wall. It's considerably faster than getCollisionPoint().
Posted: Wed Jun 25, 2008 1:20 pm
by cp51
hey,
thanks for the info. Im going to look at that right now.
I have a question though. Currently i have 16 range finders in a circle. I created a rangeFinder objectthat i pass a pointer to the selector to and what angle it will be looking in.
However, i also have a simple CubeSceneNode that uses selector for collision detection with the world. When i have just the box(no rangeFinder object), everything is fine, however, when i add in the range finder stuff, the box just drops through the floor...
Does this have something to do with reusing the selector? Do I need multiple selectors? is that even possible?
Thanks for the help everyone.
Posted: Wed Jun 25, 2008 1:23 pm
by JP
Create an IMetaTriangleSelector (big basket for triangle selectors) and put all your triangle selectors in there and use it as you were using triangle selectors previously.
Posted: Wed Jun 25, 2008 2:06 pm
by cp51
wow you guys are fast.
thanks a lot, that worked. So excited lol.
-Thanks again everyone.