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