Author Topic: Picking  (Read 771 times)

Offline miron123

  • byte
  • *
  • Posts: 16
    • View Profile
« on: March 08, 2014, 10:08:06 am »
I m working on a 3D world and Im trying to translate my camera position but i want to attach the mouse cursor at the clicked position. If I move my camera my mouse cursor stays at the position where I first clicked. My problem now is that I implemented an orbital camera. cause of that I cant calc a factor based on the camera hight( camera.getPostion().z) but I need postion in the world where I clicked with the mouse.
I tried to implement the picking methods in the forum but I never got a correct object.
My code:

Code: [Select]
private static void getObject3DatMouse(int x, int y) {
SimpleVector dir = Interact2D.reproject2D3DWS(camera, buffer, x, y).normalize();
Object[] res = world.calcMinDistanceAndObject3D(camera.getPosition(),dir, 10000 /* or whatever */);
int[] res1 = Interact2D.pickPolygon(world.getVisibilityList(), camera.getPosition(), dir);
if (res1 != null) {
Object3D picked = world.getObject(res1[1]);
Object3D pciked = (Object3D) res[1];

I just tried to get an object based on the Mouse.getX() and Mouse.getY() positon but I always res:
  • = 1.0E12 and [1]= null

the res1 array is always empty.
So my question is, if I do the picking incorrectly or I have to improve it somehow.
Of cause I included:


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11829
    • View Profile
Re: Picking
« Reply #1 on: March 10, 2014, 08:11:40 pm »
Your code somehow mixes both approaches. Stick with this way: If it still doesn't work, try to increase to see if that helps.