I’m trying to animate a 3D car in PyOpenGL to make it move along an eight-shaped track. The problem is that I don’t seem to find the best way to make the car turn along the curve of the track.
The way that I’ve tried is making the car translate over the x and z axis, as well as making a glRotate to rotate the car, but that doesn’t seem like the best way to do it.
My code looks like this:
# Values for all the animation process, including translate and rotate
angulo = 0.0
traslacion = 0.0
giroXl = 0.0
giroZl = 0.0
...
# The display function, where the 3D car model recieves the instructions for
# the movement along the track
def display():
...
glTranslate(0, 0, traslacion) # Moves the car along a straight line, this works just fine
# This is where I try to turn the car along the track curve, this is where I'm stuck
if bandRecta == True:
glTranslate(giroXl, 0, giroZl)
glRotate(angulo, 0.0, 1.0, 0.0)
...
# The glutTimerFunc, where the values get manipulated
def movimiento():
...
angulo = angulo + (1.0 if angulo < 180.0 else 0.0)
traslacion = traslacion + (1.0 if traslacion < 100.0 else 0.0)
if traslacion == 50:
bandRecta = True
giroXl = giroXl + (1.0 if giroXl < 50.0 else 0.0)
giroZl = giroZl + (1.0 if giroZl < 50.0 else 0.0)
For the record, I’m using Python 3.5 with PyOpenGL (obviously) and GLUT.