Page 1 of 1

Lines and Bounding Boxes problem

Posted: Thu Aug 06, 2009 2:14 am
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.

Posted: Thu Aug 06, 2009 7:15 am
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?

Posted: Thu Aug 06, 2009 5:04 pm
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.

Posted: Thu Aug 06, 2009 5:22 pm
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.

Posted: Thu Aug 06, 2009 6:53 pm
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.