• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

### #Actual__SKYe

Posted 16 February 2013 - 07:43 PM

First, when you draw you call



glRotatef(30, 1, 1, 0)


And after drawing you call:



glRotatef(-30, -1, -1, 0)


. To reverse the rotation, you only need to change the sign of the degrees, not the axis, so it should be:



glRotatef(-30, 1, 1, 0);


To avoid this (and to make it easier), instead of doing this:



glTranslatef(self.position[0], self.position[1], self.position[2])
glRotate(30, 1, 1, 0)

... draw ...

glRotate(-30, 1, 1, 0)
glTranslatef(-self.position[0], -self.position[1], -self.position[2])


do



glPushMatrix();
glTranslatef(self.position[0], self.position[1], self.position[2])
glRotate(30, 1, 1, 0)

... draw ...

glPopMatrix();


This way, between glPushMatrix() and glPopMatrix(), you can do whatever transformations you want, that it won't affect the previous matrix.

I don't know if this is exactly your problem, but when you draw the cubes, you're translating them first and then rotating.

In this case, the farther away the cube is from the origin, the longer will be the rotation, because it will be rotating around the axis and not around itself.

Again, i don't know if this is intentional or not, if it is then forget it.

I don't really know Python, but this seems to be a problem with OpenGL, so i hope it helps.

Also, unless the OpenGL spec is different for Python, shouldn't the glRotate() call be glRotatef() (or glRotated() if your using doubles)?

### #2__SKYe

Posted 16 February 2013 - 07:43 PM

First, when you draw you call

glRotatef(30, 1, 1, 0)


And after drawing you call:

glRotatef(-30, -1, -1, 0)


. To reverse the rotation, you only need to change the sign of the degrees, not the axis, so it should be:

 glRotatef(-30, 1, 1, 0);


To avoid this (and to make it easier), instead of doing this:



glTranslatef(self.position[0], self.position[1], self.position[2])
glRotate(30, 1, 1, 0)

... draw ...

glRotate(-30, 1, 1, 0)
glTranslatef(-self.position[0], -self.position[1], -self.position[2])


do



glPushMatrix();
glTranslatef(self.position[0], self.position[1], self.position[2])
glRotate(30, 1, 1, 0)

... draw ...

glPopMatrix();


This way, between glPushMatrix() and glPopMatrix(), you can do whatever transformations you want, that it won't affect the previous matrix.

I don't know if this is exactly your problem, but when you draw the cubes, you're translating them first and then rotating.

In this case, the farther away the cube is from the origin, the longer will be the rotation, because it will be rotating around the axis and not around itself.

Again, i don't know if this is intentional or not, if it is then forget it.

I don't really know Python, but this seems to be a problem with OpenGL, so i hope it helps.

Also, unless the OpenGL spec is different for Python, shouldn't the glRotate() call be glRotatef()?

### #1__SKYe

Posted 16 February 2013 - 07:39 PM

First, when you draw you call glRotatef(30, 1, 1, 0), and after drawing you call glRotatef(-30, -1, -1, 0). To reverse the rotation, you only need to change the sign of the degrees, not the axis, so it should be glRotatef(-30, 1, 1, 0);

To avoid this (and to make it easier), instead of doing this:

glTranslatef(self.position[0], self.position[1], self.position[2])
glRotate(30, 1, 1, 0)

... draw ...

glRotate(-30, 1, 1, 0)
glTranslatef(-self.position[0], -self.position[1], -self.position[2])


do

glPushMatrix();
glTranslatef(self.position[0], self.position[1], self.position[2])
glRotate(30, 1, 1, 0)

... draw ...

glPopMatrix();


This way, between glPushMatrix() and glPopMatrix, you can do whatever transformations you want, that it won't affect the previous matrix.

I don't know if this is exactly your problem, but when you draw the cubes, you're translating them first and then rotating.

In this case, the farther away the cube is from the origin, the longer will be the rotation, because it will be rotating around the axis and not around itself.

Again, i don't know if this is intentional or not, if it is then forget it.

I don't really know Python, but this seems to be a problem with OpenGL, so i hope it helps.

PARTNERS