PDA

View Full Version : How do I make a spinning cube?



qwerty5683
10-24-2017, 07:54 PM
I'm trying to make a cube where the center of mass of the cube located at (−0.5, 0.5, 0.0) and it spins continuously
about x-axis and its fix point of rotation is at its center of mass (−0.5, 0.5, 0.0). I know the cube would have 36 vertices so I would have something like
vec4 cube_vertices[36] = {...};


Not sure where to go from here. I need help making the cube itself and then need help with making it spin. Any help would be appreciated.

Goofus43
10-25-2017, 12:35 PM
There are a lot of tutorials online which show how to send data to make a textured cube (it's one of the standards), do a google search. Generally the rotation is done by grabbing the time at start of the program and then using the time difference to increment the rotation matrix in the modelview transform. Note that if you want to rotate around a point as stated that is not the origin (0,0,0) then you should first translate to origin, then rotate, then translate back to starting point. Else you rotate around the origin, not the center of the cube.

Found many such tutorials doing this Google search "tutorial opengl rotating cube" go look.