Added proper rotation and proper camera moving.

This commit is contained in:
Quantum 2013-10-27 19:51:55 -04:00
parent 54a134c73e
commit 376628d9a6
5 changed files with 30 additions and 20 deletions

View file

@ -10,17 +10,11 @@ class Camera(object):
self.yaw = yaw self.yaw = yaw
self.roll = roll self.roll = roll
def move(self, dx, dy, dz): def move(self, speed):
pitch = self.pitch dx, dy, dz = self.direction()
yaw = self.yaw self.x += dx * speed
if pitch > 90 or pitch < -90: self.y += dy * speed
pitch = -pitch self.z += dz * speed
dx = -dx
dy = -dy
dz = -dz
self.z += dx * cos(radians(yaw - 90)) + dz * cos(radians(yaw))
self.x -= dx * sin(radians(yaw - 90)) + dz * sin(radians(yaw))
self.y += dy * sin(radians(pitch - 90)) + dz * sin(radians(pitch))
def mouse_move(self, dx, dy): def mouse_move(self, dx, dy):
if self.pitch > 90 or self.pitch < -90: if self.pitch > 90 or self.pitch < -90:

View file

@ -31,12 +31,13 @@ class Asteroid(Entity):
class Body(Entity): class Body(Entity):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.delta = kwargs.pop('delta', 5) self.rotation_angle = kwargs.pop('rotation_angle', 5)
self.atmosphere = kwargs.pop('atmosphere', 0) self.atmosphere = kwargs.pop('atmosphere', 0)
self.cloudmap = kwargs.pop('cloudmap', 0) self.cloudmap = kwargs.pop('cloudmap', 0)
self.last_tick = 0 self.last_tick = 0
self.mass = kwargs.pop('mass', None) self.mass = kwargs.pop('mass', None)
super(Body, self).__init__(*args, **kwargs) super(Body, self).__init__(*args, **kwargs)
self.initial_roll = self.rotation[2]
def update(self): def update(self):
super(Body, self).update() super(Body, self).update()
@ -44,7 +45,7 @@ class Body(Entity):
if self.last_tick != framedata.tick: if self.last_tick != framedata.tick:
self.last_tick = framedata.tick self.last_tick = framedata.tick
pitch, yaw, roll = self.rotation pitch, yaw, roll = self.rotation
roll += self.delta / 100.0 roll = (self.initial_roll + framedata.tick * self.rotation_angle) % 360
self.rotation = pitch, yaw, roll self.rotation = pitch, yaw, roll
@ -102,12 +103,12 @@ class Satellite(Body):
return id return id
def update(self): def update(self):
super(Body, self).update() super(Body, self).update() # Notice how the parent class is skipped
if self.last_tick != framedata.tick: if self.last_tick != framedata.tick:
self.last_tick = framedata.tick self.last_tick = framedata.tick
pitch, yaw, roll = self.rotation pitch, yaw, roll = self.rotation
roll += self.delta / 100.0 roll = (self.initial_roll + framedata.tick * self.rotation_angle) % 360
self.rotation = pitch, yaw, roll self.rotation = pitch, yaw, roll
self.parent.update() self.parent.update()

View file

@ -53,7 +53,7 @@ class Applet(pyglet.window.Window):
cam.roll += 4 cam.roll += 4
if key.S in self.keys: if key.S in self.keys:
cam.roll -= 4 cam.roll -= 4
cam.move(0, 0, -self.speed * 128 * 0.003) cam.move(self.speed)
framedata.tick += self.tick framedata.tick += self.tick
for entity in self.world.tracker: for entity in self.world.tracker:

View file

@ -22,6 +22,7 @@
"yaw": 23.4, "yaw": 23.4,
"roll": -90, "roll": -90,
"mass": 5.97219e+24, "mass": 5.97219e+24,
"rotation": 86400,
"atmosphere": { "atmosphere": {
"cloud_texture": "cloudmap.png", "cloud_texture": "cloudmap.png",
"diffuse_texture": "atmosphere_earth.png", "diffuse_texture": "atmosphere_earth.png",
@ -35,8 +36,10 @@
"sma": 384399, "sma": 384399,
"eccentricity": 0.0549, "eccentricity": 0.0549,
"inclination": 5.145, "inclination": 5.145,
"rotation": 0,
"pitch": -90, "pitch": -90,
"yaw": 6.68 "yaw": 6.68,
"roll": -90
}, },
"iss": { "iss": {
"model": "satellites/iss.obj", "model": "satellites/iss.obj",
@ -53,6 +56,7 @@
"pitch": -90, "pitch": -90,
"yaw": 25.19, "yaw": 25.19,
"mass": 6.4185e+23, "mass": 6.4185e+23,
"rotation": 88643,
"satellites": { "satellites": {
"phobos": { "phobos": {
"distance": 9377, "distance": 9377,
@ -70,12 +74,14 @@
"pitch": -90, "pitch": -90,
"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,
"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]],
"radius": "1821.3 * 5", "radius": "1821.3 * 5",
"distance": 126510, "distance": 126510,
"sma": 421700, "sma": 421700,
"rotation": 0,
"pitch": -90, "pitch": -90,
"inclination": 2.21, "inclination": 2.21,
"eccentricity": 0.0041 "eccentricity": 0.0041
@ -86,6 +92,7 @@
"distance": 201270, "distance": 201270,
"sma": 670900, "sma": 670900,
"pitch": -90, "pitch": -90,
"rotation": 0,
"inclination": 2.71, "inclination": 2.71,
"eccentricity": 0.009 "eccentricity": 0.009
}, },
@ -95,6 +102,7 @@
"distance": 321120, "distance": 321120,
"sma": 1070400, "sma": 1070400,
"pitch": -90, "pitch": -90,
"rotation": 0,
"inclination": 2.51, "inclination": 2.51,
"eccentricity": 0.0013 "eccentricity": 0.0013
}, },
@ -104,6 +112,7 @@
"distance": 564810, "distance": 564810,
"sma": 1882700, "sma": 1882700,
"pitch": -90, "pitch": -90,
"rotation": 0,
"inclination": 0.192, "inclination": 0.192,
"eccentricity": 0.0074 "eccentricity": 0.0074
} }
@ -116,6 +125,7 @@
"z": "9.58 * AU", "z": "9.58 * AU",
"pitch": -90, "pitch": -90,
"yaw": 26.73, "yaw": 26.73,
"rotation": 38052,
"ring": { "ring": {
"texture": "ring_saturn.png", "texture": "ring_saturn.png",
"distance": 1169, "distance": 1169,
@ -129,6 +139,7 @@
"z": "19.23 * AU", "z": "19.23 * AU",
"pitch": -90, "pitch": -90,
"yaw": 97.77, "yaw": 97.77,
"rotation": -62064,
"ring": { "ring": {
"texture": "ring_uranus.png", "texture": "ring_uranus.png",
"pitch": 0, "pitch": 0,
@ -143,6 +154,7 @@
"radius": 24764, "radius": 24764,
"mass": 1.0243e+26, "mass": 1.0243e+26,
"z": "30.5 * AU", "z": "30.5 * AU",
"rotation": 57996,
"pitch": -90, "pitch": -90,
"yaw": 28.32 "yaw": 28.32
}, },

View file

@ -83,7 +83,7 @@ def load_world(file):
pitch = e(info.get('pitch', 0)) pitch = e(info.get('pitch', 0))
yaw = e(info.get('yaw', 0)) yaw = e(info.get('yaw', 0))
roll = e(info.get('roll', 0)) roll = e(info.get('roll', 0))
delta = e(info.get('delta', 5)) 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)
@ -111,7 +111,10 @@ def load_world(file):
distance = e(info.get('distance', 100)) # Semi-major axis when actually displayed in virtual space distance = e(info.get('distance', 100)) # Semi-major axis when actually displayed in virtual space
sma = e(info.get('sma', distance)) # Semi-major axis used to calculate orbital speed sma = e(info.get('sma', distance)) # Semi-major axis used to calculate orbital speed
if hasattr(parent, 'mass') and parent.mass is not None: if hasattr(parent, 'mass') and parent.mass is not None:
speed = 360 / (2 * pi * sqrt((sma * 1000) ** 3 / (G * parent.mass)) / tick) period = 2 * pi * sqrt((sma * 1000) ** 3 / (G * parent.mass))
speed = 360 / (period / tick)
if not rotation: # Rotation = 0 assumes tidal lock
rotation = period
else: else:
speed = info.get('orbit_speed', 1) speed = info.get('orbit_speed', 1)
type = Satellite type = Satellite
@ -139,7 +142,7 @@ def load_world(file):
if not cheap: if not cheap:
atmosphere_id = compile(disk, radius, radius + size, 30, atm_texture) atmosphere_id = compile(disk, radius, radius + size, 30, atm_texture)
object = type(object_id, (x, y, z), (pitch, yaw, roll), delta=delta, object = type(object_id, (x, y, z), (pitch, yaw, roll), rotation_angle=360 / (rotation / (tick + .0)),
atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background, **params) atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background, **params)
world.tracker.append(object) world.tracker.append(object)