Range Finding To Wall

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
cp51
Posts: 11
Joined: Wed Jun 18, 2008 2:12 pm

Range Finding To Wall

Post 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.
TomiZ
Posts: 40
Joined: Wed Aug 29, 2007 6:02 am
Location: Poland
Contact:

Post 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.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post 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?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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;
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post 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.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

"the wall"? Which wall?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
cp51
Posts: 11
Joined: Wed Jun 18, 2008 2:12 pm

Post 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.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

No problem. Collision detection can be tricksy, so give us a shout if you run into problems.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
merovingian
Posts: 37
Joined: Thu Feb 28, 2008 4:34 am
Location: Perth, Western Australia

Post 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().
cp51
Posts: 11
Joined: Wed Jun 18, 2008 2:12 pm

Post 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.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
cp51
Posts: 11
Joined: Wed Jun 18, 2008 2:12 pm

Post by cp51 »

wow you guys are fast.

thanks a lot, that worked. So excited lol.

-Thanks again everyone.
Post Reply