Hello, I was using some very basic code that created a cube and was able to rotate it. Such code uses these two global variables:
float rotate_x=0,rotate_y=0;
, this subroutine to capture keyboard input and allow me to rotate the objects through key pressing
void GLFWCALL handleKeypress (int key, int press) {
switch (key) {
case GLFW_KEY_ESC:
exit(1);
break;
case GLFW_KEY_RIGHT:
rotate_x+=5;
break;
case GLFW_KEY_LEFT:
rotate_x-=5;
break;
case GLFW_KEY_UP:
rotate_y+=5;
break;
case GLFW_KEY_DOWN:
rotate_y-=5;
break;
}
}
The main function is a display function where it called
glRotatef (rotate_x, 1.0, 0.0, 0.0);
glRotatef (rotate_y, 0.0, 1.0, 0.0);
Then it called a bunch of glVertex with values manually defined. And it worked very well.
However, when using this code before the glrotate to feed a pre-loaded model to Opengl, it stops working. I mean, the models more or less show up on screen, but I cannot rotate them anymore through the pressing of the directional keys. Here is the code:
int n_triangles = scene.getNTriangles();
Triangle* tri_array = scene.getTriArray();
vector <Mtl> material_container = scene.getMtlContainer();
for (int i=0; i<n_triangles; i++) {
Triangle tri = tri_array[i];
int color_type = tri.getMaterialId();
//cout << "color_type " << color_type << endl;
Mtl color = material_container[color_type];
//exit (-1);
glBegin (GL_TRIANGLES);
glColor3f (color.kd.red,color.kd.green,color.kd.blue);
glVertex3f (tri.getVert11().getX(),tri.getVert11().getY(),tri.getVert11().getZ());
glVertex3f (tri.getVert22().getX(),tri.getVert22().getY(),tri.getVert22().getZ());
glVertex3f (tri.getVert33().getX(),tri.getVert33().getY(),tri.getVert33().getZ());
}*/
glRotatef (rotate_x, 1.0, 0.0, 0.0);
glRotatef (rotate_y, 0.0, 1.0, 0.0);
What I am doing wrong here? Thanks for the help.