Okay so i made every object with a rotation matrix and a position matrix and it works, without using quarternions. Here some code if anyone is interested. Took me a while to figure this out.
void moveX(float v){ // any object x axis movement
glPushMatrix();
glLoadMatrixf(positionMatrix);
glTranslatef(rotationMatrix[0]*v,rotationMatrix[4]*v,rotationMatrix[8]*v);
glGetFloatv(GL_MODELVIEW_MATRIX,positionMatrix);
glPopMatrix();
}
void rotateX(float v){ //any object x axis rotation
glPushMatrix();
glLoadMatrixf(rotationMatrix);
glRotatef(v,rotationMatrix[0],rotationMatrix[4],rotationMatrix[8]);
glGetFloatv(GL_MODELVIEW_MATRIX,rotationMatrix);
glPopMatrix();
}
void setView(){// camera
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadMatrixf(rotationMatrix);
glMultMatrixf(positionMatrix);
//wrong implementation might have the inverse effect
//rotate first move second will cause the fps effect
//move first rotate second will cause the fixed camera effect
//all other models will/should draw with the camera matrix defaults added to them
}
void draw(){ // model
glPushMatrix();
glMultMatrixf(positionMatrix);
glMultMatrixf(rotationMatrix);
glColor4f(red,green,blue,alpha);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-scale,-scale,-scale);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-scale,-scale,+scale);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-scale,+scale,+scale);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-scale,+scale,-scale);
glTexCoord2f(0.0f, 0.0f); glVertex3f(+scale,-scale,-scale);
glTexCoord2f(0.0f, 1.0f); glVertex3f(+scale,-scale,+scale);
glTexCoord2f(1.0f, 1.0f); glVertex3f(+scale,+scale,+scale);
glTexCoord2f(1.0f, 0.0f); glVertex3f(+scale,+scale,-scale);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-scale,-scale,-scale);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-scale,-scale,+scale);
glTexCoord2f(1.0f, 1.0f); glVertex3f(+scale,-scale,+scale);
glTexCoord2f(1.0f, 0.0f); glVertex3f(+scale,-scale,-scale);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-scale,+scale,-scale);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-scale,+scale,+scale);
glTexCoord2f(1.0f, 1.0f); glVertex3f(+scale,+scale,+scale);
glTexCoord2f(1.0f, 0.0f); glVertex3f(+scale,+scale,-scale);
glVertex3f(-scale,-scale,-scale);
glVertex3f(-scale,+scale,-scale);
glVertex3f(+scale,+scale,-scale);
glVertex3f(+scale,-scale,-scale);
glVertex3f(-scale,-scale,+scale);
glVertex3f(-scale,+scale,+scale);
glVertex3f(+scale,+scale,+scale);
glVertex3f(+scale,-scale,+scale);
glEnd();
glPopMatrix();
}
I used opengl built in matrix operations which gives a really bad cpu performance. I’ll fix my own matrix operation classes later.
glGetFloatv(); is the one causing heavy cpu drain.