Jump to content
  • Advertisement
Sign in to follow this  
szalejot

[solved] Rotation around axis

This topic is 2670 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,
I'm coding robot symulator, and I have some problems with rotations.
First arm of robot starts at (0, 0, 0). Next I'm doing two rotations: about x-axis and then about y-axis.

This is drawing code:
GLUquadric* arm1 = gluNewQuadric();
gluQuadricDrawStyle(arm1, GLU_FILL);
gluQuadricNormals(arm1, GLU_FLAT);
gluQuadricOrientation(arm1, GLU_OUTSIDE);
glRotatef(arm1angX, 1.0f, 0.0f, 0.0f);
glRotatef(arm1angY, 0.0f, 1.0f, 0.0f);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff_blue);
gluCylinder(arm1, armRadius, armRadius, arm1len, 10, 10);
gluDeleteQuadric(arm1);



For collision detection I need to compute the other end of arm (not (0, 0, 0)).
So I wrote function which will compute this (based on rotation matrixes from http://en.wikipedia....Basic_rotations ):
float3 calculateOffset()
{
float3 result = make_float3(0, 0, arm1len);
float3 tmp = result;
tmp.y = result.y*cos((M_PI * arm1angX) / 180.0f) - result.z*sin((M_PI * arm1angX) / 180.0f);
tmp.z = result.y*sin((M_PI * arm1angX) / 180.0f) + result.z*cos((M_PI * arm1angX) / 180.0f);
result = tmp;
tmp.x = result.x*cos((M_PI * arm1angY) / 180.0f) + result.z*sin((M_PI * arm1angY) / 180.0f);
tmp.z = -1*result.x*sin((M_PI * arm1angY) / 180.0f) + result.z*cos((M_PI * arm1angY) / 180.0f);
result = tmp;
return result;
}


And here problem starts: I draw a Sphere on result coordinates and it match end of arm only when arm1angX==0 or arm1angY==0. When there are both !=0 arm end and sphere are in different places.
What I am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
hi

see the glrotatef specification at:
http://www.opengl.or...ml/glRotate.xml

simply put this calculation into your collision detection on a matrix, this will solve the problem
OR ask modelview matrix from opengl: glgetfloatv(gl_modelview_matrix) and transform you geometry into this matrix to find out correct values

Share this post


Link to post
Share on other sites
Thanks for fast reply.
I used matrix from documentation you linked me, but result is the same as my function.
Where can I do mistake?

hi

see the glrotatef specification at:
http://www.opengl.or...ml/glRotate.xml

simply put this calculation into your collision detection on a matrix, this will solve the problem
OR ask modelview matrix from opengl: glgetfloatv(gl_modelview_matrix) and transform you geometry into this matrix to find out correct values

Share this post


Link to post
Share on other sites
When did this annoying trend get started to delete threads or cripple them by replacing the original post with "solved"? A forum isn't a personal help hotline and functions as archive as much as anything else. Some people DO use the search function and that doesn't work if everything is deleted after the answer was found. Not to mention search engines will find them too and I guess about 80% of technical programming issues are solved by Google finding forum posts where somebody else already had the exact same problem.

All this trend achieves is that the same questions get asked over and over again and the regulars eventually get tired of typing the same answers over and over again. Even if you might not be aware of it, but "I got my reply, delete it" basically means "let's make sure nobody else can see it" and is kind of selfish, isn't it?

Share this post


Link to post
Share on other sites
Sorry, you're right. I will change title.

When did this annoying trend get started to delete threads or cripple them by replacing the original post with "solved"? A forum isn't a personal help hotline and functions as archive as much as anything else. Some people DO use the search function and that doesn't work if everything is deleted after the answer was found. Not to mention search engines will find them too and I guess about 80% of technical programming issues are solved by Google finding forum posts where somebody else already had the exact same problem.

All this trend achieves is that the same questions get asked over and over again and the regulars eventually get tired of typing the same answers over and over again. Even if you might not be aware of it, but "I got my reply, delete it" basically means "let's make sure nobody else can see it" and is kind of selfish, isn't it?

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!