This is my problem:
After each rotation I have a new reference.
I need to rotate the object and keep the reference the same
void display(GLFWwindow* window)
{
static int first = 1;
while (!glfwWindowShouldClose(window))
{
// Scale to window size
GLint windowWidth, windowHeight;
glfwGetWindowSize(window, &windowWidth, &windowHeight);
glViewport(0, 0, windowWidth, windowHeight);
// Draw stuff
glClearColor(212.0f/255.0f, 208.0f/255.0f, 200.0f/255.0f, 1.0f); //255 r 236 g 233 b 216
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION_MATRIX);
glLoadIdentity();
gluPerspective(60, (double)windowWidth / (double)windowHeight, 1, 10000);
glMatrixMode(GL_MODELVIEW_MATRIX);
glPushMatrix();
glTranslatef(0, 0, -3);
// drawCube();
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); //Setup The Ambient Light
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); //Setup The Diffuse Light
// glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0); //Position The Light
glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient); //Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse); //Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1); //Position The Light
glLightfv(GL_LIGHT2, GL_AMBIENT, lightAmbient); //Setup The Ambient Light
glLightfv(GL_LIGHT2, GL_DIFFUSE, lightDiffuse); //Setup The Diffuse Light
glLightfv(GL_LIGHT2, GL_POSITION, lightPosition2); //Position The Light
glRotatef(rotacionarx, 1.0f, 0.0f, 0.0f);
glRotatef(rotacionary, 0.0f, 1.0f, 0.0f);
glRotatef(rotacionarz, 0.0f, 0.0f, 1.0f);
/*float radAngle = (rotacionarx / 180.f)*3.1415f;
glRotatef(rotacionarx, 1.f, 0.f, 0.f);
glRotatef(rotacionary, 0.f, cos(radAngle), -sin(radAngle));*/
if (first){
first = 0;
calculamaxmin();
// to scale model
xs = (maxx - minx) / 2.0;
ys = (maxy - miny) / 2.0;
zs = (maxz - minz) / 2.0;
if (xs > ys&&xs > zs) qs = xs;
else if (ys > zs) qs = ys;
else qs = zs;
sk = 1.0 / qs;
// to fit inside cube
u = (minx + maxx) / 2.0;
v = (miny + maxy) / 2.0;
w = (minz + maxz) / 2.0;
}
glScalef(sk, sk, sk);
glTranslatef(-u, -v, -w);
// drawCube();
drawSTL();
glPopMatrix();
// Update Screen
glfwSwapBuffers(window);
// Check for any input, or window movement
glfwPollEvents();
}
}
Thank you again