class Satellite(Body): def __init__(self, *args, **kwargs): self.parent = kwargs.pop('parent') self.orbit_speed = kwargs.pop('orbit_speed', 1) # Semi-major axis and eccentricity defines orbit distance = kwargs.pop('distance', 100) eccentricity = kwargs.pop('eccentricity', 0) # Inclination, longitude of ascending node, and argument of periapsis defines orbital plane inclination = kwargs.pop('inclination', 0) longitude = kwargs.pop('longitude', 0) argument = kwargs.pop('argument', 0) # Orbit calculation self.orbit_id = None self.orbit_cache = None self.theta = 0 # OpenGL's z-axis is reversed self.orbit = KeplerOrbit(distance, eccentricity, inclination, longitude, argument) super(Satellite, self).__init__(*args, **kwargs) def get_orbit(self): # Cache key is the three orbital plane parameters and eccentricity cache = (self.orbit.eccentricity, self.orbit.longitude, self.orbit.inclination, self.orbit.argument) if self.orbit_cache == cache: return self.orbit_id if self.orbit_id is not None: glDeleteLists(self.orbit_id, 1) id = glGenLists(1) glNewList(id, GL_COMPILE) glBegin(GL_LINE_LOOP) for theta in xrange(360): x, z, y = self.orbit.orbit(theta) glVertex3f(x, y, z) glEnd() glEndList() self.orbit_id = id self.orbit_cache = cache return id def update(self): super(Body, self).update() # Notice how the parent class is skipped if self.last_tick != self.world.tick: self.last_tick = self.world.tick pitch, yaw, roll = self.rotation roll = (self.initial_roll + self.world.tick * self.rotation_angle) % 360 self.rotation = pitch, yaw, roll self.parent.update() px, py, pz = self.parent.location self.theta = self.world.tick * self.orbit_speed % 360 x, z, y = self.orbit.orbit(self.theta) self.location = (x + px, y + py, z + pz)
def __init__(self, *args, **kwargs): self.parent = kwargs.pop('parent') self.orbit_speed = kwargs.pop('orbit_speed', 1) # Semi-major axis and eccentricity defines orbit distance = kwargs.pop('distance', 100) eccentricity = kwargs.pop('eccentricity', 0) # Inclination, longitude of ascending node, and argument of periapsis defines orbital plane inclination = kwargs.pop('inclination', 0) longitude = kwargs.pop('longitude', 0) argument = kwargs.pop('argument', 0) # Orbit calculation self.orbit_id = None self.orbit_cache = None self.theta = 0 # OpenGL's z-axis is reversed self.orbit = KeplerOrbit(distance, eccentricity, inclination, longitude, argument) super(Satellite, self).__init__(*args, **kwargs)