H3D.org Forum Index Programming Issues
mouse to world | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| erik | Posted on: 2006/7/13 4:55 |
Not too shy to talk ![]() ![]() Joined: 2005/3/15 From: Uppsala Posts: 12 |
mouse to world I am struggling with mapping of the mouse position to world coordinates by using the gluUnproject function. First I obtain the modelview matrix, the projection matrix, and the viewport. Then I use glReadPixels to obtain the depth value at the current position. This information and the mouse position is passed on to gluUnproject in order to obtain the corresponding local position. I don't get it to work properly, someone have any hints?
|
| karlu | Posted on: 2006/7/13 14:03 |
Guru ![]() ![]() Joined: 2004/12/2 From: Sweden Posts: 586 |
Re: mouse to world I never understood how to use gluUnproject, so I implemented my own.
I explain how in this thread, but it might not be very clear. Not using Unproject you have to invert a matrix or two, that's a major downside.Here is the code I use to extract the position, x, of the mouse at the near plane and the vector, v, pointing directly into the screen at that position. It is simple to get from there to a position at a specific depth. I use my own little linear algebra package, but it should be clear enough what's being done. If not, don't hesitate to kick me hard to teach me to be more clear. No guarantees that this is the simplest and most effective way of performing the tast!
|
| erik | Posted on: 2006/7/14 11:28 |
Not too shy to talk ![]() ![]() Joined: 2005/3/15 From: Uppsala Posts: 12 |
Re: mouse to world Thanks KJ, think I got it to work now. With this approach you of course have to implement some raycasting to compute intersection with your objects and in my case that is very simple.
/ Erik |
| karlu | Posted on: 2006/7/17 3:43 |
Guru ![]() ![]() Joined: 2004/12/2 From: Sweden Posts: 586 |
Re: mouse to world Not at all! You may use the Z-value of the depth buffer. The Z-value describes the depth as a function of the near and far plane, so its position in global coordinates can easily be determined. Then all you have to do is a plane intersection, which is trivial. But then again, if you can make readily available tools work, such as the gluUnproject function, then that is always easier than to implement the tool yourself ;-)
|
| mjavaid | Posted on: 2009/12/19 3:05 |
Not too shy to talk ![]() ![]() Joined: 2008/12/23 From: Posts: 15 |
Re: mouse to world Hi KJ
Do you know about how to make such a conversion from window to world coordinates while working in Python. As I'm afraid one may not use OpenGl variables in Python. Thanks Maria |
| karlu | Posted on: 2010/1/3 20:20 |
Guru ![]() ![]() Joined: 2004/12/2 From: Sweden Posts: 586 |
Re: mouse to world You will need to know the values of several OpenGL states to use in the calculations, so I'm afraid you need to use OpenGL anyhow. I'm not sure if calling OpenGL from a Python script would work but you could try it. The coordinate converting code is available here.
|
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |





I explain how in 