View Full Version : Get the square position in 3D chess board

01-26-2005, 04:47 AM
Hi all,

I'm design a 3D chess with openGL.

Each piece is model and the board is one other model

I got a camera moved. (forward, backward .. )

I would like to be able to move a piece when the user will click on the piece square

My problem is : when I will move the camera, the coordonate of each square will
move as well.

I would like a algorithm or a function to know which square was picked by the user.

Because I don't want to calculate again the square coordonate every time that the camera move.



01-26-2005, 05:46 AM
1)Just read the depth of the pixel you clicked at and pass it (along with the x,y) to gluUnproject (if I haven't messed anything up...). Then you will have exact coords of where you clicked - deriving which square was clicked won't be too difficult.
2) The board is on a fixed level (say y = 2.0). You can get the Matrix and assume certain y. X and z will be relatively easy to calculate within your own code(Done it long ago, don't remember exactly how...).
3)As far as I remember, there is a tutorial on picking on nehe.gamedev.net.
I hope that's what you asked about...

01-26-2005, 06:36 AM
Thanks Lurker_pas

I looked at gluUnProject it is exactly that I wanted

I have to work on now