def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(0., 0., -4. / min(self.aspect, 0.7)) glRotatef(self.yRotDeg, 0., 1., 0.) glRotatef(self.xRotDeg, 1., 0., 0.) if self.shape == 'cuboid': self.paintCuboid(self.sample_width, self.sample_thickness, self.sample_height, rotate=45.) elif self.shape == 'cylinder': self.paintCylinder(self.sample_diameter, self.sample_height) elif self.shape == 'sphere': self.paintSphere(self.sample_diameter) else: self.sample_width = self.sample_thickness = 70 self.sample_height = 100 self.paintCuboid(self.sample_width, self.sample_thickness, self.sample_height) self.paintArrow('x', [0, 0, 1]) self.paintArrow('y', [1, 0, 0]) self.paintArrow('z', [0, 1, 0]) self.paintArrow('n', [0, 0, 0]) self.paintArrow('gamma', [1, 0, 1]) self.paintCells()
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a linear motor as a long box along the axis, with a thin cylinder (spoke) to each atom. """ glPushMatrix() try: glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) drawbrick(color, orig_center, self.axis, self.length, self.width, self.width, opacity = self.opacity) drawLinearSign((0,0,0), orig_center, self.axis, self.length, self.width, self.width) # (note: drawLinearSign uses a small depth offset so that arrows are slightly in front of brick) # [bruce comment 060302, a guess from skimming drawLinearSign's code] for a in self.atoms[:]: drawcylinder(color, orig_center, a.posn()-self.center, self.sradius, opacity = self.opacity) except: #bruce 060208 protect OpenGL stack from exception analogous to that seen for RotaryMotor in bug 1445 print_compact_traceback("exception in LinearMotor._draw, continuing: ") glPopMatrix()
def _display_vector_head(self, head_angle: float): """Displays the robot's head to the current OpenGL context :param head_angle: the angle of the lift in radians """ glPushMatrix() # Rotate the head around the pivot glTranslatef(HEAD_PIVOT_X, 0.0, HEAD_PIVOT_Z) glRotatef(-head_angle, 0, 1, 0) glTranslatef(-HEAD_PIVOT_X, 0.0, -HEAD_PIVOT_Z) # Render all of the head meshes self.display_by_key("head_geo") # Screen self.display_by_key("backScreen_mat") self.display_by_key("screenEdge_geo") self.display_by_key("overscan_1_geo") # Eyes self.display_by_key("eye_L_geo") self.display_by_key("eye_R_geo") # Eyelids self.display_by_key("eyeLid_R_top_geo") self.display_by_key("eyeLid_L_top_geo") self.display_by_key("eyeLid_L_btm_geo") self.display_by_key("eyeLid_R_btm_geo") # Face cover (drawn last as it's translucent): self.display_by_key("front_Screen_geo") glPopMatrix()
def paintGL(self): glLoadIdentity() gluPerspective(45, self.width / self.height, 0.1, 110.0) #set perspective? glTranslatef( 0, 0, self.zoomLevel) #I used -10 instead of -2 in the PyGame version. glRotatef(self.rotateDegreeV, 1, 0, 0) #I used 2 instead of 1 in the PyGame version. glRotatef(self.rotateDegreeH, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if len(self.shapes) != 0: glBegin(GL_LINES) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawWires: for e in s.edges: for v in e: glVertex3fv(s.vertices[v]) glEnd() glBegin(GL_QUADS) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawFaces: for f in s.facets: for v in f: glVertex3fv(s.vertices[v]) glEnd()
def drawTexture(self, texture, dx, dy, dw, dh, x, y, w, h, r): ''' texture is an int textureRect is a list of size 4, determines which square to take from the texture drawRect is a list of size 4, is used to determine the drawing size ''' glBindTexture(self.texext, texture) glPushMatrix() glTranslatef(dx + dw / 2, dy + dh / 2, 0) glRotatef(r, 0, 0, 1.0) glTranslatef(-1 * (dx + dw / 2), -1 * (dy + dh / 2), 0) glBegin(GL_QUADS) #Top-left vertex (corner) glTexCoord2f(x, y + h) #image/texture glVertex3f(dx, dy, 0) #screen coordinates #Bottom-left vertex (corner) glTexCoord2f(x + w, y + h) glVertex3f((dx + dw), dy, 0) #Bottom-right vertex (corner) glTexCoord2f(x + w, y) glVertex3f((dx + dw), (dy + dh), 0) #Top-right vertex (corner) glTexCoord2f(x, y) glVertex3f(dx, (dy + dh), 0) glEnd() glPopMatrix()
def _draw_jig(self, glpane, color, highlighted = False): """ Draw a Grid Plane jig as a set of grid lines. """ glPushMatrix() glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/math.pi, q.x, q.y, q.z) hw = self.width/2.0; hh = self.height/2.0 corners_pos = [V(-hw, hh, 0.0), V(-hw, -hh, 0.0), V(hw, -hh, 0.0), V(hw, hh, 0.0)] if highlighted: grid_color = color else: grid_color = self.grid_color if self.picked: drawLineLoop(self.color, corners_pos) else: drawLineLoop(color, corners_pos) if self.grid_type == SQUARE_GRID: drawGPGrid(glpane, grid_color, self.line_type, self.width, self.height, self.x_spacing, self.y_spacing, q.unrot(self.assy.o.up), q.unrot(self.assy.o.right)) else: drawSiCGrid(grid_color, self.line_type, self.width, self.height, q.unrot(self.assy.o.up), q.unrot(self.assy.o.right)) glPopMatrix()
def draw_in_abs_coords(self, glpane, color): """ Draw the handle as a highlighted object. @param glpane: The 3D Graphics area. @type gplane: L{GLPane} @param color: Unused. @type color: @attention: I{color} is not used. """ q = self.parent.quat glPushMatrix() if self.parent.center: glTranslatef( self.parent.center[0], self.parent.center[1], self.parent.center[2]) if q: glRotatef( q.angle * ONE_RADIAN, q.x, q.y, q.z) self._draw(highlighted = True) glPopMatrix()
def mouseMove(event): global lastPosX, lastPosY, zoomScale, xRot, yRot, zRot if event.type == pygame.MOUSEBUTTONDOWN and event.button == 4: glScaled(1.05, 1.05, 1.05) elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 5: glScaled(0.95, 0.95, 0.95) if event.type == pygame.MOUSEMOTION: x, y = event.pos dx = x - lastPosX dy = y - lastPosY mouseState = pygame.mouse.get_pressed() if mouseState[0]: modelView = (GLfloat * 16)() mvm = glGetFloatv(GL_MODELVIEW_MATRIX, modelView) temp = (GLfloat * 3)() temp[0] = modelView[0] * dy + modelView[1] * dx temp[1] = modelView[4] * dy + modelView[5] * dx temp[2] = modelView[8] * dy + modelView[9] * dx norm_xy = math.sqrt(temp[0] * temp[0] + temp[1] * temp[1] + temp[2] * temp[2]) glRotatef(math.sqrt(dx * dx + dy * dy), temp[0] / norm_xy, temp[1] / norm_xy, temp[2] / norm_xy) lastPosX = x lastPosY = y
def drawFilledCircle(color, center, radius, normal): """ Scale, rotate/translate the unit circle properly. Added a filled circle variant, piotr 080405 """ glMatrixMode(GL_MODELVIEW) glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) rQ = Q(V(0, 0, 1), normal) rotAngle = rQ.angle*180.0/pi #This may cause problems as proved before in Linear motor display. #rotation around (0, 0, 0) #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005: # rQ.x = 1.0 glRotatef(rotAngle, rQ.x, rQ.y, rQ.z) glScalef(radius, radius, 1.0) glCallList(drawing_globals.filledCircleList) glEnable(GL_LIGHTING) glPopMatrix() return
def on_draw(self): """Redraw window.""" self.set_3d() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # rotate camera glRotatef(self.camera.v_angle_deg(), 1.0, 0, 0) glRotatef(self.camera.h_angle_deg(), 0.0, 1.0, 0) glTranslatef( -self.camera.x_pos, -self.camera.y_pos, self.camera.z_pos) if self.rendering_type == "fill": self.use_shader("test") elif self.rendering_type == "lines": self.use_shader("lines") self.renderer.render() # draw HUD self.set_2d() self.draw_hud()
def main(): pygame.init() display = (800, 600) # pygame.display.set_mode(display, pygame.DOUBLEBUFFER) screen = pygame.display.set_mode(display) gluPerspective(45, display[0] / display[1], 0.001, 1000.0) glTranslatef(0.0, 0.0, -5.0) glRotatef(0, 0, 0, 0) print('before loop') done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) Cube() pygame.display.flip() pygame.time.wait(10) print('after loop')
def paintGL(self): #This function uses shape objects, such as cube() or meshSector(). Shape objects require the following: #a list named 'vertices' - This list is a list of points, from which edges and faces are drawn. #a list named 'wires' - This list is a list of tuples which refer to vertices, dictating where to draw wires. #a list named 'facets' - This list is a list of tuples which refer to vertices, ditating where to draw facets. #a bool named 'render' - This bool is used to dictate whether or not to draw the shape. #a bool named 'drawWires' - This bool is used to dictate whether wires should be drawn. #a bool named 'drawFaces' - This bool is used to dictate whether facets should be drawn. glLoadIdentity() gluPerspective(45, self.width / self.height, 0.1, 110.0) #set perspective? glTranslatef(0, 0, self.zoomLevel) #I used -10 instead of -2 in the PyGame version. glRotatef(self.rotateDegreeV, 1, 0, 0) #I used 2 instead of 1 in the PyGame version. glRotatef(self.rotateDegreeH, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) if len(self.shapes) != 0: glBegin(GL_LINES) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawWires: for w in s.wires: for v in w: glVertex3fv(s.vertices[v]) glEnd() glBegin(GL_QUADS) for s in self.shapes: glColor3fv(s.color) if s.render and s.drawFaces: for f in s.facets: for v in f: glVertex3fv(s.vertices[v]) glEnd()
def drawFilledCircle(color, center, radius, normal): """ Scale, rotate/translate the unit circle properly. Added a filled circle variant, piotr 080405 """ glMatrixMode(GL_MODELVIEW) glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) rQ = Q(V(0, 0, 1), normal) rotAngle = rQ.angle * 180.0 / pi #This may cause problems as proved before in Linear motor display. #rotation around (0, 0, 0) #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005: # rQ.x = 1.0 glRotatef(rotAngle, rQ.x, rQ.y, rQ.z) glScalef(radius, radius, 1.0) glCallList(drawing_globals.filledCircleList) glEnable(GL_LIGHTING) glPopMatrix() return
def draw(self, x, y, z=0, angle=0, scale=1): """Draws the SVG to screen. :Parameters `x` : float The x-coordinate at which to draw. `y` : float The y-coordinate at which to draw. `z` : float The z-coordinate at which to draw. Defaults to 0. Note that z-ordering may not give expected results when transparency is used. `angle` : float The angle by which the image should be rotated (in degrees). Defaults to 0. `scale` : float The amount by which the image should be scaled, either as a float, or a tuple of two floats (xscale, yscale). """ glPushMatrix() glTranslatef(x, y, z) if angle: glRotatef(angle, 0, 0, 1) if scale != 1: try: glScalef(scale[0], scale[1], 1) except TypeError: glScalef(scale, scale, 1) if self._a_x or self._a_y: glTranslatef(-self._a_x, -self._a_y, 0) glCallList(self.disp_list) glPopMatrix()
def rotate(): if len(node.rotate) != 4: for r in node.rotate: glRotatef(*r) else: glRotatef(*node.rotate)
def paintGL(self): if self.crashFlag: #run cleanup operations glUseProgram(0) glDisableVertexAttribArray(self.attrID) glDeleteBuffers(1,[self.vertexBuffer]) glDeleteVertexArrays(1, [self.vertexArrayID]) glLoadIdentity() gluPerspective(45, self.sizeX / self.sizeY, 0.1, 110.0) #set perspective glTranslatef(0, 0, self.zoomLevel) glRotatef(self.rotateDegreeV + self.vOffset, 1, 0, 0) glRotatef(self.rotateDegreeH, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) self.vertexData = [ -1, 1, 0, 0, -1, 0, 1, 1, 0 ] arrayType = GLfloat * len(self.vertexData) target = GL_ARRAY_BUFFER offset = 0 size = len(self.vertexData) * ctypes.sizeof(ctypes.c_float) data = arrayType(*self.vertexData) glBufferSubData(target, offset, size, data) glDrawArrays(GL_TRIANGLES, 0, 3)
def rotate_camera(self, angle: float = 0, axis: int = 0): assert -1 < axis < 3, "Invalid axis!" xyz = [0, 0, 0] xyz[axis] = 1 x, y, z = xyz glRotatef(angle, x, y, z)
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a Rotary Motor jig as a cylinder along the axis, with a thin cylinder (spoke) to each atom. If <highlighted> is True, the Rotary Motor is draw slightly larger. """ ## print "RMotor _draw_jig",env.redraw_counter # This confirms that Jigs are drawn more times than they ought to need to be, # possibly due to badly organized Jig hit-testing code -- 4 times on mouseenter that highlights them in Build mode # (even after I fixed a bug today in which it redrew the entire model twice each frame); # but it's hard to find something to compare it to for an objective test of whether being a Jig matters, # since atoms, bonds, and chunks all have special behavior of their own. BTW, the suspected bad Jig code might redraw # everything (not only Jigs) this often, even though all it cares about is seeing Jigs in glRenderMode output. # BTW2, on opening a file containing one jig, it was drawn something like 20 times. # [bruce 060724 comments] if highlighted: inc = 0.01 # tested. Fixes bug 1681. mark 060314. else: inc = 0.0 glPushMatrix() try: glTranslatef(self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef(q.angle * 180.0 / pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) bCenter = orig_center - (self.length / 2.0 + inc) * self.axis tCenter = orig_center + (self.length / 2.0 + inc) * self.axis drawcylinder(color, bCenter, tCenter, self.radius + inc, capped=1, opacity=self.opacity) for a in self.atoms: drawcylinder(color, orig_center, a.posn() - self.center, self.sradius + inc, opacity=self.opacity) rotby = self.getrotation() #bruce 050518 # if exception in getrotation, just don't draw the rotation sign # (safest now that people might believe what it shows about amount of rotation) drawRotateSign((0, 0, 0), bCenter, tCenter, self.radius, rotation=rotby) except: #bruce 060208 protect OpenGL stack from exception seen in bug 1445 print_compact_traceback( "exception in RotaryMotor._draw, continuing: ") print " some info that might be related to that exception: natoms = %d" % len( self.atoms) ###@@@ might not keep this glPopMatrix() return
def paintSphere(self, diameter): r = diameter / 70. glColor3f(0., 0., 0.) glPushMatrix() glTranslatef(0., r - 1., 0.) # move down glRotatef(90., 1., 0., 0.) slices = max(int(round(r * 32)), 9) glutWireSphere(r, slices, slices) glPopMatrix()
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a ESP Image jig as a plane with an edge and a bounding box. """ glPushMatrix() glTranslatef(self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef(q.angle * 180.0 / math.pi, q.x, q.y, q.z) #bruce 060207 extensively revised texture code re fixing bug 1059 if self.tex_name is not None and self.image_obj: # self.image_obj condition is needed, for clear_esp_image() to work textureReady = True glBindTexture( GL_TEXTURE_2D, self.tex_name ) # maybe this belongs in draw_plane instead? Put it there later. ##e self._initTextureEnv() # sets texture params the way we want them else: textureReady = False drawPlane(self.fill_color, self.width, self.width, textureReady, self.opacity, SOLID=True, pickCheckOnly=self.pickCheckOnly) hw = self.width / 2.0 corners_pos = [ V(-hw, hw, 0.0), V(-hw, -hw, 0.0), V(hw, -hw, 0.0), V(hw, hw, 0.0) ] drawLineLoop(color, corners_pos) # Draw the ESP Image bbox. if self.show_esp_bbox: wo = self.image_offset eo = self.edge_offset drawwirecube(color, V(0.0, 0.0, 0.0), V(hw + eo, hw + eo, wo), 1.0) #drawwirebox # This is for debugging purposes. This draws a green normal vector using # local space coords. Mark 050930 if 0: from graphics.drawing.CS_draw_primitives import drawline drawline(green, V(0.0, 0.0, 0.0), V(0.0, 0.0, 1.0), 0, 3) glPopMatrix() # This is for debugging purposes. This draws a yellow normal vector using # model space coords. Mark 050930 if 0: from graphics.drawing.CS_draw_primitives import drawline from utilities.constants import yellow drawline(yellow, self.center, self.center + self.planeNorm, 0, 3)
def _draw_jig(self, glpane, color, highlighted = False): """ Draw an ESPImage jig (self) as a plane with an edge and a bounding box. @note: this is not called during graphicsMode.Draw_model as with most Jigs, but during graphicsMode.Draw_after_highlighting. """ glPushMatrix() glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/math.pi, q.x, q.y, q.z) #bruce 060207 extensively revised texture code re fixing bug 1059 if self.tex_name is not None and self.image_obj: # self.image_obj cond is needed, for clear_esp_image() to work textureReady = True glBindTexture(GL_TEXTURE_2D, self.tex_name) # review: maybe this belongs in draw_plane instead? self._initTextureEnv() # sets texture params the way we want them else: textureReady = False drawPlane(self.fill_color, self.width, self.width, textureReady, self.opacity, SOLID = True, pickCheckOnly = self.pickCheckOnly ) hw = self.width/2.0 corners_pos = [V(-hw, hw, 0.0), V(-hw, -hw, 0.0), V( hw, -hw, 0.0), V( hw, hw, 0.0)] drawLineLoop(color, corners_pos) # Draw the ESP Image bbox. if self.show_esp_bbox: wo = self.image_offset eo = self.edge_offset drawwirecube(color, V(0.0, 0.0, 0.0), V(hw + eo, hw + eo, wo), 1.0) #drawwirebox # This is for debugging purposes. This draws a green normal vector # using local space coords. [Mark 050930] if 0: from graphics.drawing.CS_draw_primitives import drawline drawline(green, V(0.0, 0.0, 0.0), V(0.0, 0.0, 1.0), 0, 3) glpane.kluge_reset_texture_mode_to_work_around_renderText_bug() glPopMatrix() # This is for debugging purposes. This draws a yellow normal vector # using model space coords. [Mark 050930] if 0: from graphics.drawing.CS_draw_primitives import drawline from utilities.constants import yellow drawline(yellow, self.center, self.center + self.planeNorm, 0, 3)
def on_draw(self): with gx_matrix: glTranslatef(self.x, self.y, 0) glTranslatef(self.width / 2, 0, 0) if self.side == 'front': glRotatef(self.zangle, 0, 1, 0) else: glRotatef(self.zangle + 180, 0, 1, 0) glTranslatef(-self.width / 2, 0, 0) super(MTFlippableWidget, self).on_draw()
def iniciar_renderizado(self): """Acciones posteriores al renderizado de objetos.""" self.fbos[0].usar() #glClearColor(*self.capa.escena.color)#0.) para fondo transparente glClear(GL_COLOR_BUFFER_BIT) #| GL_DEPTH_BUFFER_BIT) # Transformación de la cámara glLoadIdentity() glScalef(self.acerc, self.acerc, 0.) glTranslatef(-self.pos.x, -self.pos.y, 0.) glRotatef(-self.angulo, 0., 0., 1.)
def applyTransform(self): """ Apply self's transform to the GL matrix stack. (Pushing/popping the stack, if needed, is the caller's responsibility.) @note: this is used for display list primitives in CSDLs, but not for shader primitives in CSDLs. """ (q, v) = self.getRotateTranslate() glTranslatef(v[0], v[1], v[2]) glRotatef(q.angle * 180.0 / math.pi, q.x, q.y, q.z) return
def paintCylinder(self, diameter, height): r = diameter / 70. height = 2 * height / 70. glColor3f(0., 0., 0.) glPushMatrix() glTranslatef(*self.offsets) # move down glRotatef(-90., 1., 0., 0.) quadric = gluNewQuadric() gluQuadricDrawStyle(quadric, GLU_LINE) slices = max(int(round(r * 32)), 15) gluCylinder(quadric, r, r, height, slices, 1) glPopMatrix()
def calc_rotation_matrix(self, x, y, z): ''' ''' glPushMatrix() glLoadIdentity() for r in [[x, 1, 0, 0], [y, 0, 1, 0], [z, 0, 0, 1]]: glRotatef(*r) m = glGetFloatv(GL_MODELVIEW_MATRIX) glPopMatrix() rot = [[y for j, y in enumerate(x) if j <= 2] for i, x in enumerate(m) if i <= 2] return m, rot
def draw_pin(self, x, y): glPushMatrix() glColor3f(1.0, 1.0, 0.0) glTranslatef(x, 0.0, -y) glRotatef(-90, 1.0, 0.0, 0.0) obj = gluNewQuadric() gluCylinder(obj, 0.05, 0.05, 0.5, 10, 10) glPushMatrix() gluDisk(obj, 0.0, 0.05, 10, 10) glTranslatef(0.0, 0.5, 0.0) glPopMatrix() glPopMatrix()
def display(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix() glTranslatef(0.0, 0.0, -1.0) glRotatef(self.rot_x, 1.0, 0.0, 0.0) glRotatef(self.rot_z, 0.0, 1.0, 0.0) self.render() glPopMatrix() glFlush() glutSwapBuffers()
def render(self): glTranslatef(self.position.x, self.position.y, 0.0) glRotatef(self.rotation, 0.0, 0.0, 1.0) glScalef(self.scale.x, self.scale.y, 0.0) for child in self._children: glPushMatrix() child.render() glPopMatrix() self.draw()
def opgl_move_to_pose(self, from_fixed_frame: bool = True): if from_fixed_frame: # Reset init view glLoadIdentity() # Translate to the right position glTranslatef(self.pose.position[0], self.pose.position[1], self.pose.position[2]) # Rotate to the right orientation glRotatef(self.pose.orientation.get_theta(rad=False), self.pose.orientation[1], self.pose.orientation[2], self.pose.orientation[3])
def draw_led(self, x, y, color): glPushMatrix() if color < 0: glColor3f(*self.color_led_red) else: glColor3f(*self.color_led_green) glTranslatef(x, 0.1, -y) glRotatef(-90, 1.0, 0.0, 0.0) obj = gluNewQuadric() gluSphere(obj, 0.15, 10, 10) glPopMatrix()
def _draw_orbitals(self): r = 1.5 glPushAttrib(GL_CURRENT_BIT) self._set_material((0, 0, 1)) for a in [60, -60, 0]: glPushMatrix() glRotatef(a, 1, 0, 0) glTranslatef(0, 0, -0.25 / 2) self._torus_(radius=r, inner_radius=0.15, xs=25, ys=25 ) glPopMatrix() glPopAttrib()
def init_window(terrain): """ Initialise the application window """ pygame.init() resolution = (WINDOW_WIDTH, WINDOW_HEIGHT) pygame.display.set_mode(resolution, DOUBLEBUF | OPENGL) pygame.display.set_caption("{0} - FPS: Unknown".format(NAME)) gluPerspective(FOV, (resolution[0] / resolution[1]), 0.1, 1000) glTranslatef(-(terrain.size / 2), -(terrain.height_3d / 2), -10) glRotatef(45, -90, 0, 0) glEnable(GL_DEPTH_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) color = hex_to_float(BACKGROUND_COLOR) glClearColor(color[0], color[1], color[2], 1)
def _draw_jig(self, glpane, color, highlighted=False): """ Draw a Rotary Motor jig as a cylinder along the axis, with a thin cylinder (spoke) to each atom. If <highlighted> is True, the Rotary Motor is draw slightly larger. """ ## print "RMotor _draw_jig",env.redraw_counter # This confirms that Jigs are drawn more times than they ought to need to be, # possibly due to badly organized Jig hit-testing code -- 4 times on mouseenter that highlights them in Build mode # (even after I fixed a bug today in which it redrew the entire model twice each frame); # but it's hard to find something to compare it to for an objective test of whether being a Jig matters, # since atoms, bonds, and chunks all have special behavior of their own. BTW, the suspected bad Jig code might redraw # everything (not only Jigs) this often, even though all it cares about is seeing Jigs in glRenderMode output. # BTW2, on opening a file containing one jig, it was drawn something like 20 times. # [bruce 060724 comments] if highlighted: inc = 0.01 # tested. Fixes bug 1681. mark 060314. else: inc = 0.0 glPushMatrix() try: glTranslatef( self.center[0], self.center[1], self.center[2]) q = self.quat glRotatef( q.angle*180.0/pi, q.x, q.y, q.z) orig_center = V(0.0, 0.0, 0.0) bCenter = orig_center - (self.length / 2.0 + inc) * self.axis tCenter = orig_center + (self.length / 2.0 + inc) * self.axis drawcylinder(color, bCenter, tCenter, self.radius + inc, capped = 1, opacity = self.opacity ) for a in self.atoms: drawcylinder(color, orig_center, a.posn()-self.center, self.sradius + inc, opacity = self.opacity) rotby = self.getrotation() #bruce 050518 # if exception in getrotation, just don't draw the rotation sign # (safest now that people might believe what it shows about amount of rotation) drawRotateSign((0,0,0), bCenter, tCenter, self.radius, rotation = rotby) except: #bruce 060208 protect OpenGL stack from exception seen in bug 1445 print_compact_traceback("exception in RotaryMotor._draw, continuing: ") print " some info that might be related to that exception: natoms = %d" % len(self.atoms) ###@@@ might not keep this glPopMatrix() return
def _draw_square(self): glPushMatrix() glColor3f(*rgb_to_f(*color.Blue)) glTranslatef(self._square_x, self._square_y, 0) glRotatef(self._angle, 0, 0, 1.) glBegin(GL_POLYGON) size = self._square_size / 2 square_vertices = [ (size, size), (size, -size), (-size, -size), (-size, size), ] for square_vertex in square_vertices: glVertex2d(*square_vertex) glEnd() glPopMatrix()
def draw(self): super(MTCircularSlider, self).draw() # faster calculation if we remove dot x, y = self.center p = 0, 0 r = self.radius t = self.thickness s = self.sweep_angle padding = self.padding with gx_matrix: set_color(*self.style.get('bg-color')) glTranslatef(x, y, 0) glRotatef(-self.rotation, 0, 0, 1) drawSemiCircle(p, r - t, r, 32, 1, 0, s) set_color(*self.style.get('slider-color')) drawSemiCircle(p, r - t + padding, r - padding, 32, 1, 0, self._slider_angle)
def draw_in_abs_coords(self, glpane, color): """ Draw the handle as a highlighted object. @param glpane: B{GLPane} object @type glpane: L{GLPane} @param color: Highlight color """ q = self.parent.quat glPushMatrix() glTranslatef(self.parent.center[0], self.parent.center[1], self.parent.center[2]) glRotatef(q.angle * ONE_RADIAN, q.x, q.y, q.z) if self.flipDirection: self._draw(flipDirection=self.flipDirection, highlighted=True) else: self._draw(highlighted=True) glPopMatrix()
def _can_(self, radius=1, height=1): ''' ''' glPushMatrix() glPushMatrix() glRotatef(90, 1, 0, 0) self._disk_(radius=radius) glPopMatrix() glPushMatrix() glTranslatef(0, -height, 0) glRotatef(90, 1, 0, 0) self._disk_(radius=radius) glPopMatrix() self._cylinder_(radius, height) glPopMatrix()
def pushMatrix(self): # [modified from same method in class Chunk] """Do glPushMatrix(), and then transform from external to local coordsys. """ # do most of the things that might cause exceptions before doing any OpenGL calls. x,y,z = self.motion cx,cy,cz = self.delegate.center q = self.quat try: a,b,c,d = q.angle*180.0/pi, q.x, q.y, q.z except: ###UNTESTED print "exception in a,b,c,d = q.angle*180.0/pi, q.x, q.y, q.z for q == %r" % (q,) # does my quat bug print this? no, it happily permits a quat to become Q(nan, nan, nan, nan) with no exception... a,b,c,d = 0,1,0,0 glPushMatrix() glTranslatef(x+cx,y+cy,z+cz) glRotatef(a,b,c,d) glTranslatef(-cx,-cy,-cz) return
def _nipple_(self, trans, rot, rh, flange='mini'): ''' ''' if flange == 'mini': frh = (0.66, 0.5) glPushMatrix() glTranslatef(*trans) glRotatef(*rot) self._can_(*rh) glPushMatrix() self._can_(*frh) glTranslatef(0, -rh[1] + frh[1], 0) self._can_(*frh) glPopMatrix() glPopMatrix()
def pushMatrix(self): # [modified from same method in class Chunk] """Do glPushMatrix(), and then transform from external to local coordsys. """ # do most of the things that might cause exceptions before doing any OpenGL calls. x, y, z = self.motion cx, cy, cz = self.delegate.center q = self.quat try: a, b, c, d = q.angle * 180.0 / pi, q.x, q.y, q.z except: ###UNTESTED print "exception in a,b,c,d = q.angle*180.0/pi, q.x, q.y, q.z for q == %r" % ( q, ) # does my quat bug print this? no, it happily permits a quat to become Q(nan, nan, nan, nan) with no exception... a, b, c, d = 0, 1, 0, 0 glPushMatrix() glTranslatef(x + cx, y + cy, z + cz) glRotatef(a, b, c, d) glTranslatef(-cx, -cy, -cz) return
def init_gl_stuff(): global current_res, fov # tells opengl to use the depth buffer, so things are drawn in the correct order glEnable(GL_DEPTH_TEST) #use our zbuffer #setup the camera glMatrixMode(GL_PROJECTION) # resets the matrix back to the origin glLoadIdentity() # defining a view frustrum gluPerspective( fov, # vertical field of view (deg) float(current_res[0]) / current_res[1], # aspect ratio 0.1, # zNear, the near clipping plane, don't render things closer than this 100.0 # zFar, the far clipping plane, don't render things beyond this ) # move the camera back three units glTranslatef(0.0, 0.0, -5.0) # orbit higher to view the subject at a better angle glRotatef(25, 1, 0, 0)
def draw(self): if not self.visible: return for objectID in self.objects: x, y, angle = self.objects[objectID] with gx_matrix: glTranslatef(x, y, 0.0) glRotatef(angle, 0.0, 0.0, 1.0) set_color(.5) drawCSSRectangle( pos=(-0.5 * self.width, -0.5 * self.height), size=(self.width, self.height), style=self.style ) set_color(*self.style['vector-color']) with gx_begin(GL_LINES): glVertex2f(0., 0.) glVertex2f(0., -0.5 * self.height)
def render(self): ''' ''' # super(Laser, self).render() MultiStateObject3D.render(self) glPushAttrib(GL_CURRENT_BIT) self._set_material() glPushMatrix() glRotatef(90, 1, 0, 0) self._disk_() glPopMatrix() glPushMatrix() glTranslatef(0, -1, 0) glRotatef(90, 1, 0, 0) self._disk_() glPopMatrix() self._cylinder_(1, 1) glPopAttrib()
def display(): start_point = ( start_picture_coord[0] * HEIGHT * mosaic_factory.ratio / (args.tiles - 1), start_picture_coord[1] * HEIGHT / (args.tiles - 1) ) center = (HEIGHT * mosaic_factory.ratio / 2., HEIGHT / 2.) reverse_sigmoid_progress = fake_sigmoid(1 - progress) sigmoid_progress = 1 - reverse_sigmoid_progress max_zoom = args.tiles zoom = max_zoom ** reverse_sigmoid_progress angle = start_orientation + sigmoid_progress * angle_difference( current_mosaic_picture.orientation, start_orientation ) if reverse_sigmoid_progress > 0.1: alpha = 1.0 else: alpha = reverse_sigmoid_progress * 10.0 glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() glTranslatef(center[0], center[1], 0.0) glRotatef(angle, 0, 0, 1) glTranslatef(-center[0], -center[1], 0.0) glTranslatef(start_point[0], start_point[1], 0.0) glScalef(zoom, zoom, 1.0) glTranslatef(-start_point[0], -start_point[1], 0.0) glColor4f(0.0, 0.0, 0.0, alpha) glCallList(mosaic_display_lists[current_mosaic_picture]) glColor4f(0.0, 0.0, 0.0, 1.0 - alpha) glScalef(max_zoom, max_zoom, 1.0) glCallList(picture_display_lists[current_mosaic_picture]) glPopMatrix() glutSwapBuffers()
def _elbow_(self, bend_radius, tube_radius): ''' ''' glPushMatrix() points = [(0, 0, 0), (0, 0, 0), (0, bend_radius, 0), (math.cos(bend_radius), bend_radius + math.sin(bend_radius), 0), (math.cos(bend_radius), bend_radius + math.sin(bend_radius), 0), (bend_radius, 2 * bend_radius, 0), (2 * bend_radius, 2 * bend_radius, 0), (2 * bend_radius, 2 * bend_radius, 0)] self._tube_(points, self.color, radius=tube_radius) glPushMatrix() glTranslatef(0, 0.5, 0) self._can_(0.66, 0.5) glPopMatrix() glTranslatef(2 * bend_radius - 0.5, 2 * bend_radius, 0) glRotatef(90, 0, 0, 1) self._can_(0.66, 0.5) glPopMatrix()
def render(self): ''' ''' super(Quadrupole, self).render() glPushMatrix() # if self.state: # glPushMatrix() # glRotatef(90, 1, 0, 0) # # import random # mod = 60 # nj = mod / 9 # revn = 2 # h = 7 # for i in [0, 1, 2, 4]: # for j in range(nj): # jj = j # j = j / float(nj) * mod - 1 # fact = ((ac + j) % mod) / mod # glPushMatrix() # radius = 1.2 * (1 - math.pow(fact, 4)) # glTranslatef(radius * math.cos(fact * revn * 2 * math.pi + math.pi / 2.0 * i), # radius * math.sin(fact * revn * 2 * math.pi + math.pi / 2.0 * i), # - fact * h + 4.2) # # self._set_material(color = [1, fact, 0, 2 * (fact ** 0.5) - 1.8 * fact ** 2]) # self._sphere_(radius = 0.2) # glPopMatrix() # glPopMatrix() self._set_material() self._cylinder_(0.75, 4) glTranslatef(0, 0, -3) glRotatef(-90, 1, 0, 0) self._can_(radius=1, height=3) glPopMatrix()
def _setup_modelview(self): """ set up modelview coordinate system """ #bruce 080912 moved this from GLPane into GLPane_minimal # note: it's not yet used in ThumbView, but maybe it could be. glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef( 0.0, 0.0, - self.vdist) # translate coordinate system for drawing, away from eye # (-Z direction) by vdist. This positions center of view # in eyespace. q = self.quat glRotatef( q.angle * 180.0 / math.pi, q.x, q.y, q.z) # rotate coordinate system for drawing by trackball quat # (this rotation is around the center of view, since that is what # is positioned at drawing coordsystem's current origin, # by the following code) glTranslatef( self.pov[0], self.pov[1], self.pov[2]) # translate model (about to be drawn) to bring its center of view # (cov == - pov) to origin of coordinate system for drawing. # We translate by -cov to bring model.cov to origin. return
def update_viewport(self): width, height = self.system_size w2 = width / 2.0 h2 = height / 2.0 # prepare the viewport glViewport(0, 0, width, height) # set the projection glMatrixMode(GL_PROJECTION) glLoadIdentity() glFrustum(-w2, w2, -h2, h2, 0.1, 1000) glScalef(5000, 5000, 1) # use the rotated size. width, height = self.size w2 = width / 2.0 h2 = height / 2.0 glTranslatef(-w2, -h2, -500) # set the model view glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(w2, h2, 0) glRotatef(self._rotation, 0, 0, 1) glTranslatef(-w2, -h2, 0) # update window size for w in self.children: shw, shh = w.size_hint if shw and shh: w.size = shw * width, shh * height elif shw: w.width = shw * width elif shh: w.height = shh * height
def draw_in_abs_coords(self, glpane, color): """ Draw the handle as a highlighted object. @param glpane: B{GLPane} object @type glpane: L{GLPane} @param color: Highlight color """ q = self.parent.quat glPushMatrix() glTranslatef( self.parent.center[0], self.parent.center[1], self.parent.center[2]) glRotatef( q.angle * ONE_RADIAN, q.x, q.y, q.z) if self.flipDirection: self._draw(flipDirection = self.flipDirection, highlighted = True) else: self._draw(highlighted = True) glPopMatrix()