• 15
• 15
• 11
• 9
• 10

# [solved] Rotation around axis

This topic is 2521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 on other sites
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 on other sites
OK, i repared it, wrong order of rotations.

##### 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 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?