mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Get rid of glMatrix since we handle all matrices manually
This commit is contained in:
parent
0607ab4d4c
commit
517a7584ca
|
@ -5,7 +5,7 @@ from pyglet.gl import *
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
from punyverse.glgeom import compile, glMatrix, glRestore, belt, Sphere, Disk, OrbitVBO, Matrix4f
|
from punyverse.glgeom import compile, glRestore, belt, Sphere, Disk, OrbitVBO, Matrix4f
|
||||||
from punyverse.model import load_model, WavefrontVBO
|
from punyverse.model import load_model, WavefrontVBO
|
||||||
from punyverse.orbit import KeplerOrbit
|
from punyverse.orbit import KeplerOrbit
|
||||||
from punyverse.texture import get_best_texture, load_clouds
|
from punyverse.texture import get_best_texture, load_clouds
|
||||||
|
@ -53,9 +53,8 @@ class Asteroid(Entity):
|
||||||
self.rotation = rx + 1, ry + 1, rz + 1
|
self.rotation = rx + 1, ry + 1, rz + 1
|
||||||
|
|
||||||
def draw(self, options):
|
def draw(self, options):
|
||||||
with glMatrix():
|
glLoadMatrixf(self.mv_matrix.as_gl())
|
||||||
glLoadMatrixf(self.mv_matrix.as_gl())
|
self.model.draw()
|
||||||
self.model.draw()
|
|
||||||
|
|
||||||
|
|
||||||
class AsteroidManager(object):
|
class AsteroidManager(object):
|
||||||
|
@ -105,9 +104,8 @@ class Belt(Entity):
|
||||||
self.rotation = pitch, self.world.tick * self.rotation_angle % 360, roll
|
self.rotation = pitch, self.world.tick * self.rotation_angle % 360, roll
|
||||||
|
|
||||||
def draw(self, options):
|
def draw(self, options):
|
||||||
with glMatrix(), glRestore(GL_CURRENT_BIT):
|
glLoadMatrixf(self.mv_matrix.as_gl())
|
||||||
glLoadMatrixf(self.mv_matrix.as_gl())
|
glCallList(self.belt_id)
|
||||||
glCallList(self.belt_id)
|
|
||||||
|
|
||||||
|
|
||||||
class Sky(Entity):
|
class Sky(Entity):
|
||||||
|
@ -126,7 +124,7 @@ class Sky(Entity):
|
||||||
|
|
||||||
def draw(self, options):
|
def draw(self, options):
|
||||||
cam = self.world.cam
|
cam = self.world.cam
|
||||||
with glMatrix(), glRestore(GL_TEXTURE_BIT | GL_ENABLE_BIT):
|
with glRestore(GL_TEXTURE_BIT | GL_ENABLE_BIT):
|
||||||
matrix = self.world.view_matrix() * Matrix4f.from_angles((-cam.x, -cam.y, -cam.z), self.rotation)
|
matrix = self.world.view_matrix() * Matrix4f.from_angles((-cam.x, -cam.y, -cam.z), self.rotation)
|
||||||
glLoadMatrixf(matrix.as_gl())
|
glLoadMatrixf(matrix.as_gl())
|
||||||
glEnable(GL_CULL_FACE)
|
glEnable(GL_CULL_FACE)
|
||||||
|
@ -225,7 +223,7 @@ class Body(Entity):
|
||||||
return self.orbit_vbo
|
return self.orbit_vbo
|
||||||
|
|
||||||
def _draw_orbits(self, distance):
|
def _draw_orbits(self, distance):
|
||||||
with glMatrix(), glRestore(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT):
|
with glRestore(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT):
|
||||||
glLoadMatrixf(self.parent.orbit_matrix.as_gl())
|
glLoadMatrixf(self.parent.orbit_matrix.as_gl())
|
||||||
|
|
||||||
glDisable(GL_LIGHTING)
|
glDisable(GL_LIGHTING)
|
||||||
|
@ -299,7 +297,7 @@ class SphericalBody(Body):
|
||||||
self.ring = Disk(distance, distance + size, 30)
|
self.ring = Disk(distance, distance + size, 30)
|
||||||
|
|
||||||
def _draw_sphere(self, fv4=GLfloat * 4):
|
def _draw_sphere(self, fv4=GLfloat * 4):
|
||||||
with glMatrix(), glRestore(GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT):
|
with glRestore(GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT):
|
||||||
glLoadMatrixf(self.mv_matrix.as_gl())
|
glLoadMatrixf(self.mv_matrix.as_gl())
|
||||||
glEnable(GL_CULL_FACE)
|
glEnable(GL_CULL_FACE)
|
||||||
glCullFace(GL_BACK)
|
glCullFace(GL_BACK)
|
||||||
|
@ -318,7 +316,7 @@ class SphericalBody(Body):
|
||||||
self.sphere.draw()
|
self.sphere.draw()
|
||||||
|
|
||||||
def _draw_atmosphere(self):
|
def _draw_atmosphere(self):
|
||||||
with glMatrix(), glRestore(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT):
|
with glRestore(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT):
|
||||||
mv = self.mv_matrix.matrix
|
mv = self.mv_matrix.matrix
|
||||||
matrix = Matrix4f([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, mv[12], mv[13], mv[14], 1])
|
matrix = Matrix4f([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, mv[12], mv[13], mv[14], 1])
|
||||||
glLoadMatrixf(matrix.as_gl())
|
glLoadMatrixf(matrix.as_gl())
|
||||||
|
@ -332,7 +330,7 @@ class SphericalBody(Body):
|
||||||
self.atmosphere.draw()
|
self.atmosphere.draw()
|
||||||
|
|
||||||
def _draw_clouds(self):
|
def _draw_clouds(self):
|
||||||
with glMatrix(), glRestore(GL_ENABLE_BIT | GL_TEXTURE_BIT):
|
with glRestore(GL_ENABLE_BIT | GL_TEXTURE_BIT):
|
||||||
glLoadMatrixf(self.mv_matrix.as_gl())
|
glLoadMatrixf(self.mv_matrix.as_gl())
|
||||||
glEnable(GL_BLEND)
|
glEnable(GL_BLEND)
|
||||||
glEnable(GL_ALPHA_TEST)
|
glEnable(GL_ALPHA_TEST)
|
||||||
|
@ -345,7 +343,7 @@ class SphericalBody(Body):
|
||||||
self.clouds.draw()
|
self.clouds.draw()
|
||||||
|
|
||||||
def _draw_rings(self):
|
def _draw_rings(self):
|
||||||
with glMatrix(), glRestore(GL_ENABLE_BIT | GL_TEXTURE_BIT):
|
with glRestore(GL_ENABLE_BIT | GL_TEXTURE_BIT):
|
||||||
glLoadMatrixf(self.mv_matrix.as_gl())
|
glLoadMatrixf(self.mv_matrix.as_gl())
|
||||||
glDisable(GL_LIGHTING)
|
glDisable(GL_LIGHTING)
|
||||||
glEnable(GL_TEXTURE_2D)
|
glEnable(GL_TEXTURE_2D)
|
||||||
|
@ -383,6 +381,5 @@ class ModelBody(Body):
|
||||||
info.get('sz', scale))
|
info.get('sz', scale))
|
||||||
|
|
||||||
def _draw(self, options):
|
def _draw(self, options):
|
||||||
with glMatrix():
|
glLoadMatrixf(self.mv_matrix.as_gl())
|
||||||
glLoadMatrixf(self.mv_matrix.as_gl())
|
self.vbo.draw()
|
||||||
self.vbo.draw()
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from six.moves import range
|
||||||
TWOPI = pi * 2
|
TWOPI = pi * 2
|
||||||
|
|
||||||
__all__ = ['compile', 'ortho', 'frustrum', 'crosshair', 'circle', 'Sphere', 'belt',
|
__all__ = ['compile', 'ortho', 'frustrum', 'crosshair', 'circle', 'Sphere', 'belt',
|
||||||
'glSection', 'glMatrix', 'glRestore', 'progress_bar']
|
'glSection', 'glRestore', 'progress_bar']
|
||||||
|
|
||||||
|
|
||||||
class glContext(object):
|
class glContext(object):
|
||||||
|
@ -58,27 +58,6 @@ class glRestoreClient(object):
|
||||||
glPopClientAttrib()
|
glPopClientAttrib()
|
||||||
|
|
||||||
|
|
||||||
class glMatrix(object):
|
|
||||||
def __init__(self, location=None, rotation=None):
|
|
||||||
self.location = location
|
|
||||||
self.rotation = rotation
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
glPushMatrix()
|
|
||||||
|
|
||||||
if self.location:
|
|
||||||
glTranslatef(*self.location)
|
|
||||||
|
|
||||||
if self.rotation:
|
|
||||||
pitch, yaw, roll = self.rotation
|
|
||||||
glRotatef(pitch, 1, 0, 0)
|
|
||||||
glRotatef(yaw, 0, 1, 0)
|
|
||||||
glRotatef(roll, 0, 0, 1)
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
||||||
glPopMatrix()
|
|
||||||
|
|
||||||
|
|
||||||
def array_to_ctypes(arr):
|
def array_to_ctypes(arr):
|
||||||
return cast(arr.buffer_info()[0], POINTER({
|
return cast(arr.buffer_info()[0], POINTER({
|
||||||
'f': c_float,
|
'f': c_float,
|
||||||
|
@ -295,13 +274,14 @@ def belt(radius, cross, object, count):
|
||||||
r = gauss(radius, cross)
|
r = gauss(radius, cross)
|
||||||
x, y, z = cos(theta) * r, gauss(0, cross), sin(theta) * r
|
x, y, z = cos(theta) * r, gauss(0, cross), sin(theta) * r
|
||||||
|
|
||||||
with glMatrix():
|
glPushMatrix()
|
||||||
glTranslatef(x, y, z)
|
glTranslatef(x, y, z)
|
||||||
scale = gauss(1, 0.5)
|
scale = gauss(1, 0.5)
|
||||||
if scale < 0:
|
if scale < 0:
|
||||||
scale = 1
|
scale = 1
|
||||||
glScalef(scale, scale, scale)
|
glScalef(scale, scale, scale)
|
||||||
choice(object).draw()
|
choice(object).draw()
|
||||||
|
glPopMatrix()
|
||||||
|
|
||||||
|
|
||||||
def progress_bar(x, y, width, height, filled):
|
def progress_bar(x, y, width, height, filled):
|
||||||
|
|
Loading…
Reference in a new issue