1 Replies - 413 Views - Last Post: 05 October 2012 - 05:45 AM Rate Topic: -----

#1 JL29  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 50
  • Joined: 20-May 10

(JAVA)3D grid picking in LWJGL without y(up)-axis

Posted 05 October 2012 - 01:33 AM

Hello Dreamincode members!

Currently I am facing a small problem that I can't seem to resolve on myself.
I have a 3D world with a Player object. The user should be able to click in the world so the player can walk to that tile.

The problem is not figuring out the tile in 2D but in 3D this is different. Since there are no pixel x and y's to work with, I don't know how to translate a click at a certain x and y position to the x and z position in world space.

Getting the grid to work is something I could handle on my own but translating the click to an x and z in world space is something I can't get to work. I should not have to worry about the y position because the game is handled in those grids. This takes away one dimension (up - down) so I guess I don't have to cast rays I guess?

My camera is currently using GLU.gluCreateLookAt to creat the view. Here is a method I use to calculate everything. Please dont mind the dirty code and the intialization of those variables. It is just some test method.

public void lookThrough()
    {	
		float distance = 10.0f;
		float camX = distance * (float)-Math.sin(angle);// * (float)Math.cos((yangle));
		float camY = distance;//distance * (float)-Math.sin((yangle));
		float camZ = -distance * (float)Math.cos((angle));// * (float)Math.cos((yangle));
		
        GLU.gluLookAt(	camX + position.x, camY + position.y, camZ + position.z, 
        				lookat.x, lookat.y, lookat.z, 
        				0.0f, 1.0f, 0.0f);
    }


I tried searching for a solution but all I could find was 3D picking... wich is not easy to do and I have the feeling there is a much easier solution to this.

Could someone help me explain how to do this, or give me some information about this topic?

Thanks in advance,

Joshua

Is This A Good Question/Topic? 0
  • +

Replies To: (JAVA)3D grid picking in LWJGL without y(up)-axis

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,259
  • Joined: 27-December 08

Re: (JAVA)3D grid picking in LWJGL without y(up)-axis

Posted 05 October 2012 - 05:45 AM

Please avoid duplicate posting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1