I’m trying to rotate 2 individual cubes independently. So far that works fine. I use glRotate to do this. I speciy my angle, and the point to rotate around. How do you dertermine “which” way the cube rotates?
I have:
//Cube2
glPushMatrix();
glRotatef(cubRot,-10,0,15);
glTranslatef(-10, 0, 15);
glutWireCube(2);
glPopMatrix();
This cube will rotate in 3d space excactly in place but it rotates in a “wild” fashion. Can you control whether it rotates top to bottom, left to right etc…? I’m really new at this stuff.
ace_man, i think the code you are writing is not correct:
//Cube2
glPushMatrix();
glRotatef(cubRot,-10,0,15);
glTranslatef(-10, 0, 15);
glutWireCube(2);
glPopMatrix();
the glRotatef command takes 4 parameters, the angle of rotation and the other three represent the axis you’re rotating your object on. If you want to rotate your cube on the Y -axis try doing glRotate(cubRot,0.0,1.0,0.0) -> rotate the cube by cubRot in the Y-axis. if cubRot is negative it will spin to the left, if it is positive it will spin to the right. remember that where you place the 1.0 is the correspondent to the axis you want to rotate. don’t forget to increment cubRot after!! if not your cube will just not move at all!
Remember:
glRotate(cubRot,1.0,0.0,0.0)->spin on the x-axis
glRotate(cubRot,0.0,1.0,0.0)->spin on the y-axis
glRotate(cubRot,0.0,0.0,1.0)->spin on the z-axis
glRotate(cubRot,1.0,1.0,0.0)->spin on the x/y diagonal
etc…
ace_man, i think the code you are writing is not correct:
//Cube2
glPushMatrix();
glRotatef(cubRot,-10,0,15);
glTranslatef(-10, 0, 15);
glutWireCube(2);
glPopMatrix();
the glRotatef command takes 4 parameters, the angle of rotation and the other three represent the axis you’re rotating your object on. If you want to rotate your cube on the Y -axis try doing glRotate(cubRot,0.0,1.0,0.0) -> rotate the cube by cubRot in the Y-axis. if cubRot is negative it will spin to the left, if it is positive it will spin to the right. remember that where you place the 1.0 is the correspondent to the axis you want to rotate. don’t forget to increment cubRot after!! if not your cube will just not move at all!
Remember:
glRotate(cubRot,1.0,0.0,0.0)->spin on the x-axis
glRotate(cubRot,0.0,1.0,0.0)->spin on the y-axis
glRotate(cubRot,0.0,0.0,1.0)->spin on the z-axis
glRotate(cubRot,1.0,1.0,0.0)->spin on the x/y diagonal
etc…
I understand the concepts of how glRotate work. You can specify an axis to rotate around OR specify a vector in the form of (x,y,z) like glRotate(angle, 10, 4,-25)
If I place my object at 10, 4, -25 and simply put glRotate(angle, 1,0,0), my cube will “orbit” around 0,0,0. I want it to rotate in place (in differen directions) around the “origin” defined inside the cube. This is why I specified the vector to rotate around.
Maybe I am misunderstanding things, but I thought that you could rotate in only one of these two ways. In my 3Dworld, I have objects scattered all over the place. I want to rotate them all(in place) in differen manners. Sorry, if I was unclear what I was trying to accomplish.
hi… if you want to rotate an object in place (that is about its center) I would do this
push matrix
translate to center of object
rotate the object
translate back
draw object
pop matrix
what I mean by this is that
glRotate(ang, x, y, z) does not select an axis the xyz is a direction, or more accurately the point that a ray will pass through from the origin. what you want to do is different
so instead say we have an object at
20 10 5 and we want to rotate it about the y axis