Jump to content
  • Advertisement
Sign in to follow this  
tkdd08

OpenGL Maintain alignment of two objects with modelview

This topic is 1926 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'm rather new to the world of OpenGL and I've been banging my head against the desk for a while now trying to figure this out so hopefully you guys can help me with that. I have two objects, both of which are modelled statically and maintain their own transformation matrices for any transformations done to them.

One object - the enemy in my game - I want the user to always be staring at, so I maintain a point that represents it's center, and use gluLookAt to accomplish that. Now I want this enemy to be able to rotate up and down around the x axis and left and right around the y axis with respect to the eye point at (0, 0, 0), and when it does the other object - my weapon - will follow it.

Here's a screenshot so you can get a better idea of what I'm working with

All works fine and dandy for the enemy if I am only rotating in one direction, but as soon as I start to mix, things start to break. For example:

Enemy starts at origin, rotate around y-axis 90 degrees so that enemy is now to our right, try to rotate around x-axis relative to view, and enemy/weapon rotate almost in place, this is because the modelview's x-axis is now parallel to the enemy. I would have to rotate around the z-axis to get the effect of rotating up or down.

The other challenge, is that the weapon object is always following the cursor (ie x, y of cursor -> x, y, z on world coordiantes, with z held at -10.0). But if I rotate the enemy+weapon roughly 90 degrees around the y-axis, and then try to move my weapon, it won't move in the x direction anymore (since we're parallel to the modelview's x-axis). 

Any ideas on how to accomplish all this? Any help would be greatly appreciated!!

Share this post


Link to post
Share on other sites
Advertisement
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!