I have some 3D objects. But I want to rotate only some of them with rotation effect. I need to rotate the objects, not the camera. How can I do it using GLFW? Please give me an example.
Asked
Active
Viewed 2,629 times
1 Answers
3
First, the rotation in OpenGL works the same way if you use GLFW or not. If you use OpenGL without shaders (fixed pipeline), for rotate only the object A in your scene you should:
glMatrixMode(GL_MODELVIEW);
glPushMatrix(); // save the current GL_MODELVIEW matrix
glRotatef(angle, 0, 1, 0); // rotate your object
drawObjectAHere(); // draw object A
glPopMatrix(); // restore the GL_MODELVIEW matrix
More information here: How to rotate a specific object in openGL?
If you use shaders, you should create the rotation matrix yourself, and send it to your vertex shader. This library can be useful for create your rotation matrix : http://glm.g-truc.net/0.9.7/index.html And I hope, this tutorial will be useful too, to understand how use this matrix in your shaders, to rotate your object : http://www.geeks3d.com/20111115/how-to-compute-the-position-in-a-vertex-shader-glsl-opengl-part-3/
-
If the object has been drawn, how to move it and rotate it around base axis (X, Y, or Z)? – CherryBelle Apr 17 '16 at 11:50
-
You cannot move or rotate your object after draw it. You should first setup the matrix and then draw it. For move and rotate an object, you can combinate glRotatef(angle,0.0,1.0,0.0); follow by glTranslatef(0.0,0.0,-5.0); Here the object will rotate, then translate. So the object rotate on itself at the coordinate 0.0,0.0,-5.0. – Jérôme Apr 17 '16 at 12:13