OpenGL Hinge Lock

I found an example program on how to avoid locking the driveshaft: http://www.mfwweb.com/OpenGL/Special_Rotations/Source.c My question is what the void Render_Scene(void) function looks like if we have several objects placed in a vector or list? I used a snippet of this code in my program, but the rotation does not work. I know that there are some problems with matrices. Here is my paintGL () function (I use qt):

 void GLBox::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); double *trans; double *rot; double *matrix; double ang; double **vertexes; //camera glTranslated(xTrans, yTrans, zTrans); glRotated(xRot, 1, 0, 0); glRotated(yRot, 0, 1, 0); glRotated(zRot, 0, 0, 1); for(unsigned int i = 0; i < vector_objects.size(); i++) { glPushMatrix(); trans = (*vector_objects[i]).getTranslation(); rot = (*vector_objects[i]).getRotation(); matrix = (*vector_objects[i]).getMatrixRotation(); vertexes = (*vector_objects[i]).getVertexes_coordinates(); ang = (*vector_objects[i]).getAngle(); glTranslated(trans[0], trans[1], trans[2]); if (ang != 0.0) { //glLoadIdentity (); glRotatef (ang, rot[0], rot[1], rot[2]); glMultMatrixd(matrix); glGetDoublev(GL_MODELVIEW_MATRIX, matrix); } glMultMatrixd(matrix); //drawing for(int j = 0; j < (*vector_objects[i]).getNumber_of_vertexes(); j += 3) { glBegin(GL_TRIANGLES); glVertex3dv( vertexes[j]); glVertex3dv( vertexes[j + 1]); glVertex3dv( vertexes[j + 2]); glEnd(); } glPopMatrix(); } glFlush(); } 

Perhaps you know how to fix this problem? thanks for the help

+1
source share
1 answer

You really want to use quaternions for this. There are many samples. I used one of SGI (written by Gavin Bell) quite successfully. There are also libraries (e.g. GLM ) that include procedures for their use and use. Almost any decent book on the basics of computer graphics will contain at least one or two chapters on quaternion-based turns.

+1
source

Source: https://habr.com/ru/post/923076/


All Articles