diff --git a/punyverse/camera.py b/punyverse/camera.py index e397333..a1eb0db 100644 --- a/punyverse/camera.py +++ b/punyverse/camera.py @@ -1,4 +1,4 @@ -from math import * +from math import sin, cos, radians class Camera(object): diff --git a/punyverse/entity.py b/punyverse/entity.py index 300e788..5e2af80 100644 --- a/punyverse/entity.py +++ b/punyverse/entity.py @@ -36,6 +36,10 @@ class Body(Entity): self.last_tick = 0 self.mass = kwargs.pop('mass', None) self.world = kwargs.pop('world') + orbit_distance = kwargs.pop('orbit_distance', 40000) + .0 + self.orbit_show = orbit_distance * 1.25 + self.orbit_blend = orbit_distance / 4 + self.orbit_opaque = orbit_distance super(Body, self).__init__(*args, **kwargs) self.initial_roll = self.rotation[2] @@ -83,19 +87,11 @@ class Satellite(Body): id = glGenLists(1) glNewList(id, GL_COMPILE) - glDisable(GL_LIGHTING) - glDisable(GL_TEXTURE_2D) - glPushAttrib(GL_LINE_BIT | GL_CURRENT_BIT) - glColor3f(1, 1, 1) - glLineWidth(1) glBegin(GL_LINE_LOOP) for theta in xrange(360): x, z, y = self.orbit.orbit(theta) glVertex3f(x, y, z) glEnd() - glPopAttrib() - glEnable(GL_TEXTURE_2D) - glEnable(GL_LIGHTING) glEndList() self.orbit_id = id diff --git a/punyverse/game.py b/punyverse/game.py index 1b02c4f..f0b20f3 100644 --- a/punyverse/game.py +++ b/punyverse/game.py @@ -75,15 +75,15 @@ class Applet(pyglet.window.Window): # On standard world: 10x is one day per second, 100x is 10 days, 300x is a month # 900x is a quarter, 1825 is a half year, 3650 is a year, 36500 is a decade, 365000 is a century # and yes the individual hours and seconds look ugly - self.ticks = [20, 40, 60, # Second range - 120, 300, 600, 1200, 1800, 2700, 3600, # Minute range - 7200, 14400, 21600, 43200, 86400, # Hour range - 172800, 432000, 604800, # 2, 5, 7 days - 1209600, 2592000, # 2 week, 1 month - 5270400, 7884000, 15768000, 31536000, # 2, 3, 6, 12 months - 63072000, 157680000, 315360000, # 2, 5, 10 years - 630720000, 1576800000, 3153600000, # 20, 50, 100 years - ] + self.ticks = [20, 40, 60, # Second range + 120, 300, 600, 1200, 1800, 2700, 3600, # Minute range + 7200, 14400, 21600, 43200, 86400, # Hour range + 172800, 432000, 604800, # 2, 5, 7 days + 1209600, 2592000, # 2 week, 1 month + 5270400, 7884000, 15768000, 31536000, # 2, 3, 6, 12 months + 63072000, 157680000, 315360000, # 2, 5, 10 years + 630720000, 1576800000, 3153600000, # 20, 50, 100 years + ] self.ticks = [i / 20 for i in self.ticks] self.__time_per_second_cache = None self.__time_per_second_value = None @@ -256,8 +256,9 @@ class Applet(pyglet.window.Window): glEnable(GL_LIGHTING) glEnable(GL_BLEND) world = self.world + get_distance = entity_distance(x, y, z) if x != world.x or y != world.y or z != world.z: - world.tracker.sort(key=entity_distance(x, y, z), reverse=True) + world.tracker.sort(key=get_distance, reverse=True) world.tracker.sort(key=attrgetter('background'), reverse=True) world.x, world.y, world.z = x, y, z @@ -316,10 +317,20 @@ class Applet(pyglet.window.Window): glPopMatrix() if self.orbit and hasattr(entity, 'get_orbit') and hasattr(entity, 'parent'): - glPushMatrix() - glTranslatef(*entity.parent.location) - glCallList(entity.get_orbit()) - glPopMatrix() + parent = entity.parent + distance = get_distance(parent) + if distance < parent.orbit_show: + glPushMatrix() + glTranslatef(*entity.parent.location) + glDisable(GL_LIGHTING) + glPushAttrib(GL_LINE_BIT | GL_CURRENT_BIT) + glColor4f(1, 1, 1, 1 if distance < parent.orbit_opaque else + (1 - (distance - parent.orbit_opaque) / parent.orbit_blend)) + glLineWidth(1) + glCallList(entity.get_orbit()) + glPopAttrib() + glEnable(GL_LIGHTING) + glPopMatrix() glColor4f(1, 1, 1, 1) glDisable(GL_TEXTURE_2D) diff --git a/punyverse/world.json b/punyverse/world.json index 49d5d6b..685de2f 100644 --- a/punyverse/world.json +++ b/punyverse/world.json @@ -28,6 +28,7 @@ "diffuse_texture": "atmosphere_earth.png", "diffuse_size": 30 }, + "orbit_distance": "AU", "satellites": { "moon": { "texture": ["moon.jpg", "moon_medium.jpg", "moon_small.jpg", [0.53, 0.53, 0.53, 1]], @@ -57,6 +58,7 @@ "yaw": 25.19, "mass": 6.4185e+23, "rotation": 88643, + "orbit_distance": "AU", "satellites": { "phobos": { "distance": 9377, @@ -75,6 +77,7 @@ "yaw": 3.13, "comment": "satellites here are 3/10 the virtual distance than physical, and five times the size", "rotation": 35730, + "orbit_distance": "3 * AU", "satellites": { "io": { "texture": ["moons/io.jpg", "moons/io_small.jpg", [0.62, 0.56, 0.35, 1]], @@ -131,6 +134,7 @@ "distance": 1169, "size": 2247 }, + "orbit_distance": "4 * AU", "satellites": { "titan": { "texture": ["moons/titan.jpg", "moons/titan_small.jpg", [0.52, 0.39, 0.23, 1]], @@ -212,6 +216,7 @@ "pitch": -90, "yaw": 97.77, "rotation": -62064, + "orbit_distance": "6 * AU", "ring": { "texture": "ring_uranus.png", "pitch": 0, @@ -226,6 +231,7 @@ "radius": 24764, "mass": 1.0243e+26, "z": "30.5 * AU", + "orbit_distance": "6 * AU", "rotation": 57996, "pitch": -90, "yaw": 28.32 diff --git a/punyverse/world.py b/punyverse/world.py index 51d8b7a..6495f1e 100644 --- a/punyverse/world.py +++ b/punyverse/world.py @@ -59,7 +59,8 @@ def load_world(file): root = json.load(f, object_pairs_hook=OrderedDict) world = World() - e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': root.get('au', 2000)}) + au = root.get('au', 2000) + e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': au}) tick = root.get('tick', 4320) # How many second is a tick? length = root.get('length', 4320) # Satellite distance is in km, divide by this gets in world units world.tick_length = tick @@ -86,6 +87,7 @@ def load_world(file): rotation = e(info.get('rotation', 86400)) radius = e(info.get('radius', length)) / length background = info.get('background', False) + orbit_distance = e(info.get('orbit_distance', au)) if 'texture' in info: cheap, skip, texture = get_best_texture(info['texture'], optional=info.get('optional', False)) @@ -103,7 +105,7 @@ def load_world(file): else: print 'Nothing to load for %s.' % name - params = {'world': world} + params = {'world': world, 'orbit_distance': orbit_distance} if parent is None: type = Body else: