Unproject mouse to get 3D world coordinates Libgdx
My Question: How do i get a 3D model to move with the mouse cursor keeping
the y location of the model at 0. (Using Libgdx)
What i have tried: I'm trying to get my 3D models to follow my cursor.
At the moment i have simply made the models move with the x and y
coordinates of my mouse with adding factors like a multiplier and camera
location. This is not very good because it doesn't follow the cursor and
if i rotate the camera then the model doesn't move in the correct
direction.
This is the code i used for moving the model :
instances.get(modelIndex).transform.setToTranslation(((Gdx.input.getX()-650)/10)
+ cam.position.x,0,((Gdx.input.getY()-400)/10)+ cam.position.z);
Here's a link to an image of the problem (The green circle is where the
mouse is). http://i.imgur.com/kFfSJQ2.png
I know that I'm going about this wrong and that i should be using the
unproject method. I have tried to use the unproject method and did have
little success, the model was just stuck to the near pane of the camera. I
want my object to stay at 0 on the y axes so i used this
cam.unproject(mousePos);
instances.get(modelIndex).transform.setToTranslation(mousePos.x, 0,
mousePos.z); This then resulted in the model moving quite slowly(not with
the mouse), in the right direction. Also when i rotated or moved the
camera the model would be set somewhere in the distance or even behind the
camera.
No comments:
Post a Comment