Lines and Bounding Boxes problem

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Antaka
Posts: 7
Joined: Tue Jul 28, 2009 4:37 pm

Lines and Bounding Boxes problem

Post by Antaka »

Hi, I'm trying to make a small waypoints guiding system for the NPCs in my game. I load some nodes called "waypoint" from the .irr file, save their positions, and I have a list with all the collidable objects in the scene, then I have a small algorithm to find the way form the NPC position to the player's position.
The problem is to check if the NPC has a clear path to the waypoint or the player.
I make this by building a line between both of them, and checking with the list of items if any of them are colliding with the line, the strange thing, is that the line collides with objects in a completely different place. I've checke that printing the name of the colliding item.
I have the feeling that the lines are being created with a different point of reference than the item's bounding box.

I know there are some already made libs for this, but it's for a college project, and making my own waypoint system will give me extra points...

Thanks in advance, and please tell me if I was not clear enough in my explanation.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Which code do you use for the collision check? You have bboxes in your subject, do you build a bbox for your line segments, or do you check collision of the line against scene node bboxes?
Antaka
Posts: 7
Joined: Tue Jul 28, 2009 4:37 pm

Post by Antaka »

I send the absolute position of both characters as "pos1" and "pos2", "listProps" is the list of the collidable objetcs in the scene, and then check it this way:

Code: Select all

core::line3df line;
core::vector3df start;
core::vector3df end;

start.set(pos1);
start.Y = 5;
end.set(pos2);
end.Y = 5;

line.setLine(start,end);
	

for(unsigned int k = 0; k < listProps.size(); k++){
	if(listProps[k]->getBoundingBox().intersectsWithLine(line)){
		printf("%s\n",listProps[k]->getName());
		return false;
	}
}
return true

Oh, I'm using IrrNewt for physics, does it have anything that can help me with this? I've checked everywhere but found nothing, thanks.
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I suppose listProps contains ISceneNode's?
You probably want getTransformedBoundingBox instead of getBoundingBox. That will give you a boundingbox which regards the movement, translation and scaling of your scenenode which I suppose is what you want here.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Antaka
Posts: 7
Joined: Tue Jul 28, 2009 4:37 pm

Post by Antaka »

That helped a lot :D I feel sooooo blind :cry:
It seems to be working nicely, although it has an obvious problem with archways I'll have to solve. Probably splitng the archways in a few nodes or puting them out of the list...
Thanks a lot again.
Post Reply