def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded: continue # Skip (comment out) initialized check, which safely causes empty # model during progressive load. This can cause exceptions/garbage # render, but seems fine for now # May need to lock init() and draw_objects() together # if not obj.model.initialized: # continue glPushMatrix() glTranslatef(*(obj.offsets)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glTranslatef(*(obj.centeroffset)) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded \ or not obj.model.initialized: continue glPushMatrix() glTranslatef(*(obj.offsets)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glTranslatef(*(obj.centeroffset)) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) light_z = max(self.parent.platform.width, self.parent.platform.depth) glLightfv(GL_LIGHT0, GL_POSITION, vec(0, self.parent.platform.depth / 2, light_z, 0)) glLightfv(GL_LIGHT1, GL_POSITION, vec(self.parent.platform.width, self.parent.platform.depth / 2, light_z, 0)) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded \ or not obj.model.initialized: continue glPushMatrix() glTranslatef(*(obj.offsets)) glTranslatef(*(obj.centeroffset)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() if self.orthographic: glTranslatef(0, 0, -3 * self.dist) # Move back else: glTranslatef(0, 0, -self.dist) # Move back # Rotate according to trackball glMultMatrixd(build_rotmatrix(self.basequat)) # Move origin to bottom left of platform platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2 platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2 glTranslatef(platformx0, platformy0, 0) for obj in self.parent.objects: if not obj.model \ or not obj.model.loaded \ or not obj.model.initialized: continue glPushMatrix() glTranslatef(*(obj.offsets)) glTranslatef(*(obj.centeroffset)) glRotatef(obj.rot, 0.0, 0.0, 1.0) glScalef(*obj.scale) obj.model.display() glPopMatrix() glPopMatrix()
def gl_mult(self): """ Multiplies the active OpenGL by this one. """ ctype_matrix = (gl.GLdouble * 16)(*[float(value) for value in nditer(self.matrix)]) gl.glMultMatrixd(ctype_matrix)
def get_modelview_mat(self, local_transform): mvmat = (GLdouble * 16)() if local_transform: glPushMatrix() # Rotate according to trackball glTranslatef(0, 0, -self.dist) glMultMatrixd(build_rotmatrix(self.basequat)) # Rotate according to trackball glTranslatef(- self.build_dimensions[3] - self.platform.width / 2, - self.build_dimensions[4] - self.platform.depth / 2, 0) # Move origin to bottom left of platform glGetDoublev(GL_MODELVIEW_MATRIX, mvmat) glPopMatrix() else: glGetDoublev(GL_MODELVIEW_MATRIX, mvmat) return mvmat
def draw_objects(self): '''called in the middle of ondraw after the buffer has been cleared''' self.create_objects() glPushMatrix() glTranslatef(0, 0, -self.dist) glMultMatrixd(build_rotmatrix(self.basequat)) # Rotate according to trackball glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.2, 0.2, 0.2, 1)) glTranslatef(- self.build_dimensions[3] - self.platform.width / 2, - self.build_dimensions[4] - self.platform.depth / 2, 0) # Move origin to bottom left of platform # Draw platform glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glDisable(GL_LIGHTING) self.platform.draw() glEnable(GL_LIGHTING) # Draw mouse glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) inter = self.mouse_to_plane(self.mousepos[0], self.mousepos[1], plane_normal = (0, 0, 1), plane_offset = 0, local_transform = False) if inter is not None: glPushMatrix() glTranslatef(inter[0], inter[1], inter[2]) glBegin(GL_TRIANGLES) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(1, 0, 0, 1)) glNormal3f(0, 0, 1) glVertex3f(2, 2, 0) glVertex3f(-2, 2, 0) glVertex3f(-2, -2, 0) glVertex3f(2, -2, 0) glVertex3f(2, 2, 0) glVertex3f(-2, -2, 0) glEnd() glPopMatrix() # Draw objects glDisable(GL_CULL_FACE) glPushMatrix() glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.3, 0.7, 0.5, 1)) for i in self.parent.models: model = self.parent.models[i] glPushMatrix() glTranslatef(*(model.offsets)) glRotatef(model.rot, 0.0, 0.0, 1.0) glTranslatef(*(model.centeroffset)) glScalef(*model.scale) model.batch.draw() glPopMatrix() glPopMatrix() glEnable(GL_CULL_FACE) # Draw cutting plane if self.parent.cutting: # FIXME: make this a proper Actor axis = self.parent.cutting_axis fixed_dist = self.parent.cutting_dist dist, plane_width, plane_height = self.get_cutting_plane(axis, fixed_dist) if dist is not None: glPushMatrix() if axis == "x": glRotatef(90, 0, 1, 0) glRotatef(90, 0, 0, 1) glTranslatef(0, 0, dist) elif axis == "y": glRotatef(90, 1, 0, 0) glTranslatef(0, 0, -dist) elif axis == "z": glTranslatef(0, 0, dist) glDisable(GL_CULL_FACE) glBegin(GL_TRIANGLES) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0, 0.9, 0.15, 0.3)) glNormal3f(0, 0, self.parent.cutting_direction) glVertex3f(plane_width, plane_height, 0) glVertex3f(0, plane_height, 0) glVertex3f(0, 0, 0) glVertex3f(plane_width, 0, 0) glVertex3f(plane_width, plane_height, 0) glVertex3f(0, 0, 0) glEnd() glEnable(GL_CULL_FACE) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glEnable(GL_LINE_SMOOTH) orig_linewidth = (GLfloat)() glGetFloatv(GL_LINE_WIDTH, orig_linewidth) glLineWidth(4.0) glBegin(GL_LINE_LOOP) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0, 0.8, 0.15, 1)) glVertex3f(0, 0, 0) glVertex3f(0, plane_height, 0) glVertex3f(plane_width, plane_height, 0) glVertex3f(plane_width, 0, 0) glEnd() glLineWidth(orig_linewidth) glDisable(GL_LINE_SMOOTH) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) glPopMatrix() glPopMatrix()