class Planet: def __init__(self, imageId, major_axis, minor_axis, speed, rot_speed, size, textureMoon=None, moonOrbitParams=None): self.texture = Texture(imageId) self.qobj = gluNewQuadric() gluQuadricTexture(self.qobj, GL_TRUE) self.ellipse = Ellipse(major_axis, minor_axis, speed) self.rotation = 0 self.lastCoords = 0 self.rot_speed = rot_speed self.size = size if(textureMoon is None): self.moon = False else: self.moon = True self.textureMoon = Texture(textureMoon) self.moonSize = moonOrbitParams[2] self.moonOrbit = Ellipse(moonOrbitParams[0], moonOrbitParams[0], moonOrbitParams[1]) def draw(self): coords = self.ellipse.getCoords() glPushMatrix() glTranslatef(coords[0], 0.0, coords[1]) self.lastCoords = coords if(self.moon): glPushMatrix() self.moonOrbit.render() coords = self.moonOrbit.getCoords() glTranslatef(coords[0], 0.0, coords[1]) glScalef(self.moonSize, self.moonSize, self.moonSize) glBindTexture(GL_TEXTURE_2D, self.textureMoon.textureId) gluSphere(self.qobj, 1, 50, 50) glPopMatrix() glRotatef(270, 1.0, 0.0, 0.0) glRotatef(self.rotation, 0.0, 0.0, 1.0) glScalef(self.size, self.size, self.size) glBindTexture(GL_TEXTURE_2D, self.texture.textureId) gluSphere(self.qobj, 1, 50, 50) glPopMatrix() self.ellipse.render() self.rotation += self.rot_speed
class Asteroid: def __init__(self, fire): self.asteroid = OBJ("asteroid.obj", textureFile="asteroid.jpg") self.ellipse = Ellipse(18, 4, 0.17) self.fire = fire self.angle = 0 def draw(self): coords = self.ellipse.getCoords() glPushMatrix() glTranslatef(13.0, 0.0, 8.0) glRotatef(35, 0.0, 1.0, 0.0) self.ellipse.render() glTranslatef(coords[0], 0, coords[1] - 0.35) glPushMatrix() glScalef(0.0006, 0.0006, 0.0006) self.asteroid.render() glPopMatrix() glRotatef(90, 0, 0, 1) glRotatef(90 * math.sin(math.radians(self.angle)), 1.0, 0.0, 0.0) self.fire.drawSystem() glPopMatrix() self.angle += 0.17