rotations help

Started by
3 comments, last by BriW111 20 years, 6 months ago
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 :-)
Advertisement
You might want to have a look at the Milkshape animation code at Real soon now.

Hope this helps!
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
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]
Another place to check out is http://www.digitalfanatics.org/projects/3d_story/3dindex.html, chapter 3.

[edited by - e8johan on September 25, 2003 1:49:58 AM]

This topic is closed to new replies.

Advertisement