Jump to content
  • Advertisement

Archived

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

BriW111

rotations help

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

I am currently working on some skeletal animations for milkshape ascii, and have hit a very large brick wall. I cannot seem to get the rotations to work correctly. I went back to the basics, and tried rotating a quad around the y axis by Pi radians, and it worked correctly. I then tried rotating around the z axis by Pi, which also worked well. but then when i tried rotating around both at once, it won''t rotate by the full Pi (3.141592654 radians). I tried using Quaternions but they did not work correctly for me. I also have tried using matrices, but i''m bad at them and have found that all the examples out there do not work correctly when rotating around 2 or 3 axes at once (even gamedev.net''s articles proved useless). here is the sourecode for current rotating quad: static float a=-1,b=-1,c=1,d=1; static float e=1,f=-1,g=-1,h=1; static float i=0,j=0,k=0,l=0; glBegin(GL_QUADS); glVertex3f(a,e,i); glVertex3f(b,f,j); glVertex3f(c,g,k); glVertex3f(d,h,l); glEnd(); float aa,bb,cc,dd; float angle; static int counter; // we will rotate for exactly 300 frames, so // calculate the angle accordingly angle = (3.141592654 / 300); counter ++; // after 300 frames, stop. The object should have //rotated by exactly Pi if(counter < 301) { aa = a; bb = b; cc = c; dd = d; // Calculate the z-axis rotation a = cos(angle) * (aa) - sin(angle) * e ; b = cos(angle) * (bb) - sin(angle) * f ; c = cos(angle) * (cc) - sin(angle) * g ; d = cos(angle) * (dd) - sin(angle) * h ; e = sin(angle) * (aa) + cos(angle) * e; f = sin(angle) * (bb) + cos(angle) * f; g = sin(angle) * (cc) + cos(angle) * g; h = sin(angle) * (dd) + cos(angle) * h; //make sure we update our vectors after the first //rotation, otherwise the quad will stretch/skew // and rotate funny aa = a; bb = b; cc = c; dd = d; //Calculate the y-axis rotation a = cos(angle) * (aa) - sin(angle) * i; b = cos(angle) * (bb) - sin(angle) * j; c = cos(angle) * (cc) - sin(angle) * k; d = cos(angle) * (dd) - sin(angle) * l; i = sin(angle) * (aa) + cos(angle) * i; j = sin(angle) * (bb) + cos(angle) * j; k = sin(angle) * (cc) + cos(angle) * k; l = sin(angle) * (dd) + cos(angle) * l; } I am very bad with matrices, so i prefer to stick with this method instead. Realize that this sort of code will be used to do skeletal animation, so i cannot simply use glRotatef. I would GREATLY appreciate your help, as my Milkshape loader/animator is just a few lines of code away from completion. This is my only roadblock. Thank you all for any help you can give. PS - Just for you optimize freaks out there, my animation code pre-caches all the animation frames, and calculates the sin/cos of the angles just once. the above code i just made on-the-fly to demonstrate the problem i am having :-)

Share this post


Link to post
Share on other sites
Advertisement
I already took a look at that code, but i''m so bad with matrices i can''t really understand how his code works. I''m guessing that he puts the original x,y,z values of each vertex into the matrix and then multiplies by the rotation matrix, but i''m really not sure. It would take me a long while before i could figure out how he did it. I was kinda hoping someone could explain it as simply as possible, maybe with some easy-to-read code...

Thank you for replying anyway, i appreciate it

Share this post


Link to post
Share on other sites
Have a read of the articles in the Articles & Resources section of GameDev that deal with rotations and matrices. Some of them are a little heavy and work as great sleeping pills but keep plodding through them. You are trying to do the same thing that matrices do which is a good way to learn about how a rotation matrix works and you are on the right track. That is how I started a few months ago. In the end you will find that you will be using matrices with out even thinking about it once you play with them enough and you will see they are a kind of short hand for what you are trying to do now. Use your favorite search engine to search for articles on using matrices and how they work. A good article on vectors and matrices that starts from the basics can be found on Mark Feldmans site.



[edited by - nfz on September 23, 2003 10:56:42 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!