Im working on a map editor.The map is basically made of cubes of the same size. I also need determine on which side user clicked on cube (i use OpenGL selection buffer) and it seems to work fine.
But i also need to get coordinate(s) of the cube(s) on which user clicked. gluUnproject does that but with a bug.
The returned coordinates depend on camera location / rotation.
Look the pic, the bomb texture should be always on top of the cube, no matter which angle camera (gluLookAt) has and no matter what side of cube user clicked.
You see there is a red cube (the arrow points to it). Like you see i clicked on the bottom of the cube and bomb texture appeared away from the cube. The Y coordinate was increased by 1.
Now look at the second pic:
Here i clicked on right side of the cube and bomb texture appeared in the right place.
Clicking on TOP of the cube (ie. LID) seems to work always fine. I get XYZ without any “+1” added to them.
But whenever i rotate the cam (cam = gluLookAt) the weird things will happen.
I mean now clicking on right side causes adding by 1 and bottom side works fine. Same with left side and vice versa.
For example look at this pic and pay attention to camera rotation:
The bomb texture again is in wrong Y.
Second pic with camera moved “down” and cube is now little bit more above the camera.
Cube LID is textured correctly, bomb texture is in right place.
Can somebody please tell me what causes this “OFFSET” bug that depends on cam location?
Any ideas at least what could be wrong?
Maybe it has something to do with matrices?
I appreciate any help with that bug.