Think about glRotatef()
as if you actually "draw" an axis, which starts from (0, 0, 0) and points to whatever coordinates you give to it. Your example uses the (0, 1, 0) which is the World Y axis.
But let's say, you want to rotate your P
point (10, 10, 0) around the A
axis [(3, 3, 3), (3, 4, 3)].This axis -- as you can see -- is parallel with Y.
First you have to translate your whole world so now your A
axis will lie on World Y axis.
glClear( GL_COLOR_BUFFER_BIT )
glTranslatef( 3, 3, 3 )
Now you have to rotate everything around the World Y axis:
glRotatef( rotation*100.0, 0, 1, 0 )
And then you have to translate it back:
glTranslatef( -3, -3, -3 )
And now you can draw your P
point:
glBegin( GL_POINTS )
glVertex3f( 10, 10, 0 )
glEnd()
NOTE: forget my stupid glBegin/End example, it is ancient, use VAOs and VBOs!
I don't know what framework are you using, but here is a pretty basic example in pyglet:
import pyglet
from pyglet.gl import *
window = pyglet.window.Window( 256, 256 )
x = 0
def update(dt):
global x
x += 1
@window.event
def on_draw():
global x
glClear( GL_COLOR_BUFFER_BIT )
glLoadIdentity()
glTranslatef( 128, 128, 0 )
glRotatef( x, 0, 0, 1 )
glTranslatef( -128, -128, 0 )
glBegin( GL_TRIANGLES )
glColor3f( 1, 0, 0 )
glVertex3f( 128, 128, 0 )
glColor3f( 0, 1, 0 )
glVertex3f( 200, 128, 0 )
glColor3f( 0, 0, 1 )
glVertex3f( 200, 200, 0 )
glEnd()
pyglet.clock.schedule_interval(update, 1/60)
pyglet.app.run()
AND THE RESULT IS HERE!