Jump to content
  • Advertisement
Sign in to follow this  
MattCa

Rotating an object around the player?

This topic is 2482 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 guys,
I am looking for a way to rotate an object around the player, using the players rotation as the angle (so the object remains at the same screen co-ordinates even when the player moves the mouse).

I've heard of something called Arcball rotation, but I've only seen it applied with the camera, another object, and rotation transformations.

If possible, is there a method that doesn't require matrices?

Thanks,
Matt.

Share this post


Link to post
Share on other sites
Advertisement

If possible, is there a method that doesn't require matrices?


You say matrices - I presume you're doing this in 3D? Or is it 2D? Or doom-like 3D? Despite the ambiguity, some thoughts:

You could:
* not rotate it at all. When you do your modelview transformation for the rest of the world, you're rotating the world around to your viewing frustum. So simply render your object in a different matrix context.
* unwind the rotations you applied to the world due to the player's orientation (negative angles, reverse order).
* Push the matrix stack before rotating the world to the player's orientation, render the world, pop the matrix and render the object.

Now, I've said matrix all over the place when you say you want something that doesn't require matrices - because I'm not sure what technology you're using. But if you were doing all this without matrices it would still be the same solutions, they'd just look different:
* don't rotate it at all. place the object where you want it to appear with respect to the viewport.
* apply the reverse of whatever rotations you're currently doing
* make a copy of the transformation with whatever it is you *are* using, prior to rotation, then apply that when it comes time to render the object

For example, if you want to render a 3d object as a UI widget in front of the player, you'd go with the first option - you'd have a completely different projection and modelview context for that object, irrespective of the player's world position, and you'd probably render it after you'd rendered the world.

If you're going to look into things like NeHe's Arcball, or Quaternions, or... just about anything else... you're going to run into matrices. And they're not that bad, really.

Share this post


Link to post
Share on other sites

[quote name='MattCa' timestamp='1320264947' post='4879845']
If possible, is there a method that doesn't require matrices?


You say matrices - I presume you're doing this in 3D? Or is it 2D? Or doom-like 3D? Despite the ambiguity, some thoughts:

You could:
* not rotate it at all. When you do your modelview transformation for the rest of the world, you're rotating the world around to your viewing frustum. So simply render your object in a different matrix context.
* unwind the rotations you applied to the world due to the player's orientation (negative angles, reverse order).
* Push the matrix stack before rotating the world to the player's orientation, render the world, pop the matrix and render the object.

Now, I've said matrix all over the place when you say you want something that doesn't require matrices - because I'm not sure what technology you're using. But if you were doing all this without matrices it would still be the same solutions, they'd just look different:
* don't rotate it at all. place the object where you want it to appear with respect to the viewport.
* apply the reverse of whatever rotations you're currently doing
* make a copy of the transformation with whatever it is you *are* using, prior to rotation, then apply that when it comes time to render the object

For example, if you want to render a 3d object as a UI widget in front of the player, you'd go with the first option - you'd have a completely different projection and modelview context for that object, irrespective of the player's world position, and you'd probably render it after you'd rendered the world.

If you're going to look into things like NeHe's Arcball, or Quaternions, or... just about anything else... you're going to run into matrices. And they're not that bad, really.
[/quote]

Hi!
Yeah, I'm working in 3D. Basically, I have an object that I want to be translated around the player (using the players rotation). The reason I want it to set the x, y and z co-ordinates instead of just rotating while drawing is because I want to check for collisions with the object (kind of like a 'grabbed object' that gets dropped when it collides with the scenery - something like Amnesia's ability to pick up objects).

And by 'no matrices' I mean would it be possible to do the above math without them? E.g. vector1.x = Math.sin(toRadians(rotation.x)); etc etc :D

Regards,
Matt.

Share this post


Link to post
Share on other sites

Cant you do the transformation using matrices and then get the position out of the resulting matrix?



I'm using OpenGL 1.1 at the moment, so the only matrices I'm able to use are the transformation and the modelview matrices..
Do you have any links/code that could help me to extract the transformed position from one of these? I'm not really sure how to extract the new position :/

Thanks,
Matt.

Share this post


Link to post
Share on other sites

I'm using OpenGL 1.1 at the moment, so the only matrices I'm able to use are the transformation and the modelview matrices..
Do you have any links/code that could help me to extract the transformed position from one of these? I'm not really sure how to extract the new position :/


No. They are not the only matrices available to you. You've just chosen that situation for yourself. Technically speaking it is possible to extract the world space transforms using glGet, however this will also include the camera transform, which is not really what you want (And you'd still need to write your own matrix methods). I'd probably suggest that you include a decent maths library in your app (from what I've seen, glm looks respectable, and is SIMD optimised). Do all of your glTranslate/glRotate etc calls with the equivalent matric functions instead, and then upload the resulting matrices using glMultMatrix. This way you have access to the matrices, and you'll be in a nice place should you want to port the code to GLES or GL3/GL4 in the future.....

As a general rule of thumb, if you need to access some values associated with an object, then that value should be stored as a member variable of that object. Calling glTranslate et al, is the equivalent of catapulting the data into the atlantic ocean. Yes it's possible to retrieve the values, but it wil be a massive PITA. It would have been easier to have made a copy of them before you strapped them into the catapult.....

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!