I need help with intersectWhere

Hi,



I am trying to use Ray.intersectWhere methodo with TerrainPage, but i dont know what i am doing wrong, intersectWhere seems to work well just on TerrainPage4Page1Page1Block1. :?



I am using an AbsoluteMouse and TrianglePickResults.



results = new TrianglePickResults();
results.setCheckDistance(true);




public void performAction(InputActionEvent event) {
   float time = event.getTime();

   // is left button down
   if (MouseInput.get().isButtonDown(MOUSE_BUTTON_LEFT)) {

      // Get the position that the mouse is pointing to
      Vector2f screenPos = new Vector2f(mouse.getHotSpotPosition().x, mouse.getHotSpotPosition().y);

      // Get the world location of that X,Y value - near
      Vector3f startPoint = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 0);

      // Get the world location of that X,Y value - far
      Vector3f endPoint = DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 1);

      Ray ray = new Ray(startPoint, endPoint.subtract(startPoint));

      results.clear();
      rootNode.findPick(ray, results);

      Vector3f loc = loc = new Vector3f();
      Vector3f[] vertex = new Vector3f[3];

      if (results.getNumber() > 0) {
         TriMesh mesh = (TriMesh) results.getPickData(0).getTargetMesh();

         for (int j = 0; j < mesh.getTriangleQuantity(); j++) {
            mesh.getTriangle(j, vertex);
            if (hit = ray.intersectWhere(vertex[0], vertex[1], vertex[2], loc))
               break;
         }


         if (hit)
            LoggingSystem.getLogger().log(Level.INFO , mesh.getName() + " SUCCESS");
         else
            LoggingSystem.getLogger().log(Level.INFO , mesh.getName() + " fail");
      }
   }
}



summarized output:

INFO: TerrainPage1Page4Page4Block1 fail
INFO: TerrainPage1Page4Page4Block2 fail
INFO: TerrainPage1Page4Page4Block3 fail
INFO: TerrainPage1Page4Page4Block4 fail

INFO: TerrainPage2Page3Page3Block1 fail
INFO: TerrainPage2Page3Page3Block2 fail
INFO: TerrainPage2Page3Page3Block3 fail
INFO: TerrainPage2Page3Page3Block4 fail

INFO: TerrainPage3Page2Page2Block1 fail
INFO: TerrainPage3Page2Page2Block2 fail
INFO: TerrainPage3Page2Page2Block3 fail
INFO: TerrainPage3Page2Page2Block4 fail

INFO: TerrainPage4Page1Page1Block1 SUCCESS
INFO: TerrainPage4Page1Page1Block2 fail
INFO: TerrainPage4Page1Page1Block3 fail
INFO: TerrainPage4Page1Page1Block4 fail


Sorry my English, can anybody help me ? please.

Highnik.

You need to add the translation to the coordinates:


                for (int j = 0; j < mesh.getTriangleQuantity(); j++) {
                    mesh.getTriangle(j, vertex);
                    if (hit = ray.intersectWhere(vertex[0].addLocal(mesh.getWorldTranslation()),
                            vertex[1].addLocal(mesh.getWorldTranslation()),
                            vertex[2].addLocal(mesh.getWorldTranslation()), loc))
                        break;
                }



I'd argue that getTriangle should allow a boolean for auto adding translation.

it is working fine now !