Hi Everyone,
I require your expertise please.
Using A* path finding, I can find a route between buildings, but it is not always optimal. So what I want to do is to see what is the furthest way point along my path I can directly see from my current position.
Code to generate the line and check for collision with any buildings:
[java]
// Create line from start to the end way point
Line startEnd = new Line(startPoint, endPoint);
startEnd.setLineWidth(20);
Geometry line = new Geometry(“StartEnd”, startEnd);
line.setMaterial(matYellow);
matYellow.getAdditionalRenderState().setWireframe(true);
// Attach to scene
this.wayPoints.attachChild(line);
// Check collision with buildings
List<Spatial> builds = this.buildings.getChildren();
for(int building = 0; building < builds.size(); building++)
{
Spatial buildingSpatial = builds.get(building);
CollisionResults results = new CollisionResults();
BoundingVolume bv = buildingSpatial.getWorldBound();
line.collideWith(bv, results);
System.out.println("Building Check: " + buildingSpatial.getName() + " hits: " + results.size());
if(results.size() > 0)
{
System.out.println(“hit a building”);
}
}
[/java]
So the reason why I have set the line width is that my object that I eventually want to move along the path is not going to be as small as 1px.
However, the collision results are always 0 in size.
So how can I solve this?
My though it is to use a ray, but you can specify a size of a ray. Additionally I need to specify a ray direction, how can I calculate this given a start and end vector. I have looked at the maths path in the wiki but I don’t know what maths I need to use. Please help.
Here is a picture to prove the line does intersect with the buildings:
You help is much appreciated. Mark