This commit is contained in:
Thomas FORGIONE 2016-12-01 10:55:41 +01:00
parent b6130ca640
commit befe9c19fe
No known key found for this signature in database
GPG Key ID: 2A210FFC062E00C3
4 changed files with 52 additions and 31 deletions

View File

@ -58,11 +58,21 @@ class OrbitControls(Controls):
super().__init__()
self.phi = 0
self.theta = 0
self.scale = 1
def apply(self):
gl.glScalef(self.scale, self.scale, self.scale)
gl.glRotatef(self.theta * 180 / math.pi, 1.0, 0.0, 0.0)
gl.glRotatef(self.phi * 180 / math.pi, 0.0, 1.0, 0.0)
def apply_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
# Wheel up
if event.button == 4:
self.scale += 0.2
elif event.button == 5:
self.scale -= 2
def update(self, time = 10):
if not pygame.mouse.get_pressed()[0]:

View File

@ -74,7 +74,6 @@ class ModelParser:
"""Initializes the model
"""
self.up_conversion = up_conversion
print(up_conversion)
self.vertices = []
self.normals = []
self.tex_coords = []

View File

@ -48,7 +48,9 @@ class Material:
gl.glBindTexture(gl.GL_TEXTURE_2D, self.id)
def unbind(self):
pass
from OpenGL import GL as gl
gl.glDisable(gl.GL_TEXTURE_2D)
import PIL.Image
@ -150,33 +152,11 @@ class MeshPart:
gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(self.vertex_vbo.data) * 9)
gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
gl.glDisableClientState(gl.GL_NORMAL_ARRAY)
gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
def draw_from_arrays(self):
pass
class Mesh:
def __init__(self):
self.vertices = []
self.tex_coords = []
self.normals = []
self.parts = []
self.current_material = None
self.current_part = None
def draw(self):
for part in self.parts:
part.draw()
def add_face(self, face):
if self.current_part is None or face.material != self.current_part.material:
self.current_part = MeshPart(self)
self.current_part.material = face.material
self.parts.append(self.current_part)
self.current_part.add_face(face)
def generate_vbos(self):
for part in self.parts:
part.generate_vbos()

View File

@ -18,7 +18,18 @@ from d3.camera import Camera
from d3.shader import DefaultShader
WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 768
WINDOW_HEIGHT = 1024
def resize(width, height):
print((width, height))
length = min(width, height)
offset = int( math.fabs(width - height) / 2)
if width < height:
gl.glViewport(0, offset, length, length)
else:
gl.glViewport(offset, 0, length, length)
def main(args):
@ -35,10 +46,13 @@ def main(args):
pg.init()
display = (WINDOW_WIDTH, WINDOW_HEIGHT)
pg.display.set_mode(display, pgl.DOUBLEBUF | pgl.OPENGL)
pg.display.set_mode(display, pgl.DOUBLEBUF | pgl.OPENGL | pgl.RESIZABLE)
pg.display.set_caption('Model-Converter')
# OpenGL init
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
glu.gluPerspective(45, (WINDOW_WIDTH / WINDOW_HEIGHT), 0.1, 50.0)
@ -68,6 +82,9 @@ def main(args):
while running:
for event in pg.event.get():
controls.apply_event(event)
if event.type == pg.QUIT:
pg.quit()
quit()
@ -78,6 +95,8 @@ def main(args):
elif event.type == pg.MOUSEBUTTONDOWN:
if event.button == 1:
pg.mouse.get_rel()
elif event.type == pg.VIDEORESIZE:
resize(event.size[0], event.size[1])
# Update physics
controls.update()
@ -90,6 +109,19 @@ def main(args):
gl.glPushMatrix()
controls.apply()
gl.glBegin(gl.GL_LINES)
gl.glColor3f (1.0,0.0,0.0)
gl.glVertex3f(0.0,0.0,0.0)
gl.glVertex3f(2.0,0.0,0.0)
gl.glColor3f (0.0,1.0,0.0)
gl.glVertex3f(0.0,0.0,0.0)
gl.glVertex3f(0.0,2.0,0.0)
gl.glColor3f (0.0,0.0,1.0)
gl.glVertex3f(0.0,0.0,0.0)
gl.glVertex3f(0.0,0.0,2.0)
gl.glEnd()
shader.bind()
model.draw()
shader.unbind()