www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: jumong on September 07, 2010, 05:50:03 am

Title: How to get 3D position by clicking 2d position?
Post by: jumong on September 07, 2010, 05:50:03 am
How to get 3D position by click 2d position?
I did follow
Vector3f rayTo = new Vector3f(renderer.getRayTo((int) event.getX(), (int) event.getY()));

CollisionWorld.ClosestRayResultCallback rayCallback = new CollisionWorld.ClosestRayResultCallback(cameraPosition, rayTo);
dynamicWorld.rayTest(cameraPosition, rayTo, rayCallback);
if (rayCallback.hasHit()) {
  Vector3f vec = rayCallback.hitPointWorld;
}

but position is incorrect, What am I doing wrong?
Title: Re: How to get 3D position by clicking 2d position?
Post by: EgonOlsen on September 07, 2010, 07:43:34 am
What should i say...this isn't a jPCT related question initially posted in an unrelated forum backed up by a private message with the same content...that won't get you anywhere...

You should actually ask this in a forum that deals with whatever you are using there.

IF this is using some data provided by jPCT somehow (albeit that's not visible in your code), make sure that the coordinate systems match...but i've already mentioned that in another post IIRC.
Title: Re: How to get 3D position by clicking 2d position?
Post by: jumong on September 07, 2010, 08:36:54 am
Then, how to get 3d position in JPCT?
Title: Re: How to get 3D position by clicking 2d position?
Post by: EgonOlsen on September 07, 2010, 08:57:31 am
In pure jPCT? Like so: http://www.jpct.net/wiki/index.php/Picking (http://www.jpct.net/wiki/index.php/Picking)