Jump to content
  • Advertisement
Sign in to follow this  
TFS_Waldo

OpenGL Rotate an object to mouse's coordinates?

This topic is 4837 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

Hey there. I hope someone can help. I am not sure how to do this, and I have searched for it. I found all kinds of posts, but nothing helped. I am using OpenGL, and I need to use the mouse's coordinates and rotate an object (turret) at the bottom of the screen to where the mouse is pointing. I also do not know how to get the mouse coordinates in order to rotate the object. If someone can post some code I would greatly appreciate it! =) Thanks in advance, Matt U.

Share this post


Link to post
Share on other sites
Advertisement
Will someone please reply? I know the answer is out there. But I cannot find it anywhere on the forums when I search. I see a lot of people that figured it out, but I can't. =(

Share this post


Link to post
Share on other sites
Google for gluUnproject. There are a lot of sites with info on how to use it (including GameDev).

And don't bump a post if it isn't answered in 45 minutes. Give people some time to answer it first.

EDIT: Nevermind about gluUnproject, I think you're talking about rotating something that's already in window coordinates.

Share this post


Link to post
Share on other sites
I am not sure I understand what you want, but let's try.
Firstly: getting the mouse position. That depends on your Platform. Windows I guess? Thank I would suggest you look into DirectInput.

Now, setting the angle of the turret:
ydist - Y-Distance between turret and mouse position
xdist - X-Distance between turret and mouse position

You get the angle in radiant with:
atan2(Y,X);

To get it in degree (OpenGL uses degrees):
atan2(Y,X)*180.0f/M_PI;

I hope that helped a bit also I do not think I cleared all your problems.

Share this post


Link to post
Share on other sites
Hey, sorry for the bump. =P That's my own fault. I was just in a hurry to find the answer. And I get frustrated with stuff like this sometimes. =P Sorry!

And I'll try that code to see if it works. I believe that is what I am looking for. =)

Share this post


Link to post
Share on other sites
Quote:
Original post by TFS_Waldo
Hey, sorry for the bump. =P That's my own fault. I was just in a hurry to find the answer. And I get frustrated with stuff like this sometimes. =P Sorry!
No worries, we all get frustrated at times and it was more for future reference than admonishment. Sorry I misunderstood your post at first.

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!