I am creating a small program that requires picking multiple points on the screen that collide with terrain. I created a TerrainQuad, translated and rotated it with the following code:
[java]
terrain = new TerrainQuad(“my terrain”, patchSize, 513, heightMap);
// We give the terrain its material, position & scale it, and attach it.
terrain.setMaterial(mat_terrain);
terrain.setLocalTranslation(128,-128,-2);
terrain.setLocalScale(2f, 2f, 1f);
terrain.rotateUpTo(zenith);
rootNode.attachChild(terrain);[/java]
and I am detecting picks on the terrain with the following code during the appropriate update with this code (taken directly from a JME3 example):
[java] // 1. Reset results list.
CollisionResults results = new CollisionResults();
// 2. Aim the ray from cam loc to cam direction.
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
// 3. Collect intersections between Ray and Shootables in results list.
terrain.collideWith(ray, results);[/java]
The problem I am facing is that the pick never works - results.size == 0 always - when I rotate and translate the terrain. However, if I do not rotate and translate the terrain, leaving it near 0,0,0, it works as expected.
My camera is looking at (lookAt) and my player is positioned (setPhysicalLocation) at 128,-128,5, right above the center of the terrain.
Any suggestions? I’ve been banging my head on this one for a day now and I think it must be something embarrassingly obvious.
Thanks for your time,
Jay Jay