Used mass to calculate orbital speed. Added phobos.

This commit is contained in:
Quantum 2013-10-26 16:25:45 -04:00
parent 4074118e6d
commit 5312c4f1dd
7 changed files with 98 additions and 24 deletions

View file

@ -1,4 +1,4 @@
/* Generated by Cython 0.18 on Sat Oct 26 13:44:10 2013 */
/* Generated by Cython 0.18 on Sat Oct 26 16:08:45 2013 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
@ -9084,14 +9084,44 @@ static int __pyx_f_9punyverse_6_model_model_list(struct __pyx_obj_9punyverse_6_m
* point(f, model, tex_id, sx, sy, sz, 0)
* glEnd() # <<<<<<<<<<<<<<
*
* glPopAttrib()
* if tex_id:
*/
glEnd();
/* "punyverse\_model.pyx":341
* glEnd()
*
* if tex_id: # <<<<<<<<<<<<<<
* glBindTexture(GL_TEXTURE_2D, 0)
* glDisable(GL_TEXTURE_2D)
*/
if (__pyx_v_tex_id) {
/* "punyverse\_model.pyx":342
*
* if tex_id:
* glBindTexture(GL_TEXTURE_2D, 0) # <<<<<<<<<<<<<<
* glDisable(GL_TEXTURE_2D)
*
*/
glBindTexture(__pyx_e_9punyverse_6_model_GL_TEXTURE_2D, 0);
/* "punyverse\_model.pyx":343
* if tex_id:
* glBindTexture(GL_TEXTURE_2D, 0)
* glDisable(GL_TEXTURE_2D) # <<<<<<<<<<<<<<
*
* glPopAttrib()
*/
glDisable(__pyx_e_9punyverse_6_model_GL_TEXTURE_2D);
goto __pyx_L25;
}
__pyx_L25:;
}
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
/* "punyverse\_model.pyx":341
* glEnd()
/* "punyverse\_model.pyx":345
* glDisable(GL_TEXTURE_2D)
*
* glPopAttrib() # <<<<<<<<<<<<<<
* glPopMatrix()
@ -9099,7 +9129,7 @@ static int __pyx_f_9punyverse_6_model_model_list(struct __pyx_obj_9punyverse_6_m
*/
glPopAttrib();
/* "punyverse\_model.pyx":342
/* "punyverse\_model.pyx":346
*
* glPopAttrib()
* glPopMatrix() # <<<<<<<<<<<<<<
@ -9108,7 +9138,7 @@ static int __pyx_f_9punyverse_6_model_model_list(struct __pyx_obj_9punyverse_6_m
*/
glPopMatrix();
/* "punyverse\_model.pyx":344
/* "punyverse\_model.pyx":348
* glPopMatrix()
*
* glEndList() # <<<<<<<<<<<<<<
@ -9116,7 +9146,7 @@ static int __pyx_f_9punyverse_6_model_model_list(struct __pyx_obj_9punyverse_6_m
*/
glEndList();
/* "punyverse\_model.pyx":345
/* "punyverse\_model.pyx":349
*
* glEndList()
* return display # <<<<<<<<<<<<<<

View file

@ -338,6 +338,10 @@ cpdef int model_list(WavefrontObject model, float sx=1, float sy=1, float sz=1,
point(f, model, tex_id, sx, sy, sz, 0)
glEnd()
if tex_id:
glBindTexture(GL_TEXTURE_2D, 0)
glDisable(GL_TEXTURE_2D)
glPopAttrib()
glPopMatrix()

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View file

@ -0,0 +1,20 @@
# Ns = Phong specular component. Ranges from 0 to 1000. (I've seen various statements about this range (see below))
# Kd = Diffuse color weighted by the diffuse coefficient.
# Ka = Ambient color weighted by the ambient coefficient.
# Ks = Specular color weighted by the specular coefficient.
# d = Dissolve factor (pseudo-transparency). Values are from 0-1. 0 is completely transparent, 1 is opaque.
# Ni = Refraction index. Values range from 1 upwards. A value of 1 will cause no refraction. A higher value implies refraction.
# illum = (0, 1, or 2) 0 to disable lighting, 1 for ambient & diffuse only (specular color set to black), 2 for full lighting (see below)
# sharpness = ? (see below)
# c
# map_Bump = Bump texture map.
# map_d = Opacity texture map.
# refl = reflection type and filename (?)
newmtl white
Ka 1 1 1
Kd 1 1 1
Ks 0 0 0
map_Kd phobos.jpg
illum 2
Ns 8

View file

@ -35,6 +35,7 @@ class Planet(Entity):
self.atmosphere = kwargs.pop('atmosphere', 0)
self.cloudmap = kwargs.pop('cloudmap', 0)
self.last_tick = 0
self.mass = kwargs.pop('mass', None)
super(Planet, self).__init__(*args, **kwargs)
def update(self):

View file

@ -1,5 +1,9 @@
{
"au": "greatly shrunk so planets can actually be seen",
"au": 10000,
"tick": 4320,
"length": "kilometre per world units for satellite distance, note that this is approx 10x smaller than AU",
"length": 637,
"planets": {
"earth": {
"texture": ["earth.jpg", "earth_medium.jpg", "earth_small.jpg", [0, 0.28, 1, 1]],
@ -8,6 +12,7 @@
"pitch": -90,
"yaw": 23.4,
"roll": -90,
"mass": 5.97219e+24,
"atmosphere": {
"cloud_texture": "cloudmap.png",
"diffuse_texture": "atmosphere_earth.png",
@ -17,8 +22,7 @@
"moon": {
"texture": ["moon.jpg", "moon_medium.jpg", "moon_small.jpg", [0.53, 0.53, 0.53, 1]],
"radius": 27.25,
"distance": 603.357,
"orbit_speed": 1,
"distance": 384399,
"eccentricity": 0.0549,
"inclination": 5.145,
"pitch": -90,
@ -27,7 +31,7 @@
"iss": {
"model": "satellites/iss.obj",
"inclination": 51.65,
"distance": 110,
"distance": 68000,
"scale": 5
}
}
@ -37,7 +41,14 @@
"radius": 53.3,
"z": "1.524 * AU",
"pitch": -90,
"yaw": 25.19
"yaw": 25.19,
"mass": 6.4185e+23,
"satellites": {
"phobos": {
"distance": 93770,
"model": "satellites/phobos.obj"
}
}
},
"jupiter": {
"texture": ["jupiter.jpg", "jupiter_medium.jpg", "jupiter_small.jpg", [0.65, 0.36, 0.19, 1]],

View file

@ -1,10 +1,6 @@
from bisect import bisect_left
from collections import OrderedDict
from operator import itemgetter
from functools import partial
import hashlib
import os.path
import random
try:
import json
@ -23,7 +19,9 @@ from punyverse.glgeom import *
from punyverse.entity import *
from punyverse.texture import *
AU = 2000
from math import pi, sqrt
G = 6.67384e-11 # Gravitation Constant
def get_best_texture(info, optional=False):
@ -62,6 +60,8 @@ def load_world(file):
world = World()
e = lambda x: eval(str(x), {'__builtins__': None}, {'AU': root.get('au', 2000)})
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
if 'start' in root:
info = root['start']
@ -95,22 +95,30 @@ def load_world(file):
else:
object_id = compile(sphere, radius, int(radius / 2), int(radius / 2), texture, lighting=lighting)
elif 'model' in info:
scale = info.get('scale', 10)
scale = info.get('scale', 1)
object_id = model_list(load_model(info['model']), info.get('sx', scale), info.get('sy', scale),
info.get('sz', scale), (0, 0, 0))
else:
print 'Nothing to load for %s.' % name
params = {}
if parent is None:
type = Planet
else:
x, y, z = parent.location
distance = e(info.get('distance', 100))
x -= distance
type = partial(Satellite, parent=parent, orbit_speed=info.get('orbit_speed', 1),
distance=distance, eccentricity=info.get('eccentricity', 0),
inclination=info.get('inclination', 0), longitude=info.get('longitude', 0),
argument=info.get('argument', 0))
distance = e(info.get('distance', 100)) # Distance here means semi-major axis
if hasattr(parent, 'mass') and parent.mass is not None:
speed = 360 / (2 * pi * sqrt((distance * 1000) ** 3 / (G * parent.mass)) / tick)
else:
speed = info.get('orbit_speed', 1)
type = Satellite
params.update(parent=parent, orbit_speed=speed,
distance=distance / length, eccentricity=info.get('eccentricity', 0),
inclination=info.get('inclination', 0), longitude=info.get('longitude', 0),
argument=info.get('argument', 0))
if 'mass' in info:
params['mass'] = info['mass']
atmosphere_id = 0
cloudmap_id = 0
@ -128,7 +136,7 @@ def load_world(file):
atmosphere_id = compile(disk, radius, radius + size, 30, atm_texture)
object = type(object_id, (x, y, z), (pitch, yaw, roll), delta=delta,
atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background)
atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background, **params)
world.tracker.append(object)
if 'ring' in info: