From 195f171fc47f76e581191ce95efa2473ab037a5b Mon Sep 17 00:00:00 2001 From: Brian Caine Date: Thu, 29 Nov 2007 23:12:08 -0500 Subject: [PATCH] Finally, some OpenGL work. Well, I created a camera class. Theoretically, the position list it has should change the view. I need to add some entity code to test it. --- game_client.py | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- pack_out/run.xml | 32 +------------ 2 files changed, 136 insertions(+), 36 deletions(-) diff --git a/game_client.py b/game_client.py index b0894d0..7830ffc 100644 --- a/game_client.py +++ b/game_client.py @@ -63,6 +63,9 @@ from OpenGL.GL import * import OpenGL.GLU from OpenGL.GLU import * +import Dice3DS +from Dice3DS import dom3ds, util + import StringIO import copy @@ -271,6 +274,8 @@ class Engine: # more stuff + self.camera = Camera((0, 0, 0), (0, 0, 0)) + if not self.config.has_key('window_title') or self.config.has_key('window_title') == None: self.config['window_title'] = WINDOW_CAPTION print "Engine.__init__(): No window title specified, using default of", WINDOW_CAPTION @@ -340,7 +345,7 @@ class Engine: else: return - for file in self.files.keys(): + for file in self.files: for name in self.files[file]['object_instances'].keys(): self.files[file]['object_instances'][name].event(new_event[0], new_event[1]) @@ -351,8 +356,12 @@ class Engine: glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) glLoadIdentity() + self.camera.align() + # draw stuff + d() # debug + glLoadIdentity() if self.change: self.lamina_screen.clear() @@ -549,7 +558,7 @@ class Engine: 'object_defs': {}, 'children': [], 'parent': '', - 'object_instances': {}, + 'object_instances': [], 'menu_instances': {}, 'menu_defs': {}} @@ -641,7 +650,16 @@ class Engine: object_instances_d.append(sub_node.childNodes[0].nodeValue) if sub_node.nodeName == 'menu': - menu_instances.append(sub_node.childNodes[0].nodeValue) + + position = '' + rotation = '' + + if sub_node.hasAttribute("position"): + position = eval(sub_node.getAttribute('position')) + if sub_node.hasAttribute("rotation"): + rotation = eval(sub_node.getAttribute('rotation')); + + menu_instances.append([sub_node.childNodes[0].nodeValue, position, rotation]) if not parent == '': self.files[parent]['children'].append(filename) @@ -652,11 +670,13 @@ class Engine: print "Engine.addFile(): Instance creation isn't done quite yet." - for menuname in menu_instances: + for menunamee in menu_instances: found_menu = 0 the_def = [] + menuname = menunamee[0] + if self.files[filename]['menu_defs'].has_key(menuname): print "\tInstantiate menu:", menuname the_def = self.files[filename]['menu_defs'][menuname] @@ -681,8 +701,40 @@ class Engine: self.files[filename]['menu_instances'][menuname] = Menu(menuname, the_def['elements'], self) self.files[filename]['menu_instances'][menuname].show() - for objectname in object_instances_d: - print "\tInstantiate object:", objectname + for objectnamee in object_instances_d: + + found_object = 0 + + the_def = [] + + objectname = objectnamee[0] + + if self.files[filename]['object_defs'].has_key(objectname): + print "\tInstantiate object:", objectname + the_def = self.files[filename]['object_defs'][objectname] + found_object = 1 + + for file in self.files.keys(): + if file != filename: + if self.files[file]['object_defs'].has_key(objectname): + print "\tInstantiate object:", objectname + the_def = self.files[file]['object_defs'][objectname] + found_object = 1 + + if found_object: + + if objectnamee[1] != '': + position = objectnamee[1] + else: + position = (0, 0, 0) + + if objectnamee[2] != '': + rotation = objectnamee[2] + else: + rotation = (0, 0, 0) + + new_object = Entity(the_def, rotation, rotation) + self.files[filename]['object_instances'].append(new_object) return 1 @@ -703,6 +755,47 @@ class Engine: return +class Camera: + + def __init__(self, (x, y, z), (xrot, yrot, zrot)): + + self.pos = (x, y, z) + self.rot = (xrot, yrot, zrot) + + def align(self): + + glLoadIdentity() + + glRotate(self.rot[0], 1.0, 0.0, 0.0) + glRotate(self.rot[1], 0.0, 1.0, 0.0) + glRotate(self.rot[2], 0.0, 0.0, 1.0) + + glTranslatef(self.pos[0], self.pos[1], self.pos[2]); + +class Entity: + + def __init__(self, info, (x, y, z)=(0, 0, 0), (xrot, yrot, zrot)=(0, 0, 0)): + + self.info = info + self.pos = (x, y, z) + self.rot = (xrot, yrot, zrot) + self.events = {} + + # insert running the script here + + def event(self, event, details): + + try: + self.events[event](details) + except: + print "Entity.event(): Error running Entity script" + + def setEvent(self, event, function): + + self.events[event] = function + + return + class Menu: def __init__(self, name, elements, engine): @@ -1060,5 +1153,40 @@ class Client(DatagramProtocol): self.requested_server = self.servers[data['server']] return +# debug + +def d(): + glBegin(GL_TRIANGLES) + + glColor3f(1.0,0.0,0.0) + glVertex3f( 0.0, 1.0, 0.0) + glColor3f(0.0,1.0,0.0) + glVertex3f(-1.0,-1.0, 1.0) + glColor3f(0.0,0.0,1.0) + glVertex3f( 1.0,-1.0, 1.0) + + glColor3f(1.0,0.0,0.0) + glVertex3f( 0.0, 1.0, 0.0) + glColor3f(0.0,0.0,1.0) + glVertex3f( 1.0,-1.0, 1.0) + glColor3f(0.0,1.0,0.0) + glVertex3f( 1.0,-1.0, -1.0) + + glColor3f(1.0,0.0,0.0) + glVertex3f( 0.0, 1.0, 0.0) + glColor3f(0.0,1.0,0.0) + glVertex3f( 1.0,-1.0, -1.0) + glColor3f(0.0,0.0,1.0) + glVertex3f(-1.0,-1.0, -1.0) + + + glColor3f(1.0,0.0,0.0) + glVertex3f( 0.0, 1.0, 0.0) + glColor3f(0.0,0.0,1.0) + glVertex3f(-1.0,-1.0,-1.0) + glColor3f(0.0,1.0,0.0) + glVertex3f(-1.0,-1.0, 1.0) + glEnd() + if __name__ == '__main__': main() diff --git a/pack_out/run.xml b/pack_out/run.xml index 9cbb65e..2c594e8 100644 --- a/pack_out/run.xml +++ b/pack_out/run.xml @@ -9,26 +9,6 @@ - - camera - - - 0 - camera - - - - - credits @@ -183,14 +163,6 @@ - initial_script - - - 0 - empty - - - person @@ -553,13 +525,13 @@ - net_script + net_script main_menu -- 2.11.4.GIT