Sign in to follow this  
Sollum

[SOLVED] 2d cordinate rotation in 3d space

Recommended Posts

Good afternoon!

I am stuck on a little math problem and i dont know how to solve it.
I want to force Object A rotate around Object B. 2d math does it well.

x = -sin(angle) * distanceFromTarget + target->x
y = cos(angle) * distanceFromTarget + target->y
z = target->z

Everything works fine. But i have no idea how to adjust the angle of orbit math wise. I can simply do stuff like glRotatef(90, 1, 0, 0) and it will do the trick, but i want to have exact cords without using GL calls. Furthermore, i dont want to be bound only to one axis.

To make my question more precise - How to "bend" my orbit mathematically?

Share this post


Link to post
Share on other sites
[quote name='Sollum' timestamp='1347458598' post='4979307']
Good afternoon!

I am stuck on a little math problem and i dont know how to solve it.
I want to force Object A rotate around Object B. 2d math does it well.

x = -sin(angle) * distanceFromTarget + target->x
y = cos(angle) * distanceFromTarget + target->y
z = target->z

Everything works fine. [b]But i have no idea how to adjust the angle of orbit math wise[/b]. I can simply do stuff like glRotatef(90, 1, 0, 0) and it will do the trick, but i want to have exact cords without using GL calls. Furthermore, i dont want to be bound only to one axis.

To make my question more precise - How to "bend" my orbit mathematically?
[/quote]

I'm not sure what you mean. If you want to change your angle around of the object orbiting another object all you have to do is change the angle variable in your equation then use glTranslate to move the object (make sure you call glLoadIdentity() every update). Or, you could just do glRotate but it depends what you want to do. Using glTranslate then glRotate probably mess everything up so make sure it's the other way around. Also, you can just have a separate angle of each axis so your call is not bound to a single axis. For instance, glRotate(xAngle,etc); glRotate(yAngle, etc);
Not sure what you're asking though so if you could reword it then that would be easier to answer.

Share this post


Link to post
Share on other sites
Rotations are performed around an axis. 2D rotation is a simplified form of 3D, in which the axis around which the rotation is performed is a conceptual axis extending normal to the 2D plane. IE, if your 2D plane is the XY plane, the axis of rotation is the Z axis. Z coordinates are "ignored", and the math simplifies down to a simple transformation.

In 3D, it gets a bit more complicated because the rotation can be performed around any arbitrary axis. Using [url="http://lmgtfy.com/?q=axis+angle+rotation+3d"]axis-angle rotation[/url], you simply need to establish the axis around which you want to rotate, and specify the angle of rotation. Edited by FLeBlanc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this