def drawbrick(color, center, axis, l, h, w, opacity=1.0): if len(color) == 3: color = (color[0], color[1], color[2], opacity) if opacity != 1.0: glDepthMask(GL_FALSE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) apply_material(color) glPushMatrix() glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(h, w, l) #bruce 060302 revised the contents of solidCubeList while fixing bug 1595 glCallList(drawing_globals.solidCubeList) if opacity != 1.0: glDisable(GL_BLEND) glDepthMask(GL_TRUE) glPopMatrix() return
def drawbrick(color, center, axis, l, h, w, opacity = 1.0): if len(color) == 3: color = (color[0], color[1], color[2], opacity) if opacity != 1.0: glDepthMask(GL_FALSE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) apply_material(color) glPushMatrix() glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(h, w, l) #bruce 060302 revised the contents of solidCubeList while fixing bug 1595 glCallList(drawing_globals.solidCubeList) if opacity != 1.0: glDisable(GL_BLEND) glDepthMask(GL_TRUE) glPopMatrix() return
def paint(self): glPushMatrix() position = self.player.getPosition() glTranslate(position.x, position.y, position.z) glRotate(self.player.orientation.y, 0.0, 1.0, 0.0) # Slide back because the pyramid below is centered at 0.5, 0, 0.5 # instead of at the origin. Without this it rotates around its corner # instead of around its center. glTranslate(-0.5, 0, -0.5) glColor(1.0, 1.0, 1.0) glBegin(GL_TRIANGLES) glVertex3f(0.5, 0.0, 0.5) glVertex3f(0.0, 1.0, 0.0) glVertex3f(1.0, 1.0, 0.0) glVertex3f(0.5, 0.0, 0.5) glVertex3f(1.0, 1.0, 0.0) glVertex3f(1.0, 1.0, 1.0) glVertex3f(0.5, 0.0, 0.5) glVertex3f(1.0, 1.0, 1.0) glVertex3f(0.0, 1.0, 1.0) glVertex3f(0.5, 0.0, 0.5) glVertex3f(0.0, 1.0, 1.0) glVertex3f(0.0, 1.0, 0.0) glEnd() glPopMatrix()
def rotate_before_swap(self): x_center, y_center = self.previous[0] x_diff, y_diff = 0, 0 if self.move_direction == 'up': y_diff = -2 elif self.move_direction == 'down': y_center += 2 y_diff = 2 elif self.move_direction == 'left': x_diff = -2 elif self.move_direction == 'right': x_center += 2 x_diff = 2 if self.steps == 1: glTranslate(x_center, -y_center, 0) glRotate(90, y_diff, x_diff, 0) glTranslate(-x_center, y_center, 0) return False if self.degree + rotating_speed >= 90: self.degree = 90 else: self.degree += rotating_speed glTranslate(x_center, -y_center, 0) glRotate(self.degree, y_diff, x_diff, 0) glTranslate(-x_center, y_center, 0) if self.degree == 90: return True return False
def draw(self): glColor3f(1.0, 1.0, 1.0) # glDisable(GL_LIGHTING) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if self.type == "inicio": glBindTexture(GL_TEXTURE_2D, self.logo_inicio) elif self.type == "fim": glBindTexture(GL_TEXTURE_2D, self.logo_fim) glPushMatrix() glRotate(90, 1, 0, 0) glBegin(GL_QUADS) glTexCoord2f(0, 1) glVertex3f(self.start_position_x - 35, self.start_position_y - 25, -70) glTexCoord2f(1, 1) glVertex3f(self.start_position_x + 35, self.start_position_y - 25, -70) glTexCoord2f(1, 0) glVertex3f(self.start_position_x + 35, self.start_position_y + 25, -70) glTexCoord2f(0, 0) glVertex3f(self.start_position_x - 35, self.start_position_y + 25, -70) glEnd() glPopMatrix() glDisable(GL_TEXTURE_2D)
def render(self): glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotate(self.pitch, 1, 0, 0) glRotate(self.yaw, 0, 1, 0) x, y, z = self.position glTranslate(-x, -y, -z)
def draw(self): glColor3f(1.0, 1.0, 1.0) # glDisable(GL_LIGHTING) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glBindTexture(GL_TEXTURE_2D, self.planets[self.skin]) glPushMatrix() glRotate(self.angle, 0, 1, 0) for i in range(0, self.lats + 1): lat0 = pi * (-0.5 + float(float(i - 1) / float(self.lats))) z0 = sin(lat0) zr0 = cos(lat0) lat1 = pi * (-0.5 + float(float(i) / float(self.lats))) z1 = sin(lat1) zr1 = cos(lat1) # Use Quad strips to draw the sphere glBegin(GL_QUAD_STRIP) for j in range(0, self.longs + 1): lng = 2 * pi * float(float(j - 1) / float(self.longs)) x = cos(lng) y = sin(lng) glTexCoord2f(0, 1) glNormal3f( self.start_position_x + (15 * self.my_scale) + x * (zr0 * 15), self.move_y + self.start_position_y + (20 * self.my_scale) + y * (zr0 * 15), z0 * -15) glTexCoord2f(1, 1) glVertex3f( self.start_position_x + (15 * self.my_scale) + x * (zr0 * 15), self.move_y + self.start_position_y + (20 * self.my_scale) + y * (zr0 * 15), z0 * -15) glTexCoord2f(1, 0) glNormal3f( self.start_position_x + (15 * self.my_scale) + x * (zr1 * 15), self.move_y + self.start_position_y + (20 * self.my_scale) + y * (zr1 * 15), z1 * -15) glTexCoord2f(0, 0) glVertex3f( self.start_position_x + (15 * self.my_scale) + x * (zr1 * 15), self.move_y + self.start_position_y + (20 * self.my_scale) + y * (zr1 * 15), z1 * -15) glEnd() glPopMatrix() glDisable(GL_TEXTURE_2D)
def rotate_player(self): current = self.player [x_diff, y_diff] = current[0] - self.previous[0] x_center = self.previous[0, 0] + x_diff if x_diff > 0 else self.previous[0, 0] y_center = self.previous[0, 1] + y_diff if y_diff > 0 else self.previous[0, 1] if self.degree + rotating_speed >= 90: self.degree = 90 if self.check_merge(self.player): self.player[[0, 1], :] = self.player[[1, 0], :] else: self.degree += rotating_speed if (current - self.previous).tolist() != [[0, 0], [0, 0]]: glTranslate(x_center, -y_center, 0) glRotate(self.degree, y_diff, x_diff, 0) glTranslate(-x_center, y_center, 0) if self.degree == 90: return True return False
def drawRotateSign(color, pos1, pos2, radius, rotation = 0.0): """Rotate sign on top of the caps of the cylinder """ glPushMatrix() glColor3fv(color) vec = pos2-pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518 glScale(radius,radius,Numeric.dot(vec,vec)**.5) glLineWidth(2.0) glDisable(GL_LIGHTING) glCallList(drawing_globals.rotSignList) glEnable(GL_LIGHTING) glLineWidth(1.0) glPopMatrix() return
def drawRotateSign(color, pos1, pos2, radius, rotation=0.0): """Rotate sign on top of the caps of the cylinder """ glPushMatrix() glColor3fv(color) vec = pos2 - pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518 glScale(radius, radius, Numeric.dot(vec, vec)**.5) glLineWidth(2.0) glDisable(GL_LIGHTING) glCallList(drawing_globals.rotSignList) glEnable(GL_LIGHTING) glLineWidth(1.0) glPopMatrix() return
def drawcylinder_worker(params): """ Draw a cylinder. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) @warning: our circular cross-section is approximated by a 13-gon whose alignment around the axis is chosen arbitrary, in a way which depends on the direction of the axis; negating the axis usually causes a different alignment of that 13-gon. This effect can cause visual bugs when drawing one cylinder over an identical or slightly smaller one (e.g. when highlighting a bond), unless the axes are kept parallel as opposed to antiparallel. """ if not _DRAW_BONDS: return (pos1, pos2, radius, capped) = params glPushMatrix() vec = pos2 - pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(radius, radius, Numeric.dot(vec, vec)**.5) glCallList(drawing_globals.CylList) if capped: glCallList(drawing_globals.CapList) glPopMatrix() return
def drawcylinder_worker(params): """ Draw a cylinder. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) @warning: our circular cross-section is approximated by a 13-gon whose alignment around the axis is chosen arbitrary, in a way which depends on the direction of the axis; negating the axis usually causes a different alignment of that 13-gon. This effect can cause visual bugs when drawing one cylinder over an identical or slightly smaller one (e.g. when highlighting a bond), unless the axes are kept parallel as opposed to antiparallel. """ if not _DRAW_BONDS: return (pos1, pos2, radius, capped) = params glPushMatrix() vec = pos2-pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(radius,radius,Numeric.dot(vec,vec)**.5) glCallList(drawing_globals.CylList) if capped: glCallList(drawing_globals.CapList) glPopMatrix() return
def drawCube(self): glPushMatrix() glLoadIdentity() glTranslate(0.0, 0.0, -50.0) glScale(20.0, 20.0, 20.0) glRotate(self.yRotDeg, 0.2, 1.0, 0.3) glTranslate(-0.5, -0.5, -0.5) glColor3f(1, 1, 1) glBegin(GL_LINES) glVertex3f(0., 0., 0.) glVertex3f(1., 0., 0.) glVertex3f(1., 0., 0.) glVertex3f(1., 1., 0.) glVertex3f(1., 1., 0.) glVertex3f(0., 1., 0.) glVertex3f(0., 1., 0.) glVertex3f(0., 0., 0.) glVertex3f(0., 0., 1.) glVertex3f(1., 0., 1.) glVertex3f(1., 0., 1.) glVertex3f(1., 1., 1.) glVertex3f(1., 1., 1.) glVertex3f(0., 1., 1.) glVertex3f(0., 1., 1.) glVertex3f(0., 0., 1.) glVertex3f(0., 0., 0.) glVertex3f(0., 0., 1.) glVertex3f(1., 0., 0.) glVertex3f(1., 0., 1.) glVertex3f(1., 1., 0.) glVertex3f(1., 1., 1.) glVertex3f(0., 1., 0.) glVertex3f(0., 1., 1.) glEnd() glPopMatrix()
def paint(self): v = self.player.getPosition() o = self.player.orientation glRotate(o.x, 1.0, 0.0, 0.0) glRotate(o.y, 0.0, 1.0, 0.0) glRotate(o.z, 0.0, 0.0, 1.0) # XXX Put the camera somewhere in the middle-ish of the player model. # This is a wild guess for now, camera position data should be available # from the model at some later point. glTranslate(-v.x - 0.5, -v.y - 2, -v.z - 0.5)
def on_draw(self): glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslate(self.translatex, self.translatey, self.depth) if self.autoRun: glRotate(self.rotx, 0, 1, 0) else: # Perform arcball rotation. glScale(1,-1,1) glMultMatrixf(self.arcball.transform) glScale(1,-1,1) with displayListify("cubeTranslate") as shouldLeave: if shouldLeave: raise LeaveWith # Scale the co-ordinates so that they are correct glScale(2/128, 2/128, 2/128) glColor(0.25, 0.25, 0.25, 1) glutWireCube(255) glTranslate(-128, -128, -128) with displayListify("allPoints") as shouldLeave: if shouldLeave: raise LeaveWith with SaveMatrix(): # Flip the co-ordinates and translate upwards glScale(1,-1,1) glColor(0.25, 0.25, 0.25, 0.5) glTranslate(0,-255,0) glPointSize(pointSize) for dat in reversed(vLists): glTranslate(0., 0., 1./nChunks*255) dat.draw(GL_POINTS) with displayListify("axisLabels") as shouldLeave: if shouldLeave: raise LeaveWith #if True: with SaveMatrix(): glTranslate(128,0,0) self.makeLabel("End").draw() glTranslate(0,0,255) self.makeLabel("Beginning").draw() with SaveMatrix(): glTranslate(-128,128,0) glRotate(90,0,0,1) self.makeLabel("Byte 1").draw() glTranslate(0,255,0) self.makeLabel("Byte 2").draw() with displayListify("fileName") as shouldLeave: if shouldLeave: raise LeaveWith glLoadIdentity() with SaveMatrix(): glColor(1,0,0) glTranslate(0,-2.2,-4) glScale(1/64, 1/64, 1/64) l = self.makeLabel(basename(currentInputFile)) l.color = (0, 128, 230, 255) l.draw() glTranslate(0,0,-1) if self.autoRun: if self.rotx > 360 - 45: vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1))) glColor(0,0,0,(self.rotx-(360-45))/45) vlist.draw(GL_QUADS) if self.rotx < 45: vlist = vertex_list(4, ('v2i', (-1, -1, 1, -1, 1, 1, -1, 1))) glColor(0,0,0,1-(self.rotx/45)) vlist.draw(GL_QUADS)
def draw(self): # self.propellant.draw() # glColor3f(1.0, 1.0, 1.0) # glDisable(GL_LIGHTING) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) if self.nave_type == 0: glBindTexture(GL_TEXTURE_2D, self.skin_azul) elif self.nave_type == 1: glBindTexture(GL_TEXTURE_2D, self.skin_amarela) elif self.nave_type == 2: glBindTexture(GL_TEXTURE_2D, self.skin_preta) glPushMatrix() # glBegin(GL_QUADS) # glTexCoord2f(0, 1) # glVertex3f(self.move_x + self.position_x -4.0, # self.move_y, 0) # glTexCoord2f(1, 1) # glVertex3f(self.move_x + self.position_x +4.0, # self.move_y, 0) # glTexCoord2f(1, 0) # # glVertex3f(self.move_x + self.position_x + 4.0, # self.move_y + 12, 0) # glTexCoord2f(0, 0) # glVertex3f(self.move_x + self.position_x - 4.0, # self.move_y + 12, 0) # glEnd() if self.moving_right: glRotate(10, 0.1, 0.7, 0.2) elif self.moving_left: glRotate(-10, 0.1, 0.7, 0.2) #Vermelho, baixo glBegin(GL_TRIANGLES) # glColor3f(1.0, 0.0, 0.0) glTexCoord2f(0, 1) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x + 5.0, self.move_y + 12, -2.0) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x + 0.0, self.move_y, 0.0) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x - 5.0, self.move_y + 12, -2.0) glEnd() # VERDE esq glBegin(GL_TRIANGLES) # glColor3f(0.0, 1.0, 0.0) glTexCoord2f(0, 1) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x - 5.0, self.move_y + 12, -2.0) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x + 0.0, self.move_y, 0.0) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x + 0.0, self.move_y + 12, 2.0) glEnd() #############3 Azul escuro dir glBegin(GL_TRIANGLES) # glColor3f(0.5, 0.5, 1.0) glTexCoord2f(0, 1) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x + 5.0, self.move_y + 12, -2.0) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x + 0.0, self.move_y, 0.0) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x + 0.0, self.move_y + 12, 2.0) glEnd() #####################Roxo FRENTE glBegin(GL_TRIANGLES) # glColor3f(0.0, 0.0, 1.0) glTexCoord2f(0, 1) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x + 0.0, self.move_y + 12, 2.0) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x + 5.0, self.move_y + 12, -2.0) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x - 5.0, self.move_y + 12, -2.0) glEnd() glPopMatrix() glDisable(GL_TEXTURE_2D)
def render(self, visibility, topMost): #MFH - display version in any menu: if not visibility: self.active = False return self.active = True if self.graphicMenu and self.menuBackground: self.engine.graphicMenuShown = True else: self.engine.graphicMenuShown = False self.engine.view.setOrthogonalProjection(normalize = True) try: v = (1 - visibility) ** 2 # Default to this font if none was specified font = self.font tipFont = self.tipFont if self.fadeScreen: Dialogs.fadeScreen(v) wS, hS = self.engine.view.geometry[2:4] if self.graphicMenu and self.menuBackground: #volshebnyi - better menu scaling self.engine.drawImage(self.menuBackground, scale = (1.0,-1.0), coord = (wS/2,hS/2), stretched = 3) else: glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_COLOR_MATERIAL) n = len(self.choices) x, y = self.pos for i, choice in enumerate(self.choices[self.viewOffset:self.viewOffset + self.viewSize]): if self.graphicMenu: if self.currentIndex == i: xpos = (.5,1) else: xpos = (0,.5) ypos = float(i+self.viewOffset) self.menuText.transform.reset() self.menuText.transform.scale(.5*self.menuScale,(-1.0/n*self.menuScale)) self.menuText.transform.translate(wS*self.menux,(hS*self.menuy)-(hS*self.vSpace)*i) self.menuText.draw(rect = (xpos[0],xpos[1],ypos/n,(ypos+1.0)/n)) #self.engine.drawImage(self.menuText, scale = (self.menuScale,-self.menuScale*2/n), coord = (wS*self.menux,hS*(self.menuy-self.vSpace*i)), rect = (xpos[0],xpos[1],ypos/n,(ypos+1.0)/n), stretched = 11) else: text = choice.getText(i + self.viewOffset == self.currentIndex) glPushMatrix() glRotate(v * 45, 0, 0, 1) scale = 0.002 if self.mainMenu and self.theme < 2 and i % 2 == 1:#8bit scale = 0.0016 w, h = font.getStringSize(" ", scale = scale) # Draw arrows if scrolling is needed to see all items if i == 0 and self.viewOffset > 0: self.engine.theme.setBaseColor((1 - v) * max(.1, 1 - (1.0 / self.viewOffset) / 3)) glPushMatrix() glTranslatef(x - v / 4 - w * 2, y + h / 2, 0) self.renderTriangle(up = (0, -1), s = .015) glPopMatrix() elif i == self.viewSize - 1 and self.viewOffset + self.viewSize < n: self.engine.theme.setBaseColor((1 - v) * max(.1, 1 - (1.0 / (n - self.viewOffset - self.viewSize)) / 3)) glPushMatrix() glTranslatef(x - v / 4 - w * 2, y + h / 2, 0) self.renderTriangle(up = (0, 1), s = .015) glPopMatrix() if i + self.viewOffset == self.currentIndex: if choice.tipText and self.showTips: if self.tipColor: c1, c2, c3 = self.tipColor glColor3f(c1,c2,c3) elif self.textColor: c1, c2, c3 = self.textColor glColor3f(c1,c2,c3) else: self.engine.theme.setBaseColor(1-v) tipScale = self.tipScale if self.tipScroll > -(self.tipSize) and self.tipScroll < 1: tipFont.render(choice.tipText, (self.tipScroll, self.tipY), scale = tipScale) if self.tipScrollMode == 0: if self.tipScrollB > -(self.tipSize) and self.tipScrollB < 1: tipFont.render(choice.tipText, (self.tipScrollB, self.tipY), scale = tipScale) a = (math.sin(self.time) * .15 + .75) * (1 - v * 2) self.engine.theme.setSelectedColor(a) a *= -.005 glTranslatef(a, a, a) else: self.engine.theme.setBaseColor(1 - v) #MFH - settable color through Menu constructor if i + self.viewOffset == self.currentIndex and self.selectedColor: c1,c2,c3 = self.selectedColor glColor3f(c1,c2,c3) elif self.textColor: c1,c2,c3 = self.textColor glColor3f(c1,c2,c3) #MFH - now to catch " >" main menu options and blank them: if text == " >": text = "" if self.engine.data.submenuSelectFound and len(text) > 0 and not self.mainMenu and self.useSelectedBox: Tw, Th = font.getStringSize(text,scale) lineSpacing = font.getLineSpacing(scale) frameWidth = Tw*1.10 #frameHeight = (Th+Th2)*1.10 frameHeight = Th + lineSpacing boxXOffset = (x + (Tw/2))*wS boxYOffset = (1.0 - (y*4.0/3.0) - (Th*1.2/2))*hS subSelectHYFactor = 640.000/self.engine.view.aspectRatio subSelectHFactor = subSelectHYFactor/self.engine.data.subSelectImgH self.engine.data.submenuSelect.transform.reset() tempWScale = frameWidth*self.engine.data.subSelectWFactor tempHScale = -(frameHeight)*subSelectHFactor self.engine.data.submenuSelect.transform.scale(tempWScale,tempHScale) self.engine.data.submenuSelect.transform.translate(boxXOffset,boxYOffset) self.engine.data.submenuSelect.draw() font.render(text, (x - v / 4, y), scale = scale) v *= 2 if self.theme == 1 and self.font == self.engine.data.pauseFont: # evilynux - Ugly workaround for Gh3 y += h*.70 #Worldrave - Changed Pause menu spacing back to .70 from .65 for now. else: y += h glPopMatrix() finally: self.engine.view.resetProjection()
def rotate(self, angle, x, y, z): glRotate(angle, x, y, z)
def drawLinearSign(color, center, axis, l, h, w): """Linear motion sign on the side of squa-linder """ depthOffset = 0.005 glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glPushMatrix() glTranslate(h / 2.0 + depthOffset, 0.0, 0.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: sl = l / 2.7 glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glPushMatrix() glTranslate(-h / 2.0 - depthOffset, 0.0, 0.0) glRotate(180.0, 0.0, 0.0, 1.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glPushMatrix() glTranslate(0.0, w / 2.0 + depthOffset, 0.0) glRotate(90.0, 0.0, 0.0, 1.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glPushMatrix() glTranslate(0.0, -w / 2.0 - depthOffset, 0.0) glRotate(-90.0, 0.0, 0.0, 1.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glEnable(GL_LIGHTING) glPopMatrix() return
def main(): pygame.init() dimensions = (800, 600) display = pygame.display.set_mode(dimensions, DOUBLEBUF | OPENGL) pygame.display.set_caption("Rubik's Cube Simulator") gluPerspective(45, (dimensions[0] / dimensions[1]), 0.1, 50.0) glTranslate(0, 0, -40) glRotate(45, 0, 1, 0) glRotate(30, 1, 0, 1) glEnable(GL_DEPTH_TEST) cube = Cube() cube.render() scramble_button = pygame.Rect(300, 300, 50, 50) while True: pygame.draw.rect(display, (0, 0, 255), scramble_button) # pygame.display.flip() cube.render() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() elif event.type == pygame.MOUSEBUTTONDOWN: # mouse_pos == event.pos if scramble_button.collidepoint(event.pos): print("hi") keys = pygame.key.get_pressed() if keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT]: if keys[pygame.K_f]: cube.rotate(Face.front, Radians.CW) elif keys[pygame.K_b]: cube.rotate(Face.back, Radians.CCW) elif keys[pygame.K_l]: cube.rotate(Face.left, Radians.CW) elif keys[pygame.K_r]: cube.rotate(Face.right, Radians.CCW) elif keys[pygame.K_u]: cube.rotate(Face.up, Radians.CW) elif keys[pygame.K_d]: cube.rotate(Face.down, Radians.CCW) else: if keys[pygame.K_f]: cube.rotate(Face.front, Radians.CCW) elif keys[pygame.K_b]: cube.rotate(Face.back, Radians.CW) elif keys[pygame.K_l]: cube.rotate(Face.left, Radians.CCW) elif keys[pygame.K_r]: cube.rotate(Face.right, Radians.CW) elif keys[pygame.K_u]: cube.rotate(Face.up, Radians.CCW) elif keys[pygame.K_d]: cube.rotate(Face.down, Radians.CW) elif keys[pygame.K_LEFT]: cube.full_rotate("y", Radians.CW) elif keys[pygame.K_RIGHT]: cube.full_rotate("y", Radians.CCW) elif keys[pygame.K_UP]: cube.full_rotate("x", Radians.CCW) elif keys[pygame.K_DOWN]: cube.full_rotate("x", Radians.CW) elif keys[pygame.K_x]: cube.full_rotate("z", Radians.CCW) elif keys[pygame.K_z]: cube.full_rotate("z", Radians.CW) elif keys[pygame.K_s]: cube.scramble()
def draw(self): glColor3f(1.0, 1.0, 1.0) # glDisable(GL_LIGHTING) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glBindTexture(GL_TEXTURE_2D, self.imageID) glPushMatrix() glRotate(self.scene_angle , 0, 1, 0) glBegin(GL_TRIANGLE_FAN) glTexCoord2f(0, 1) glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 1, -3) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2) glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, -2) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, -2) glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, -2) glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, -2) glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, -2) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, -2) glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, -2) glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, -2) glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, -2) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, -2) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, -2) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2) glEnd() # glColor3f(1.0, 1.0, 0) glBegin(GL_QUAD_STRIP) glTexCoord2f(0, 1) glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2) glVertex3f(self.move_x + self.position_x +2.5, self.move_y + -3, 0) glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, -2) glVertex3f(self.move_x + self.position_x +3, self.move_y + 0, 0) glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, -2) glVertex3f(self.move_x + self.position_x +3, self.move_y + 2, 0) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, -2) glVertex3f(self.move_x + self.position_x +2, self.move_y + 4, 0) glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, -2) glVertex3f(self.move_x + self.position_x +-1, self.move_y + 5, 0) glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, -2) glVertex3f(self.move_x + self.position_x +-3, self.move_y + 4, 0) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, -2) glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 2, 0) glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, -2) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x +-4, self.move_y + 0, 0) glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, -2) glVertex3f(self.move_x + self.position_x +-3.5, self.move_y + -1.5, 0) glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, -2) glVertex3f(self.move_x + self.position_x +-2, self.move_y + -2, 0) glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, -2) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x +-1, self.move_y + -4, 0) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, -2) glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2) glEnd() # glColor3f(1.0, 0, 0) glBegin(GL_QUAD_STRIP) glTexCoord2f(0, 1) glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2) glVertex3f(self.move_x + self.position_x +2.5, self.move_y + -3, 0) glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, 2) glVertex3f(self.move_x + self.position_x +3, self.move_y + 0, 0) glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, 2) glVertex3f(self.move_x + self.position_x +3, self.move_y + 2, 0) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, 2) glVertex3f(self.move_x + self.position_x +2, self.move_y + 4, 0) glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, 2) glVertex3f(self.move_x + self.position_x +-1, self.move_y + 5, 0) glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, 2) glVertex3f(self.move_x + self.position_x +-3, self.move_y + 4, 0) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, 2) glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 2, 0) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, 2) glVertex3f(self.move_x + self.position_x +-4, self.move_y + 0, 0) glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, 2) glVertex3f(self.move_x + self.position_x +-3.5, self.move_y + -1.5, 0) glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, 2) glVertex3f(self.move_x + self.position_x +-2, self.move_y + -2, 0) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, 2) glVertex3f(self.move_x + self.position_x +-1, self.move_y + -4, 0) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, 2) glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2) glEnd() # glColor3f(0, 1.0, 0) glBegin(GL_TRIANGLE_FAN) glTexCoord2f(0, 1) glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 1, 3) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2) glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, 2) glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, 2) glTexCoord2f(1, 1) glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, 2) glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, 2) glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, 2) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, 2) glTexCoord2f(1, 0) glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, 2) glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, 2) glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, 2) glTexCoord2f(0, 0) glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, 2) glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, 2) glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2) glEnd() glPopMatrix() glDisable(GL_TEXTURE_2D)
def draw(self): glColor3f(1.0, 1.0, 1.0) # glDisable(GL_LIGHTING) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glPushMatrix() if self.moving_right: glRotate(5, 0, 1, 0.2) elif self.moving_left: glRotate(-5, 0, 1, 0.2) glBindTexture(GL_TEXTURE_2D, self.casco) #Base da nave glBegin(GL_TRIANGLE_FAN) glTexCoord2f(0, 1) glVertex3f(self.move_x + 0, self.move_y + 0, 1) glVertex3f(self.move_x + 0, self.move_y + 6, 1) glVertex3f(self.move_x + 1.5, self.move_y + 3, 1) glVertex3f(self.move_x + 2, self.move_y + 0, 1) glTexCoord2f(1, 1) glVertex3f(self.move_x + 5, self.move_y - 6, 1) glVertex3f(self.move_x + 2, self.move_y - 7, 1) glVertex3f(self.move_x + 1, self.move_y - 7, 1) glVertex3f(self.move_x + 0, self.move_y - 8, 1) glTexCoord2f(1, 0) glVertex3f(self.move_x - 1, self.move_y - 7, 1) glVertex3f(self.move_x - 2, self.move_y - 7, 1) glVertex3f(self.move_x - 5, self.move_y - 6, 1) glTexCoord2f(0, 0) glVertex3f(self.move_x - 2, self.move_y + 0, 1) glVertex3f(self.move_x - 1.5, self.move_y + 3, 1) glVertex3f(self.move_x + 0, self.move_y + 6, 1) glEnd() #Casco da nave (fora) glBegin(GL_QUAD_STRIP) glTexCoord2f(0, 1) glVertex3f(self.move_x + 0, self.move_y + 6, 1) glVertex3f(self.move_x + 0, self.move_y + 3, 2) glVertex3f(self.move_x + 1.5, self.move_y + 3, 1) glVertex3f(self.move_x + 0.5, self.move_y + 2, 2) glVertex3f(self.move_x + 2, self.move_y + 0, 1) glVertex3f(self.move_x + 1, self.move_y + 0, 2) glVertex3f(self.move_x + 5, self.move_y - 6, 1) glVertex3f(self.move_x + 2, self.move_y - 4, 2) glTexCoord2f(1, 1) glVertex3f(self.move_x + 2, self.move_y - 7, 1) glVertex3f(self.move_x + 1, self.move_y - 6, 2) glVertex3f(self.move_x + 1, self.move_y - 7, 1) glVertex3f(self.move_x + 0.5, self.move_y - 6, 2) glVertex3f(self.move_x + 0, self.move_y - 8, 1) glVertex3f(self.move_x + 0, self.move_y - 7, 2) glVertex3f(self.move_x - 1, self.move_y - 7, 1) glTexCoord2f(1, 0) glVertex3f(self.move_x - 0.5, self.move_y - 6, 2) glVertex3f(self.move_x - 2, self.move_y - 7, 1) glVertex3f(self.move_x - 1, self.move_y - 6, 2) glVertex3f(self.move_x - 5, self.move_y - 6, 1) glVertex3f(self.move_x - 2, self.move_y - 4, 2) glVertex3f(self.move_x - 2, self.move_y + 0, 1) glTexCoord2f(0, 0) glVertex3f(self.move_x - 1, self.move_y + 0, 2) glVertex3f(self.move_x - 1.5, self.move_y + 3, 1) glVertex3f(self.move_x - 0.5, self.move_y + 2, 2) glVertex3f(self.move_x + 0, self.move_y + 6, 1) glVertex3f(self.move_x + 0, self.move_y + 3, 2) glEnd() glDisable(GL_TEXTURE_2D) glColor3f(1.0, 1.0, 1.0) glDisable(GL_LIGHTING) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glBindTexture(GL_TEXTURE_2D, self.metal) #Parte verde glBegin(GL_QUAD_STRIP) glTexCoord2f(0, 1) glVertex3f(self.move_x + 0, self.move_y + 3, 2) glVertex3f(self.move_x + 0, self.move_y + 2, 2.5) glVertex3f(self.move_x + 0.5, self.move_y + 2, 2) glVertex3f(self.move_x + 0.5, self.move_y + 1, 2.5) glVertex3f(self.move_x + 1, self.move_y + 0, 2) glVertex3f(self.move_x + 0.5, self.move_y + 0, 2.5) glVertex3f(self.move_x + 2, self.move_y - 4, 2) glTexCoord2f(1, 1) glVertex3f(self.move_x + 1, self.move_y - 4, 2.5) glVertex3f(self.move_x + 1, self.move_y - 6, 2) glVertex3f(self.move_x + 1, self.move_y - 5, 2.5) glVertex3f(self.move_x + 0.5, self.move_y - 6, 2) glVertex3f(self.move_x + 0.5, self.move_y - 5, 2.5) glVertex3f(self.move_x + 0, self.move_y - 7, 2) glVertex3f(self.move_x + 0, self.move_y - 5, 2.5) glVertex3f(self.move_x - 0.5, self.move_y - 6, 2) glTexCoord2f(1, 0) glVertex3f(self.move_x - 0.5, self.move_y - 5, 2.5) glVertex3f(self.move_x - 1, self.move_y - 6, 2) glVertex3f(self.move_x - 1, self.move_y - 5, 2.5) glVertex3f(self.move_x - 2, self.move_y - 4, 2) glVertex3f(self.move_x - 1, self.move_y - 4, 2.5) glVertex3f(self.move_x - 1, self.move_y + 0, 2) glTexCoord2f(0, 0) glVertex3f(self.move_x - 0.5, self.move_y + 0, 2.5) glVertex3f(self.move_x - 0.5, self.move_y + 2, 2) glVertex3f(self.move_x - 0.5, self.move_y + 1, 2.5) glVertex3f(self.move_x + 0, self.move_y + 3, 2) glVertex3f(self.move_x + 0, self.move_y + 2, 2.5) glEnd() glDisable(GL_TEXTURE_2D) glColor3f(1.0, 1.0, 1.0) glDisable(GL_LIGHTING) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glBindTexture(GL_TEXTURE_2D, self.vidro) # #Vidro da nave glBegin(GL_TRIANGLE_FAN) glTexCoord2f(0, 1) glVertex3f(self.move_x + 0, self.move_y - 3, 4) glVertex3f(self.move_x + 0, self.move_y + 2, 2.5) glVertex3f(self.move_x + 0.5, self.move_y + 1, 2.5) glVertex3f(self.move_x + 0.5, self.move_y + 0, 2.5) glTexCoord2f(1, 1) glVertex3f(self.move_x + 1, self.move_y - 4, 2.5) glVertex3f(self.move_x + 1, self.move_y - 5, 2.5) glVertex3f(self.move_x + 0.5, self.move_y - 5, 2.5) glVertex3f(self.move_x + 0, self.move_y - 5, 2.5) glTexCoord2f(1, 0) glVertex3f(self.move_x - 0.5, self.move_y - 5, 2.5) glVertex3f(self.move_x - 1, self.move_y - 5, 2.5) glVertex3f(self.move_x - 1, self.move_y - 4, 2.5) glTexCoord2f(0, 0) glVertex3f(self.move_x - 0.5, self.move_y + 0, 2.5) glVertex3f(self.move_x - 0.5, self.move_y + 1, 2.5) glVertex3f(self.move_x + 0, self.move_y + 2, 2.5) glEnd() glPopMatrix() glDisable(GL_TEXTURE_2D)
def drawLinearSign(color, center, axis, l, h, w): """Linear motion sign on the side of squa-linder """ depthOffset = 0.005 glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glPushMatrix() glTranslate(h/2.0 + depthOffset, 0.0, 0.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: sl = l/2.7 glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glPushMatrix() glTranslate(-h/2.0 - depthOffset, 0.0, 0.0) glRotate(180.0, 0.0, 0.0, 1.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glPushMatrix() glTranslate(0.0, w/2.0 + depthOffset, 0.0) glRotate(90.0, 0.0, 0.0, 1.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glPushMatrix() glTranslate(0.0, -w/2.0 - depthOffset, 0.0 ) glRotate(-90.0, 0.0, 0.0, 1.0) glPushMatrix() glScale(1.0, 1.0, l) glCallList(drawing_globals.linearLineList) glPopMatrix() if l < 2.6: glScale(1.0, sl, sl) if w < 1.0: glScale(1.0, w, w) drawLinearArrows(l) glPopMatrix() glEnable(GL_LIGHTING) glPopMatrix() return
def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) h = self.size().height() w = self.size().width() glEnable(GL_DEPTH_TEST) glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w)/float(h), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # Reset The View glEnable(MeshWidget.GL_MULTISAMPLE) glTranslatef(0,0.0,self.zoom) glRotate(self.rotation[0], 0.0, 1.0, 0.0) glRotate(self.rotation[1], 1.0, 0.0, 0.0) center = -self.mesh.bounding_box.center glTranslatef(center.x,center.y,center.z) if self.draw_mesh: if self.enable_restrict: for i in self.restricted: glBegin(GL_TRIANGLES) self.mesh.drawFaceIdx(i) glEnd() else: self.mesh.draw(1.0) if self.draw_bounding_box: self.mesh.bounding_box.draw() if self.draw_octree: self.mesh.quad.draw() #single vertex marker #glPushMatrix( ) #s = self.mesh.vertices.verts[self.point_draw] #glTranslatef(s.x,s.y,s.z) #q = gluNewQuadric() #gluSphere( q, GLdouble(0.65), GLint(10), GLint(10) ) #glPopMatrix( ) #self.mesh.drawAdjacentFaces( self.count ) #self.count += 1 #if self.count == len(self.mesh.faces): #self.count = 0 #time.sleep(0.3) #self.mesh.smooth(0.45) w /= 5 h /= 5 glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w)/float(h), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glDisable(GL_DEPTH_TEST) glLoadIdentity() # Reset The View glTranslatef(0,0.0,-self.mesh.bounding_box.minViewDistance()) glRotate(self.rotation[0], 0.0, 1.0, 0.0) glRotate(self.rotation[1], 1.0, 0.0, 0.0) center = -self.mesh.bounding_box.center glTranslatef(center.x,center.y,center.z) if self.draw_mesh: self.mesh.draw(0.5)
def paint(self): glRotate(self.orientation.x, 1.0, 0.0, 0.0) glRotate(self.orientation.y, 0.0, 1.0, 0.0) glRotate(self.orientation.z, 0.0, 0.0, 1.0) glTranslate(-self.position.x, -self.position.y, -self.position.z)
def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) h = self.size().height() w = self.size().width() glEnable(GL_DEPTH_TEST) glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w) / float(h), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # Reset The View glEnable(MeshWidget.GL_MULTISAMPLE) glTranslatef(0, 0.0, self.zoom) glRotate(self.rotation[0], 0.0, 1.0, 0.0) glRotate(self.rotation[1], 1.0, 0.0, 0.0) center = -self.mesh.bounding_box.center glTranslatef(center.x, center.y, center.z) if self.draw_mesh: if self.enable_restrict: for i in self.restricted: glBegin(GL_TRIANGLES) self.mesh.drawFaceIdx(i) glEnd() else: self.mesh.draw(1.0) if self.draw_bounding_box: self.mesh.bounding_box.draw() if self.draw_octree: self.mesh.quad.draw() #single vertex marker #glPushMatrix( ) #s = self.mesh.vertices.verts[self.point_draw] #glTranslatef(s.x,s.y,s.z) #q = gluNewQuadric() #gluSphere( q, GLdouble(0.65), GLint(10), GLint(10) ) #glPopMatrix( ) #self.mesh.drawAdjacentFaces( self.count ) #self.count += 1 #if self.count == len(self.mesh.faces): #self.count = 0 #time.sleep(0.3) #self.mesh.smooth(0.45) w /= 5 h /= 5 glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(w) / float(h), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glDisable(GL_DEPTH_TEST) glLoadIdentity() # Reset The View glTranslatef(0, 0.0, -self.mesh.bounding_box.minViewDistance()) glRotate(self.rotation[0], 0.0, 1.0, 0.0) glRotate(self.rotation[1], 1.0, 0.0, 0.0) center = -self.mesh.bounding_box.center glTranslatef(center.x, center.y, center.z) if self.draw_mesh: self.mesh.draw(0.5)