Added a sort of corona effect.

This commit is contained in:
Quantum 2013-11-02 15:00:47 -04:00
parent 7e25a79968
commit 0ae75da2a7
5 changed files with 75 additions and 13 deletions

View file

@ -45,6 +45,7 @@ class Body(Entity):
self.rotation_angle = kwargs.pop('rotation_angle', 5)
self.atmosphere = kwargs.pop('atmosphere', 0)
self.cloudmap = kwargs.pop('cloudmap', 0)
self.corona = kwargs.pop('corona', 0)
self.last_tick = 0
self.mass = kwargs.pop('mass', None)
self.world = kwargs.pop('world')

View file

@ -314,7 +314,9 @@ class Applet(pyglet.window.Window):
glPopAttrib()
glPopMatrix()
if self.atmosphere and hasattr(entity, 'atmosphere') and entity.atmosphere:
has_corona = hasattr(entity, 'corona') and entity.corona
has_atmosphere = hasattr(entity, 'atmosphere') and entity.atmosphere
if self.atmosphere and (has_corona or has_atmosphere):
glPushMatrix()
x0, y0, z0 = entity.location
dx, dy, dz = x - x0, y - y0, z - z0
@ -326,6 +328,9 @@ class Applet(pyglet.window.Window):
glTranslatef(x0, y0, z0)
glRotatef(pitch, 1, 0, 0)
glRotatef(yaw, 0, 1, 0)
if has_corona:
glCallList(entity.corona)
if has_atmosphere:
glCallList(entity.atmosphere)
glPopMatrix()

View file

@ -4,7 +4,8 @@ from random import random, uniform
TWOPI = pi * 2
__all__ = ['compile', 'ortho', 'frustrum', 'crosshair', 'circle', 'disk', 'sphere', 'colourball', 'torus', 'belt']
__all__ = ['compile', 'ortho', 'frustrum', 'crosshair', 'circle', 'disk', 'sphere', 'colourball', 'torus', 'belt',
'flare']
def compile(pointer, *args, **kwargs):
@ -77,6 +78,42 @@ def disk(rinner, router, segs, tex):
glDisable(GL_TEXTURE_2D)
def flare(rinner, router, res, prob, tex):
glEnable(GL_TEXTURE_2D)
glDisable(GL_LIGHTING)
glBindTexture(GL_TEXTURE_2D, tex)
last_x = 1
last_y = 0
last_theta = 0
factor = TWOPI / res
rdelta = (router - rinner) * 5
glBegin(GL_QUADS)
for i in xrange(res + 1):
theta = last_theta + factor
x = cos(theta)
y = sin(theta)
if random() > prob:
distance = router + rdelta * random()
avg_theta = (last_theta + theta) / 2
x0, y0 = rinner * last_x, rinner * last_y
x1, y1 = rinner * x, rinner * y
x2, y2 = distance * cos(avg_theta), distance * sin(avg_theta)
glTexCoord2f(0, 0)
glVertex2f(x0, y0)
glTexCoord2f(0, 1)
glVertex2f(x1, y1)
glTexCoord2f(1, 0)
glVertex2f(x2, y2)
glTexCoord2f(1, 1)
glVertex2f(x2, y2)
last_theta = theta
last_x = x
last_y = y
glEnd()
glEnable(GL_LIGHTING)
glDisable(GL_TEXTURE_2D)
def sphere(r, lats, longs, tex, lighting=True, fv4=GLfloat * 4):
"""
Sphere function from the OpenGL red book.

View file

@ -20,7 +20,13 @@
"pitch": -90,
"yaw": 7.25,
"mass": 1.9891e+30,
"rotation": 2164320
"rotation": 2164320,
"atmosphere": {
"corona_texture": "sun_corona.png",
"corona_size": 300,
"corona_division": 100,
"corona_prob": 0.5
}
},
"mercury": {
"texture": ["mercury.jpg", "mercury_small.jpg", [0.44, 0.43, 0.43]],

View file

@ -131,22 +131,35 @@ def load_world(file):
atmosphere_id = 0
cloudmap_id = 0
corona_id = 0
if 'atmosphere' in info:
atmosphere_data = info['atmosphere']
size = e(atmosphere_data.get('diffuse_size', None))
atm_size = e(atmosphere_data.get('diffuse_size', None))
atm_texture = atmosphere_data.get('diffuse_texture', None)
cloud_texture = atmosphere_data.get('cloud_texture', None)
corona_texture = atmosphere_data.get('corona_texture', None)
if cloud_texture is not None:
cheap, _, cloud_texture = get_best_texture(cloud_texture)
if not cheap:
cloudmap_id = compile(sphere, radius + 2, division, division, cloud_texture,
lighting=False)
if corona_texture is not None:
cheap, _, corona = get_best_texture(corona_texture)
if not cheap:
corona_size = atmosphere_data.get('corona_size', radius / 2)
corona_division = atmosphere_data.get('corona_division', 100)
corona_ratio = atmosphere_data.get('corona_ratio', 0.5)
corona_id = compile(flare, radius, radius + corona_size, corona_division,
corona_ratio, corona)
elif atm_texture is not None:
cheap, _, atm_texture = get_best_texture(atm_texture)
if not cheap:
atmosphere_id = compile(disk, radius, radius + size, 30, atm_texture)
atmosphere_id = compile(disk, radius, radius + atm_size, 30, atm_texture)
theta = 360 / (rotation + .0) if rotation else 0
object = type(object_id, (x, y, z), (pitch, yaw, roll), rotation_angle=theta,
atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background, **params)
atmosphere=atmosphere_id, cloudmap=cloudmap_id, background=background,
corona=corona_id, **params)
world.tracker.append(object)
if 'ring' in info: