From 376628d9a6f604569267c762a9630b3ae2d0233a Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 27 Oct 2013 19:51:55 -0400 Subject: [PATCH] Added proper rotation and proper camera moving. --- punyverse/camera.py | 16 +++++----------- punyverse/entity.py | 9 +++++---- punyverse/game.py | 2 +- punyverse/world.json | 14 +++++++++++++- punyverse/world.py | 9 ++++++--- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/punyverse/camera.py b/punyverse/camera.py index 7e17b48..e397333 100644 --- a/punyverse/camera.py +++ b/punyverse/camera.py @@ -10,17 +10,11 @@ class Camera(object): self.yaw = yaw self.roll = roll - def move(self, dx, dy, dz): - pitch = self.pitch - yaw = self.yaw - if pitch > 90 or pitch < -90: - pitch = -pitch - 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 move(self, speed): + dx, dy, dz = self.direction() + self.x += dx * speed + self.y += dy * speed + self.z += dz * speed def mouse_move(self, dx, dy): if self.pitch > 90 or self.pitch < -90: diff --git a/punyverse/entity.py b/punyverse/entity.py index 70f56b0..7fe5b54 100644 --- a/punyverse/entity.py +++ b/punyverse/entity.py @@ -31,12 +31,13 @@ class Asteroid(Entity): class Body(Entity): 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.cloudmap = kwargs.pop('cloudmap', 0) self.last_tick = 0 self.mass = kwargs.pop('mass', None) super(Body, self).__init__(*args, **kwargs) + self.initial_roll = self.rotation[2] def update(self): super(Body, self).update() @@ -44,7 +45,7 @@ class Body(Entity): if self.last_tick != framedata.tick: self.last_tick = framedata.tick 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 @@ -102,12 +103,12 @@ class Satellite(Body): return id def update(self): - super(Body, self).update() + super(Body, self).update() # Notice how the parent class is skipped if self.last_tick != framedata.tick: self.last_tick = framedata.tick 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.parent.update() diff --git a/punyverse/game.py b/punyverse/game.py index a55a6e1..9d80677 100644 --- a/punyverse/game.py +++ b/punyverse/game.py @@ -53,7 +53,7 @@ class Applet(pyglet.window.Window): cam.roll += 4 if key.S in self.keys: cam.roll -= 4 - cam.move(0, 0, -self.speed * 128 * 0.003) + cam.move(self.speed) framedata.tick += self.tick for entity in self.world.tracker: diff --git a/punyverse/world.json b/punyverse/world.json index 8baf004..b239e10 100644 --- a/punyverse/world.json +++ b/punyverse/world.json @@ -22,6 +22,7 @@ "yaw": 23.4, "roll": -90, "mass": 5.97219e+24, + "rotation": 86400, "atmosphere": { "cloud_texture": "cloudmap.png", "diffuse_texture": "atmosphere_earth.png", @@ -35,8 +36,10 @@ "sma": 384399, "eccentricity": 0.0549, "inclination": 5.145, + "rotation": 0, "pitch": -90, - "yaw": 6.68 + "yaw": 6.68, + "roll": -90 }, "iss": { "model": "satellites/iss.obj", @@ -53,6 +56,7 @@ "pitch": -90, "yaw": 25.19, "mass": 6.4185e+23, + "rotation": 88643, "satellites": { "phobos": { "distance": 9377, @@ -70,12 +74,14 @@ "pitch": -90, "yaw": 3.13, "comment": "satellites here are 3/10 the virtual distance than physical, and five times the size", + "rotation": 35730, "satellites": { "io": { "texture": ["moons/io.jpg", "moons/io_small.jpg", [0.62, 0.56, 0.35, 1]], "radius": "1821.3 * 5", "distance": 126510, "sma": 421700, + "rotation": 0, "pitch": -90, "inclination": 2.21, "eccentricity": 0.0041 @@ -86,6 +92,7 @@ "distance": 201270, "sma": 670900, "pitch": -90, + "rotation": 0, "inclination": 2.71, "eccentricity": 0.009 }, @@ -95,6 +102,7 @@ "distance": 321120, "sma": 1070400, "pitch": -90, + "rotation": 0, "inclination": 2.51, "eccentricity": 0.0013 }, @@ -104,6 +112,7 @@ "distance": 564810, "sma": 1882700, "pitch": -90, + "rotation": 0, "inclination": 0.192, "eccentricity": 0.0074 } @@ -116,6 +125,7 @@ "z": "9.58 * AU", "pitch": -90, "yaw": 26.73, + "rotation": 38052, "ring": { "texture": "ring_saturn.png", "distance": 1169, @@ -129,6 +139,7 @@ "z": "19.23 * AU", "pitch": -90, "yaw": 97.77, + "rotation": -62064, "ring": { "texture": "ring_uranus.png", "pitch": 0, @@ -143,6 +154,7 @@ "radius": 24764, "mass": 1.0243e+26, "z": "30.5 * AU", + "rotation": 57996, "pitch": -90, "yaw": 28.32 }, diff --git a/punyverse/world.py b/punyverse/world.py index 94f1813..cff312a 100644 --- a/punyverse/world.py +++ b/punyverse/world.py @@ -83,7 +83,7 @@ def load_world(file): pitch = e(info.get('pitch', 0)) yaw = e(info.get('yaw', 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 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 sma = e(info.get('sma', distance)) # Semi-major axis used to calculate orbital speed 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: speed = info.get('orbit_speed', 1) type = Satellite @@ -139,7 +142,7 @@ def load_world(file): if not cheap: 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) world.tracker.append(object)