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

New Topic/Question
This topic is locked




MultiQuote






|