Hi,
I’m having troubles using the BresenhamTerrainPicker. The following code does not return any results unless the mouse cursor is centered (well, nearly centered) in my canvas.
[java]
Vector2f screenCoords = TestApplication.this.getInputManager().getCursorPosition();
Vector3f worldCoords = TestApplication.this.getCamera().getWorldCoordinates(new Vector2f(screenCoords.x, screenCoords.y), 0f).clone();
Vector3f dir = TestApplication.this.getCamera().getWorldCoordinates(new Vector2f(screenCoords.x, screenCoords.y), 1f).subtractLocal(worldCoords);
CollisionResults results = new CollisionResults();
Ray ray = new Ray(worldCoords, dir);
System.out.println(“Ray:n” + "origin: " + ray.getOrigin() + "ndirection: " + ray.getDirection());
TestApplication.this.terrainPicker.getTerrainIntersection(ray, results);
if (results.size() > 0) {
System.out.println(results.getClosestCollision().getContactPoint());
}
[/java]
I must be missing something here…
Thanks for your help
Actually this is working only for some terrain patches. That is, I get a result, a valid one (I am checking it by positionning a sphere on the contact point), but for other patches, I haven’t got any results
This is the code I use, it works :
[java]Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0);
Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 1);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
shootables.collideWith(ray, results);[/java]
Hum, no, that shouldn’t change anything. The dir is the result of getWorldCoordinates(new Vector2f(screenCoords.x, screenCoords.y), 1f), after having applied substraction (.subtractLocal(worldCoords)). I just checked btw
I 'll check that .
Thanks very much, made my day
I just totally forgot to normalize the vector… -_-;