Added the main asteroid belt.

This commit is contained in:
Quantum 2013-11-01 18:42:50 -04:00
parent 617d4913d7
commit ad1970d2d2
7 changed files with 273 additions and 4 deletions

View file

@ -0,0 +1,11 @@
# Blender MTL File: 'mainbeltastroid.blend'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.254837 0.254837 0.254837
Ks 0.159273 0.159273 0.159273
Ni 1.000000
d 1.000000
illum 2

View file

@ -0,0 +1,188 @@
# Blender v2.68 (sub 0) OBJ File: 'mainbeltastroid.blend'
# www.blender.org
mtllib mainbelt.mtl
g Cube
v 0.290193 -0.983926 0.474791
v 0.437387 -1.185402 -0.058906
v -0.278179 0.795311 -0.169923
v -0.176207 0.961698 -0.576060
v -0.749408 0.677473 -0.403865
v -0.843249 1.101376 0.368964
v 0.921024 0.543359 -0.373421
v 1.228522 0.313481 -0.796992
v 1.413710 0.491171 0.016800
v 0.824964 -0.186862 -0.430968
v 0.169830 0.339481 0.955115
v 0.788238 0.224175 0.864338
v 0.579672 -0.319492 0.985489
v -0.850858 0.163566 0.318706
v 0.631733 -0.588108 -0.649624
v -0.094402 -0.322324 -1.249913
v -0.249124 -1.065447 -0.286061
v -0.020992 -0.954752 -0.765611
v -0.632247 -1.107953 -0.512581
v 0.124837 1.315392 0.134372
v 0.577110 0.882123 0.035559
v 0.730517 0.855449 0.648931
v -0.248585 0.742805 0.757662
v 0.897809 -0.004470 0.247323
v 0.947047 -0.715323 0.120538
v 0.998978 -0.476379 0.574922
v -0.353813 -0.204947 1.105379
v -0.981584 -0.532307 0.798081
v -0.690767 0.347252 0.944776
v -1.260799 -0.267750 -0.576518
v -0.903255 -0.554117 -0.072930
v -0.873585 -0.350903 -0.897106
v -1.083754 0.162032 -0.623495
v -0.679472 0.071680 -0.834524
v -0.150468 0.605678 -1.224164
v -0.292701 -0.962443 0.791399
v 0.496173 1.124109 -0.437672
v 0.278706 -0.267373 1.389388
vn 0.529098 -0.735317 0.423514
vn 0.695321 -0.606928 -0.384925
vn 0.383061 -0.662029 0.644190
vn 0.511064 -0.783451 0.353579
vn -0.138461 0.908731 -0.393746
vn 0.593966 0.354629 -0.722110
vn -0.359523 0.891682 0.275039
vn 0.500172 0.865296 0.033023
vn 0.619478 -0.019645 -0.784768
vn 0.619649 0.775456 -0.121254
vn 0.983189 0.132696 0.125425
vn 0.171122 0.151303 0.973563
vn 0.197398 0.332706 0.922139
vn -0.945107 0.286186 0.157704
vn -0.676128 0.735533 -0.042912
vn 0.472294 -0.437683 -0.765096
vn 0.304249 0.044783 -0.951539
vn 0.283559 0.913995 -0.290184
vn 0.830567 -0.515214 0.211455
vn -0.311526 -0.600264 -0.736637
vn 0.483338 -0.690051 -0.538714
vn -0.198815 -0.976318 0.085294
vn -0.529631 -0.847817 -0.026400
vn -0.165780 0.630247 0.758489
vn 0.699114 0.677982 0.227114
vn 0.259894 0.628514 0.733093
vn 0.677448 -0.097416 0.729091
vn 0.987177 0.091683 -0.130671
vn 0.891772 -0.211464 -0.400032
vn -0.233827 -0.388331 0.891361
vn -0.437396 -0.005360 0.899253
vn 0.072347 -0.376917 0.923417
vn -0.408216 0.016368 0.912739
vn -0.926227 -0.356903 -0.121344
vn -0.988224 0.122316 -0.091933
vn -0.501469 0.749738 -0.431766
vn -0.483647 -0.150069 -0.862302
vn -0.612900 0.611035 -0.500988
vn -0.774342 0.425106 -0.468699
vn 0.338886 -0.661704 0.668808
vn 0.178682 -0.903205 0.390248
vn -0.801728 0.596145 0.042935
vn -0.110776 0.869208 -0.481877
vn -0.805509 0.589632 0.059074
vn 0.018409 0.877560 -0.479114
vn 0.759682 -0.149805 0.632805
vn 0.713637 -0.691918 0.109416
vn 0.786427 0.594041 0.169258
vn 0.282085 0.931005 -0.231641
vn 0.583533 -0.247678 0.773398
vn 0.732741 0.478045 0.484317
vn -0.004524 0.581410 0.813598
vn -0.006905 0.433901 0.900934
vn -0.991584 0.014936 -0.128596
vn -0.563344 -0.039656 0.825270
vn -0.858666 0.466868 0.211488
vn 0.423569 -0.519252 -0.742271
vn 0.187865 -0.972846 -0.135191
vn -0.222629 -0.496977 -0.838719
vn -0.081738 -0.961894 -0.260919
vn 0.052827 -0.993867 0.097149
vn -0.766365 -0.585261 0.264864
vn 0.669742 0.730079 -0.135756
vn 0.981787 0.097127 -0.163283
vn 0.963043 0.258645 0.075174
vn -0.116467 -0.992337 0.041265
vn -0.385386 -0.892604 -0.233959
vn -0.546778 0.362906 -0.754541
vn -0.849251 -0.203792 0.487075
vn -0.445795 0.086256 -0.890970
vn -0.893227 0.392020 0.220152
vn -0.412489 0.000355 -0.910963
usemtl Material
s off
f 1//1 2//1 25//1
f 2//2 15//2 25//2
f 1//3 26//3 13//3
f 1//4 25//4 26//4
f 20//5 37//5 4//5
f 37//6 7//6 35//6
f 4//7 5//7 3//7
f 3//8 6//8 23//8
f 7//9 9//9 10//9
f 7//10 21//10 22//10
f 22//11 12//11 24//11
f 11//12 13//12 12//12
f 11//13 12//13 22//13
f 14//14 28//14 29//14
f 14//15 29//15 23//15
f 16//16 8//16 15//16
f 16//17 35//17 8//17
f 35//18 7//18 8//18
f 15//19 8//19 10//19
f 16//20 18//20 32//20
f 18//21 15//21 2//21
f 17//22 2//22 36//22
f 36//23 28//23 31//23
f 20//24 11//24 22//24
f 21//25 37//25 20//25
f 20//26 23//26 11//26
f 26//27 12//27 13//27
f 24//28 25//28 10//28
f 25//29 15//29 10//29
f 27//30 28//30 36//30
f 27//31 29//31 28//31
f 36//32 13//32 27//32
f 27//33 38//33 29//33
f 32//34 19//34 31//34
f 31//35 28//35 14//35
f 35//36 5//36 4//36
f 34//37 33//37 35//37
f 35//38 33//38 5//38
f 34//39 35//39 32//39
f 36//40 1//40 13//40
f 2//41 1//41 36//41
f 3//42 20//42 4//42
f 4//43 37//43 35//43
f 20//44 3//44 23//44
f 3//45 5//45 6//45
f 8//46 7//46 10//46
f 9//47 24//47 10//47
f 21//48 7//48 37//48
f 9//49 7//49 22//49
f 9//50 22//50 24//50
f 11//51 38//51 13//51
f 38//52 11//52 29//52
f 11//53 23//53 29//53
f 5//54 14//54 6//54
f 6//55 14//55 23//55
f 14//56 5//56 33//56
f 15//57 18//57 16//57
f 17//58 19//58 18//58
f 18//59 19//59 32//59
f 17//60 18//60 2//60
f 19//61 17//61 36//61
f 19//62 36//62 31//62
f 21//63 20//63 22//63
f 25//64 24//64 26//64
f 26//65 24//65 12//65
f 38//66 27//66 13//66
f 31//67 30//67 32//67
f 30//68 34//68 32//68
f 30//69 31//69 14//69
f 30//70 33//70 34//70
f 30//71 14//71 33//71
f 35//72 16//72 32//72

View file

@ -28,6 +28,18 @@ class Asteroid(Entity):
self.rotation = rx + 1, ry + 1, rz + 1
class Belt(Entity):
def __init__(self, *args, **kwargs):
self.rotation_angle = kwargs.pop('rotation_angle', 5)
self.world = kwargs.pop('world')
super(Belt, self).__init__(*args, **kwargs)
def update(self):
super(Belt, self).update()
pitch, yaw, roll = self.rotation
self.rotation = pitch, self.world.tick * self.rotation_angle % 360, roll
class Body(Entity):
def __init__(self, *args, **kwargs):
self.rotation_angle = kwargs.pop('rotation_angle', 5)

View file

@ -56,9 +56,12 @@ class Applet(pyglet.window.Window):
def __init__(self, *args, **kwargs):
super(Applet, self).__init__(*args, **kwargs)
texture.init()
l = clock()
self.fps = 0
self.world = load_world("world.json")
print 'Initializing game...'
self.speed = INITIAL_SPEED
self.keys = set()
self.info = True
@ -99,7 +102,6 @@ class Applet(pyglet.window.Window):
glClearColor(0, 0, 0, 1)
glClearDepth(1.0)
texture.init()
if not texture.badcard:
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
@ -130,16 +132,19 @@ class Applet(pyglet.window.Window):
glLightfv(GL_LIGHT1, GL_DIFFUSE, fv4(.5, .5, .5, 1))
glLightfv(GL_LIGHT1, GL_SPECULAR, fv4(1, 1, 1, 1))
print 'Loading asteroids...'
self.asteroid_ids = [model_list(load_model(r"asteroids\01.obj"), 5, 5, 5, (0, 0, 0)),
model_list(load_model(r"asteroids\02.obj"), 5, 5, 5, (0, 0, 0)),
model_list(load_model(r"asteroids\03.obj"), 5, 5, 5, (0, 0, 0)),
model_list(load_model(r"asteroids\04.obj"), 5, 5, 5, (0, 0, 0)),
model_list(load_model(r"asteroids\05.obj"), 5, 5, 5, (0, 0, 0))]
model_list(load_model(r"asteroids\05.obj"), 5, 5, 5, (0, 0, 0)),
]
c = self.cam
c.x, c.y, c.z = self.world.start
c.pitch, c.yaw, c.roll = self.world.direction
print 'Updating entities...'
for entity in self.world.tracker:
entity.update()

View file

@ -1,9 +1,10 @@
from math import *
from pyglet.gl import *
from random import random, uniform
TWOPI = pi * 2
__all__ = ['compile', 'ortho', 'frustrum', 'crosshair', 'circle', 'disk', 'sphere', 'colourball', 'torus']
__all__ = ['compile', 'ortho', 'frustrum', 'crosshair', 'circle', 'disk', 'sphere', 'colourball', 'torus', 'belt']
def compile(pointer, *args, **kwargs):
@ -122,6 +123,25 @@ def colourball(r, lats, longs, colour, fv4=GLfloat * 4):
gluDeleteQuadric(sphere)
def belt(radius, cross, object, count):
for i in xrange(count):
theta = TWOPI * random()
x, y, z = cos(theta) * radius, 0, sin(theta) * radius
# Pretend to move horizontally around the x-axis by delta
# then I multiply it by a rotation matrix about angle theta
# the z-axis need not to be multiplied by the matrix, as it's 0
# Do note the rotation is counter clockwise
delta = cross * uniform(-1, 1)
x += cos(theta) * delta
z += sin(theta) * delta
y += cross * uniform(-1, 1)
glPushMatrix()
glTranslatef(x, y, z)
glCallList(object)
glPopMatrix()
try:
from _glgeom import torus
except ImportError:

View file

@ -278,6 +278,16 @@
"background": true
}
},
"belts": {
"main": {
"model": "asteroids/mainbelt.obj",
"radius": "2.362 * AU",
"cross": 1000,
"scale": 30,
"count": "TEXTURE",
"rotation": 114536500
}
},
"start": {
"z": "AU - 400",
"yaw": 180

View file

@ -17,6 +17,7 @@ except ImportError:
from punyverse.glgeom import *
from punyverse.entity import *
from punyverse.texture import *
from punyverse import texture
from math import pi, sqrt
@ -59,7 +60,7 @@ def load_world(file):
world = World()
au = root.get('au', 2000)
e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': au})
e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': au, 'TEXTURE': texture.max_texture})
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
@ -171,6 +172,28 @@ def load_world(file):
print "Loading %s." % planet
body(planet, info)
for name, info in root['belts'].iteritems():
print 'Loading %s.' % name
x = e(info.get('x', 0))
y = e(info.get('y', 0))
z = e(info.get('z', 0))
radius = e(info.get('radius', 0))
cross = e(info.get('cross', 0))
count = int(e(info.get('count', 0)))
scale = info.get('scale', 1)
longitude = info.get('longitude', 0)
inclination = info.get('inclination', 0)
argument = info.get('argument', 0)
rotation = info.get('period', 31536000)
theta = 360 / (rotation + .0) if rotation else 0
object_id = model_list(load_model(info['model']), info.get('sx', scale), info.get('sy', scale),
info.get('sz', scale), (0, 0, 0))
world.tracker.append(Belt(compile(belt, radius, cross, object_id, count),
(x, y, z), (inclination, longitude, argument),
rotation_angle=theta, world=world))
return world