PDA

View Full Version : Mouse Co-ordinates



Dastagir
10-13-2009, 03:13 AM
hi friends,

How to Convert mouse 2D Co-ordinates into screen 3d Co-ordinates.Please help me regarding this issue.

regards

S.Dastagir

dletozeun
10-13-2009, 03:15 AM
Look at gluUnproject (http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml). BTW, this is not advanced.

punky
10-13-2009, 12:16 PM
i just can give u an not very advanced sample i used for select 3d object as an 2d selection, for selection i calculate 2 circles around the objects and look if the mouse radius is within the object circle

Mouse.y is the Winproc kooridnatecoordinates


typedef struct {
GLfloat x ;
GLfloat y;
GLfloat x3D;
GLfloat y3D;
bool lbuttonDown;
bool rbuttonDown;
}mouse;
mouse Mouse;

this is the winproc part


///
case WM_MOUSEMOVE:
{
Mouse.x =(short)LOWORD(lParam);
Mouse.y= (short)HIWORD(lParam);
// Check to see if the left button is held down:
break;

nHeight,nWidth is the size of the opengl window



GLfloat nh=nHeight/2;
GLfloat nw=nWidth/2;
Mouse.y3D=-(Mouse.y-nh-nHeight)/10;
Mouse.x3D=(Mouse.x-nw-nWidth)/10;