Franco Tocan

05-24-2001, 06:42 AM

Hello,

Can somebody tell me how can I obtain a

glVertex3d from mouse coordinates ?

Thanks,

Franco

Can somebody tell me how can I obtain a

glVertex3d from mouse coordinates ?

Thanks,

Franco

View Full Version : mouse coordinates

Franco Tocan

05-24-2001, 06:42 AM

Hello,

Can somebody tell me how can I obtain a

glVertex3d from mouse coordinates ?

Thanks,

Franco

Can somebody tell me how can I obtain a

glVertex3d from mouse coordinates ?

Thanks,

Franco

martinjy

05-24-2001, 07:00 AM

Well, as I understand it you would click with the mouse on the screen, and a vertex should show up in a perspective view. This is not possible unless you use an already defined z-value. Then you could compute the x- and y-value based on the mouse x- and y-values. Which in term would cause the vertices to show up in the same plane in space. If you give me more information about your task, I can help you further.

Martin

Martin

coredump

05-24-2001, 08:22 AM

use gluUnProject to map window-coords to world space...

gluUnProject(int winx, int winy, int winz, double *model, double *proj, int *view, double *x, double *y, double *z)

winx and winy would be your mouse coords, model is the modelview matrix, proj is the projection matrix, view is the viewport, x y and z are your resultant world space coords. use the glGetDoublev function to get the matrices and glGetIntegerv to get the viewport. you may want to play around with the winz value. if you call the function twice and use 0 for winz in the first call, then use 1, your resultant points define a ray in your world space which you can then use to select objects (use collision detection with the ray and your objects). good luck http://www.opengl.org/discussion_boards/ubb/smile.gif

b

gluUnProject(int winx, int winy, int winz, double *model, double *proj, int *view, double *x, double *y, double *z)

winx and winy would be your mouse coords, model is the modelview matrix, proj is the projection matrix, view is the viewport, x y and z are your resultant world space coords. use the glGetDoublev function to get the matrices and glGetIntegerv to get the viewport. you may want to play around with the winz value. if you call the function twice and use 0 for winz in the first call, then use 1, your resultant points define a ray in your world space which you can then use to select objects (use collision detection with the ray and your objects). good luck http://www.opengl.org/discussion_boards/ubb/smile.gif

b

Franco Tocan

05-24-2001, 09:51 PM

ocvan

Originally posted by coredump:

use gluUnProject to map window-coords to world space...

gluUnProject(int winx, int winy, int winz, double *model, double *proj, int *view, double *x, double *y, double *z)

winx and winy would be your mouse coords, model is the modelview matrix, proj is the projection matrix, view is the viewport, x y and z are your resultant world space coords. use the glGetDoublev function to get the matrices and glGetIntegerv to get the viewport. you may want to play around with the winz value. if you call the function twice and use 0 for winz in the first call, then use 1, your resultant points define a ray in your world space which you can then use to select objects (use collision detection with the ray and your objects). good luck :)

b

This what I do after your answer

I put this code in OnLButtonDown

GLdouble model[16];

double x;

double y;

double z;

GLdouble proj[16];

GLint view[4];

glGetDoublev(GL_MODELVIEW_MATRIX, model);

glGetDoublev(GL_PROJECTION_MATRIX, proj);

glGetIntegerv(GL_VIEWPORT, view);

gluUnProject((GLdouble)point.x, (GLdouble)point.y, (GLdouble)0, model, proj, view, &x, &y, &z );

CString str;

str.Format("x = %d, y = %d, z = %d", x, y, z);

AfxMessageBox(str);

so I have really weird values in x, y, z.

What I want to do is :

having a drawble entity let say a cube

i wish to move it in 3d space with the mouse

Thanks,

Franco

Originally posted by coredump:

use gluUnProject to map window-coords to world space...

gluUnProject(int winx, int winy, int winz, double *model, double *proj, int *view, double *x, double *y, double *z)

winx and winy would be your mouse coords, model is the modelview matrix, proj is the projection matrix, view is the viewport, x y and z are your resultant world space coords. use the glGetDoublev function to get the matrices and glGetIntegerv to get the viewport. you may want to play around with the winz value. if you call the function twice and use 0 for winz in the first call, then use 1, your resultant points define a ray in your world space which you can then use to select objects (use collision detection with the ray and your objects). good luck :)

b

This what I do after your answer

I put this code in OnLButtonDown

GLdouble model[16];

double x;

double y;

double z;

GLdouble proj[16];

GLint view[4];

glGetDoublev(GL_MODELVIEW_MATRIX, model);

glGetDoublev(GL_PROJECTION_MATRIX, proj);

glGetIntegerv(GL_VIEWPORT, view);

gluUnProject((GLdouble)point.x, (GLdouble)point.y, (GLdouble)0, model, proj, view, &x, &y, &z );

CString str;

str.Format("x = %d, y = %d, z = %d", x, y, z);

AfxMessageBox(str);

so I have really weird values in x, y, z.

What I want to do is :

having a drawble entity let say a cube

i wish to move it in 3d space with the mouse

Thanks,

Franco

coredump

05-25-2001, 02:15 AM

this can be done many different ways. one is to save the last mouse position and each time you get a click, use it with the last to obtain a delta, or change in position. use this delta to translate your geometry.

// in your mouse handler

...

delta.x = last.x - cur.x;

delta.y = last.y - cur.y;

...

now use the delta values in translate, or rotate. you may want to scale it (ex. delta * 0.3) just try different values until you acquire the results you need. this works well for x and y translations. if you want a z translation, you will have to come up with a different scheme, perhaps using the right mouse button.

b

// in your mouse handler

...

delta.x = last.x - cur.x;

delta.y = last.y - cur.y;

...

now use the delta values in translate, or rotate. you may want to scale it (ex. delta * 0.3) just try different values until you acquire the results you need. this works well for x and y translations. if you want a z translation, you will have to come up with a different scheme, perhaps using the right mouse button.

b

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.