jPCT - a 3d engine for Java => Support => Topic started by: miron123 on March 08, 2014, 10:08:06 am

Title: Picking
Post by: miron123 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:
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:

Title: Re: Picking
Post by: EgonOlsen on March 10, 2014, 08:11:40 pm
Your code somehow mixes both approaches. Stick with this way: http://www.jpct.net/wiki/index.php/Picking#The_compatible_way (http://www.jpct.net/wiki/index.php/Picking#The_compatible_way). If it still doesn't work, try to increase http://www.jpct.net/doc/com/threed/jpct/Config.html#collideOffset (http://www.jpct.net/doc/com/threed/jpct/Config.html#collideOffset) to see if that helps.