Hi,
I’m using a camera that is lightly adapted from
This is a scene editor type camera that is more appropriate for our use of JME in a visualization type application rather than a game. The camera itself does exactly what we want it to. However there is a problem with picking. I’m using some of the tutorial code for picking, namely:
[java]
CollisionResults results = new CollisionResults();
// Convert screen click to 3d position
Vector2f click2d = app.getInputManager().getCursorPosition();
Vector3f click3d = app.getCamera()
.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = app.getCamera()
.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d)
.normalizeLocal();
// Aim the ray from the clicked spot forwards.
Ray ray = new Ray(click3d, dir);
// Collect intersections between ray and all nodes in results list.
((SimpleApplication)app).getRootNode().collideWith(ray, results);
// (Print the results so we see what is going on:)
for (int i = 0; i < results.size(); i++) {
// (For each hit, we know distance, impact point, geometry.)
float dist = results.getCollision(i).getDistance();
final Vector3f pt = results.getCollision(i).getContactPoint();
String target = results.getCollision(i).getGeometry().getName();
System.out.println(“Selection #” + i + ": " + target + " at " + pt + “, " + dist
+ " WU away.”);
}
[/java]
This works correctly if just zoom but as soon as I rotate or pan the scene the picking code no longer works. The camera app state code sets a rotation etc. on the camera and this is then incorporated into the camera’s view matrix and ultimately then into the camera’s viewProjectionMatrix. Camera.getWorldCoordinates uses that matrix so I can’t figure out why rotation / pan would be causing the problem. Any suggestions appreciated.
thanks,
Nick