Archived

This topic is now archived and is closed to further replies.

kill

Rotation Question

Recommended Posts

If I do the following:
        
glRotate(a1, x1, y1, z1);
glRotate(a2, x2, y2, z2);
    
Can someone give me the formula for calculating float a_total = ...; float x_total = ...; float y_total = ...; float z_total = ...; Edited by - kill on 11/4/00 5:40:08 PM

Share this post


Link to post
Share on other sites
Why would you want to add the axes that your rotated around.
I can''t really see what youre asking, but x1, y1,z1tc should only be 1 or 0 as far as my gl knowledge goes - the a1 and a2 are the only things that specify angles. the other params are for specifying which axis to rotate about. They are basically boolean variables

If you want to find out how much you have rotated about an axis through the course of your prog, you should check the GL rotation matricies - not that I know much about them or anything.

Chris

Share this post


Link to post
Share on other sites
You''re asking for the formula for a rotation around a vector right?
I had the same question a while back, and some guy gave me the fomula. I rewrote it for my vector class, but I must admit I still havent tested it. I''m not 100% sure its right now, but thats all I can do...

    
const CVector inline Rotate(const float fAngle, const CVector& Normal) const
{ const float fCos = cosf(fAngle);
const float fSin = sinf(fAngle);
return CVector(
*this * fCos +
((Normal * *this) * (1.0f - fCos)) * Normal +
(*this ^ Normal) * fSin);
}


(ps: the ^ is cross-product)

Share this post


Link to post
Share on other sites
glRotate(a, x, y, z) can take other parameters for x, y and z then 0 and 1. glRotate is basically an angle-axis rotation function, but usually in simple tutorials it's used to set Euler angles.

You misunderstood my question. What I meant to ask is in general, if I have a vector v1 in global coordinates, and a vector v2, whose coordinates are relative to v1, not to the global coordinate system, how do I get GLOBAL coordinates of vector v2?

Thanks.


Edited by - kill on November 5, 2000 7:33:03 PM

Share this post


Link to post
Share on other sites
Thanks, it is glRotate()

But I don''t think adding them will do it. It would if both vectors were at the same coordinate space, but they aren''t... Or am I wrong?

Share this post


Link to post
Share on other sites
Ah - I think I understand your question now?:
Is it anything compared to:

glLoadIdentity();
glTranslate(vector1);
glRotate(rotation1);
glTranslate(vector2);


If so - you could save the OGL matrix by using:
    
float m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);


Value m[12], m[13], m[14] should be the position vector.

Share this post


Link to post
Share on other sites
Yes, you understood correctly, only there is no translation. Here''s what I''m doing. I have an orientation class. All my object classes and camera class are derived from this class. The orientation class holds the position, the vector(direction), and the angle around this vector. I have a function
SetAngleAxis(float a, float x, float y, float z);
which sets the vector and the angle.

I also have
Rotate(float a, float x, float y, float z);
which doesn''t set the vector, but adds the specified vector to the existing one. However, I don''t just add the vector, because the new vector is specified relative to the existing vector. The new vector is not given in global coordinates, that''s why I can''t just add it. This is why I gave the analogy of calling two glRotate() functions in a row. After the first glRotate() is applied, the second one is given relative to the first one.

I could call glRotate() twice, and then get the value from the OpenGL matrix, but I want to keep my orientation class API independent, so I want to calculate the vector positions myself.

Thanks a lot for your help. I hope u can answer this question

Share this post


Link to post
Share on other sites
So you want to do it yourself

I think the best solution would be to implement a vector and matrix class that includes rotation.
If you ever come across my site - there''s a complete CVector and CMatrix class. Maybe that should be good enough?...

Share this post


Link to post
Share on other sites
Thanks.

I think I found a different way to do this... Just a clever use of sines and cosines, but if it won''t work, I''ll take a look at ur matrix class. My system of defining orientation in the world is a little different, but we''ll see...

Thanks for ur help.

BTW, cool screenshots!

Share this post


Link to post
Share on other sites