Jump to content
  • Advertisement
Sign in to follow this  
kasteon

OpenGL project mouse to World plane

This topic is 3787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I need to project mouse (X, Y) position on OpenGL World plane (for exmple XZ plane - ground of World). Now I`m using gluUnProject() function, but the result is only mouse position in whole World, but I need to project mouse only on XZ plane. Can some one help me? Every idea is welcomed. Thanks Kamil

Share this post


Link to post
Share on other sites
Advertisement
Hello,

by calling gluUnproject you have a line/ray in your world coordinate System, no all you have to do is to intersect the XZ plane with this rayto get the coodinates of the mouse cursor on your XZ plane.


Ext.

Share this post


Link to post
Share on other sites
Thanks.
I had same idea, but I does`t work :( Can you please show me some way to do it?
Thank you very much.

Kamil

Share this post


Link to post
Share on other sites
I could tell you how to do it on paper and how to do it in general, but not how to do it exactly using opengl functions. And I suppose there is a nice cooking recipe how to do it efficiently.

So I'm sorry that I cannot help you.



Ext.

Share this post


Link to post
Share on other sites
Actually, you need two mouse positions to unproject: one with z=0 and one with z=1. Unprojecting those gets you the mouse position on the near plane and the far plane. From those you can construct your ray and intersect it with the plane.

Share this post


Link to post
Share on other sites
I had a similar problem, and i just wrote a function getMouseWorldCoordinates() that first cleared the depth and color buffers, and then created a big rectangle where your ground would go. This way the gluUnProject call would set the mouse y value to zero.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!