mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Added better handling of orbits.
This commit is contained in:
parent
c21c0b9535
commit
118bcd02a7
|
@ -1,4 +1,4 @@
|
|||
from math import *
|
||||
from math import sin, cos, radians
|
||||
|
||||
|
||||
class Camera(object):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,9 +317,19 @@ class Applet(pyglet.window.Window):
|
|||
glPopMatrix()
|
||||
|
||||
if self.orbit and hasattr(entity, 'get_orbit') and hasattr(entity, 'parent'):
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue