def display(self,factor) : ''' Function to display the localview axes. ''' right_arrow = self.right.add_vertex(self.pos,self.right.mult_vector(factor,self.right)) up_arrow = self.up.add_vertex(self.pos,self.up.mult_vector(factor,self.up)) sight_arrow = self.sight.add_vertex(self.pos,self.sight.mult_vector(factor,self.sight)) glLineWidth(4) glColor(255,0,0) glBegin(GL_LINES) glVertex(self.pos.get_vertex()) glVertex(right_arrow.get_vertex()) glEnd() glColor(0,255,0) glBegin(GL_LINES) glVertex(self.pos.get_vertex()) glVertex(up_arrow.get_vertex()) glEnd() glColor(0,0,255) glBegin(GL_LINES) glVertex(self.pos.get_vertex()) glVertex(sight_arrow.get_vertex()) glEnd()
def _line(self, r1, r2): glColor(1, 1, 1) glLineWidth(1) glBegin(GL_LINES) glVertex3f(r1[0], r1[1], 0.0) glVertex3f(r2[0], r2[1], 0.0) glEnd()
def _init_GL(self): ''' ''' glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND) glEnable(GL_LINE_SMOOTH) glLineWidth(2.0) glEnable(GL_DEPTH_TEST) # glEnable(GL_TEXTURE_2D) # set the lighting self._set_lighting() # set the background color # glClearColor(0.15, 0.15, 0.15, 1) glClearDepth(1.0) # set the camera glMatrixMode(GL_PROJECTION) # glPushMatrix() glLoadIdentity() self._set_view_volume() glMatrixMode(GL_MODELVIEW) return
def draw(self, line_width=1, color=(1.0, 0.0, 0.0)): glEnable(GL_DEPTH_TEST) glEnable(GL_LINE_SMOOTH) glShadeModel(GL_FLAT) glPushMatrix() glLineWidth(line_width) glColor3f(*color) glBegin(GL_LINES) glVertex3f(-1.0, 0.0, 0.0) glVertex3f(1.0, 0.0, 0.0) glEnd() glPushMatrix() glTranslated(1.0, 0.0, 0.0) glRotated(90, 0.0, 1.0, 0.0) glutSolidCone(0.05, 0.2, 16, 16) glPopMatrix() glBegin(GL_LINES) glVertex3f(0.0, -1.0, 0.0) glVertex3f(0.0, 1.0, 0.0) glEnd() glPushMatrix() glTranslated(0.0, 1.0, 0.0) glRotated(-90, 1.0, 0.0, 0.0) glutSolidCone(0.05, 0.2, 16, 16) glPopMatrix() glBegin(GL_LINES) glVertex3f(0.0, 0.0, -1.0) glVertex3f(0.0, 0.0, 1.0) glEnd() glPushMatrix() glTranslated(0.0, 0.0, 1.0) glutSolidCone(0.05, 0.2, 16, 16) glPopMatrix() glPopMatrix()
def drawline_worker(params): """ Draw a line. 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) """ (endpt1, endpt2, dashEnabled, stipleFactor, width, isSmooth) = params ###glDisable(GL_LIGHTING) ###glColor3fv(color) if dashEnabled: glLineStipple(stipleFactor, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) if isSmooth: glEnable(GL_LINE_SMOOTH) glBegin(GL_LINES) glVertex(endpt1[0], endpt1[1], endpt1[2]) glVertex(endpt2[0], endpt2[1], endpt2[2]) glEnd() if isSmooth: glDisable(GL_LINE_SMOOTH) if width != 1: glLineWidth(1.0) # restore default state if dashEnabled: glDisable(GL_LINE_STIPPLE) ###glEnable(GL_LIGHTING) return
def draw_lines(self): """ draw our line segments, using our current style attrs [which are partly nim] """ # find variables which determine our GL state color = self.fix_color(self.linecolor) dashEnabled = self.dashed width = self.linewidth # set temporary GL state (code copied from drawer.drawline) glDisable(GL_LIGHTING) glColor3fv(color) if dashEnabled: glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) # draw the lines if self._closed_state: glBegin(GL_LINE_LOOP) else: glBegin(GL_LINE_STRIP) for pos in self.points: glVertex3fv(pos) # [note from old code: could be pos + origin if that can matter] glEnd() # restore default GL state [some of this might be moved up to callers] if width != 1: glLineWidth(1.0) if dashEnabled: glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return
def draw(self, time, line_width=None): if self.hidden: return if time <= self.ts: return time = time * 1e-9 pos_start = self.pos path = self.speed * (time - self.ts * 1e-9) * self.dir # max_end = self.pos + (self.speed * self.te * self.dir) # if not int(self.te) == 0 and time > self.te: # pos_end = max_end # else: # pos_end = self.pos + path pos_end = self.pos + path glPushMatrix() if line_width: glLineWidth(line_width) else: glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix()
def paint(self): glColor3f(0.0, 0.0, 0.6) glLineWidth(1.0); glBegin(GL_LINES) glVertex3f(*self.obj_a.position) glVertex3f(*self.obj_b.position) glEnd()
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 _paintGLGrid(self): resolutionMillimeters = 1 griddedAreaSize = 100 glLineWidth(1.0) glBegin(GL_LINES) glColor3f(1.0, 1.0, 1.0) glVertex3f(griddedAreaSize, 0, 0) glVertex3f(-griddedAreaSize, 0, 0) glVertex3f(0, griddedAreaSize, 0) glVertex3f(0, -griddedAreaSize, 0) numOfLines = int(griddedAreaSize / resolutionMillimeters) for i in range(numOfLines): glVertex3f(resolutionMillimeters * i, -griddedAreaSize, 0) glVertex3f(resolutionMillimeters * i, griddedAreaSize, 0) glVertex3f(griddedAreaSize, resolutionMillimeters * i, 0) glVertex3f(-griddedAreaSize, resolutionMillimeters * i, 0) glVertex3f(resolutionMillimeters * (-i), -griddedAreaSize, 0) glVertex3f(resolutionMillimeters * (-i), griddedAreaSize, 0) glVertex3f(griddedAreaSize, resolutionMillimeters * (-i), 0) glVertex3f(-griddedAreaSize, resolutionMillimeters * (-i), 0) glEnd()
def make_plane(): glNewList(G_OBJ_PLANE, GL_COMPILE) glBegin(GL_LINES) glColor3f(0, 0, 0) for i in xrange(41): glVertex3f(-10.0 + 0.5 * i, 0, -10) glVertex3f(-10.0 + 0.5 * i, 0, 10) glVertex3f(-10.0, 0, -10 + 0.5 * i) glVertex3f(10.0, 0, -10 + 0.5 * i) # Axes glEnd() glLineWidth(5) glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(5, 0.0, 0.0) glEnd() glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 5, 0.0) glEnd() glBegin(GL_LINES) glColor3f(0.5, 0.7, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 5) glEnd() # Draw the Y. glBegin(GL_LINES) glColor3f(0.0, 0.0, 0.0) glVertex3f(0.0, 5.0, 0.0) glVertex3f(0.0, 5.5, 0.0) glVertex3f(0.0, 5.5, 0.0) glVertex3f(-0.5, 6.0, 0.0) glVertex3f(0.0, 5.5, 0.0) glVertex3f(0.5, 6.0, 0.0) # Draw the Z. glVertex3f(-0.5, 0.0, 5.0) glVertex3f(0.5, 0.0, 5.0) glVertex3f(0.5, 0.0, 5.0) glVertex3f(-0.5, 0.0, 6.0) glVertex3f(-0.5, 0.0, 6.0) glVertex3f(0.5, 0.0, 6.0) # Draw the X. glVertex3f(5.0, 0.0, 0.5) glVertex3f(6.0, 0.0, -0.5) glVertex3f(5.0, 0.0, -0.5) glVertex3f(6.0, 0.0, 0.5) glEnd() glLineWidth(1) glEndList()
def _rectangle(self, r1, r2): glColor(1, 1, 1) glLineWidth(1) glBegin(GL_LINE_LOOP) glVertex3f(r1[0], r1[1], 0.0) glVertex3f(r2[0], r1[1], 0.0) glVertex3f(r2[0], r2[1], 0.0) glVertex3f(r1[0], r2[1], 0.0) glEnd()
def _draw(self): glLineWidth(4.0) glBegin(GL_LINES) glColor3f(119, 25, 25) for path in list(self._path_queue): glVertex3f(path[0] * self._resolution_meter -4,path[1] * self._resolution_meter,5) glVertex3f(path[0]* self._resolution_meter+4,path[1] * self._resolution_meter,5) glEnd()
def draw_lines(self, line_width=1): glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) for position in self.line_positions: glPushMatrix() glTranslated(position[0], position[1], 0) glLineWidth(line_width) glBegin(GL_LINES) glVertex3f(0.0, 0.0, self.z_min) glVertex3f(0.0, 0.0, self.z_max) glEnd() glPopMatrix()
def draw(self, line_width=2): glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) glPushMatrix() glTranslated(self.x, self.y, self.z) glLineWidth(line_width) glColor3f(1.0, 1.0, 1.0) glBegin(GL_LINES) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, self.length) glEnd() glPopMatrix()
def drawLineLoop(color,lines, width = 1): glDisable(GL_LIGHTING) glColor3fv(color) glLineWidth(width) glBegin(GL_LINE_LOOP) for v in lines: glVertex3fv(v) glEnd() glEnable(GL_LIGHTING) #reset the glLineWidth to 1 if width!=1: glLineWidth(1) return
def _draw(self): if self._cross is None: return glLineWidth(3.0) glBegin(GL_LINES) glColor3f(1.0, 0.0, 0.0) glVertex3f(self._cross[0] - 20, self._cross[1] - 20, 10) glVertex3f(self._cross[0] + 20, self._cross[1] + 20, 10) glVertex3f(self._cross[0] - 20, self._cross[1] + 20, 10) glVertex3f(self._cross[0] + 20, self._cross[1] - 20, 10) glEnd()
def draw(self, time, line_width=None): if self.hidden: return time = time * 1e-9 if time <= self.time: return pos_start = self.pos + (self.speed * (-self.time) * self.dir) path = self.speed * (time - self.time) * self.dir if self.length: max_path = self.length * self.dir if np.linalg.norm(max_path) <= np.linalg.norm(path): path = max_path pos_end = self.pos + path glPushMatrix() if line_width: glLineWidth(line_width) else: glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix() if self.cherenkov_cone_enabled and self.colourist.cherenkov_cone_enabled: height = np.linalg.norm(pos_end - pos_start) position = pos_end - self.dir * height glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) glColor4f(0.0, 0.0, 0.8, 0.3) glPushMatrix() glTranslated(*position) glPushMatrix() v = np.array(self.dir) glMultMatrixf(transform(v)) glutSolidCone(0.6691 * height, height, 128, 64) glPopMatrix() glPopMatrix() glDisable(GL_LIGHTING)
def _initGL(self, extraArgs): """initializes OpenGL and creates the Window""" glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutInitWindowSize(self.size, self.size) glutInitWindowPosition(self.initx, self.inity) glutInit(extraArgs.split(" ")) glutCreateWindow(VERSIONSTRING.encode("ascii")) glutDisplayFunc(self.Draw) glutIdleFunc(glutPostRedisplay) glutReshapeFunc(self.Reshape) glutKeyboardFunc(self.HandleKeys) glutSpecialFunc(self.HandleKeys) glutMouseFunc(self.HandleMouse) glClearColor(*(self.bgcolor + [0.0])) glEnable(GL_LINE_SMOOTH) glLineWidth(1.3)
def _draw(self): glLineWidth(4.0) glBegin(GL_LINES) glColor3f(0.5, 0.5, 0.5) glVertex3f(0.0, 0.0, 0.0) glVertex3f(50.0, 0.0, 1.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 50.0, 1.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 50.0) glEnd()
def _paintGLCoorsystem(self): glLineWidth(10.0) glBegin(GL_LINES) glColor3f(1.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(1.0, 0.0, 0.0) glColor3f(0.0, 1.0, 0.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 1.0, 0.0) glColor3f(0.0, 0.0, 1.0) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 1.0) glEnd()
def render(self): glLineWidth(3.0) glColor(0.7, 0.0, 0.0, 1.0) gltools.glMove([0.0, 0.0, 0.0]) glBegin(GL_LINE_STRIP) for p in [self.p1, self.C, self.p2]: glVertex(p) glEnd() glColor(0.545, 0.000, 0.000, 1.0) gltools.glMove(self.p1) glutSolidSphere(0.03, 4, 2) glColor(1.000, 0.843, 0.000, 1.0) gltools.glMove(self.C) glutSolidSphere(0.03, 4, 2) glColor(0.294, 0.000, 0.510, 1.0) gltools.glMove(self.p2) glutSolidSphere(0.03, 4, 2) glLineWidth(1.0)
def _draw(self): try: self._lock.acquire() gridded_area_size = 1500 glLineWidth(1.0) num_of_lines = int(gridded_area_size / self._resolution_meters) glBegin(GL_LINES) glColor3f(0.188, 0.188, 0.188) glVertex3f(gridded_area_size, 0, 0) glVertex3f(-gridded_area_size, 0, 0) glVertex3f(0, gridded_area_size, 0) glVertex3f(0, -gridded_area_size, 0) for i in range(num_of_lines): glVertex3f(self._resolution_meters * i, -gridded_area_size, 0) glVertex3f(self._resolution_meters * i, gridded_area_size, 0) glVertex3f(gridded_area_size, self._resolution_meters * i, 0) glVertex3f(-gridded_area_size, self._resolution_meters * i, 0) glVertex3f(self._resolution_meters * (-i), -gridded_area_size, 0) glVertex3f(self._resolution_meters * (-i), gridded_area_size, 0) glVertex3f(gridded_area_size, self._resolution_meters * (-i), 0) glVertex3f(-gridded_area_size, self._resolution_meters * (-i), 0) glEnd() glLineWidth(3.0) glBegin(GL_LINES) glVertex3f(0, -gridded_area_size, 0) glVertex3f(0, gridded_area_size, 0) glVertex3f(gridded_area_size, 0, 0) glVertex3f(-gridded_area_size, 0, 0) glEnd() finally: self._lock.release()
def draw(self): # draw gestures set_color(1, 1, 1, 0.6) for touch in getCurrentTouches(): if not "desktop.gesture" in touch.userdata: continue drawLine(touch.userdata["desktop.gesture"], width=5.0) if len(getCurrentTouches()): self.inactivity = 0 return self.inactivity += getFrameDt() if self.inactivity < self.inactivity_timeout: return alpha = (self.inactivity - self.inactivity_timeout) / 3.0 alpha = boundary(alpha, 0, 1.0) w = self.get_parent_window() s2 = Vector(w.size) / 2.0 self.dt += getFrameDt() * 2 step = math.pi / 20.0 radius = 50 i = 0 with DO(gx_attrib(GL_LINE_BIT), gx_blending): glLineWidth(3) with gx_begin(GL_LINE_STRIP): while i < math.pi * 2: x, y = math.cos(self.dt - i) * radius, math.sin(self.dt - i) * radius glColor4f(1, 1, 1, min(alpha, i / math.pi)) glVertex2f(x + s2.x, y + s2.y - 70) i += step set_color(1, 1, 1, alpha) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=4) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=20, linewidth=2) label = "Draw a circle to make the menu appear" k = {"font_size": 24, "bold": True} pos = Vector(w.size) / 2.0 + Vector(0, 10) drawLabel(label=label, pos=pos, color=(0.5, 0.5, 0.5, min(alpha, 0.5)), **k) pos += Vector(1, -1) drawLabel(label=label, pos=pos, color=(1, 1, 2, alpha), **k)
def draw(self): # extract relative position rx, ry = self.relpos # calculate triangle mx = self.x + rx + self.width * 0.5 + self.trirelpos[0] my = self.y + ry + self.height * 0.5 + self.trirelpos[1] angle = Vector(1, 0).angle(Vector(mx - self.x, my - self.y)) vpos = Vector(mx, my) v1 = Vector(self.trisize, 0).rotate(angle) + vpos v2 = Vector(-self.trisize, 0).rotate(angle) + vpos # draw border if self.bordersize > 0: drawRoundedRectangle( pos=(self.x - self.padding - self.bordersize + rx, self.y - self.padding - self.bordersize + ry), size=(self.width + self.padding * 2 + self.bordersize * 2, self.height + self.padding * 2 + self.bordersize * 2), radius=self.radius, color=self.bordercolor ) glEnable(GL_LINE_SMOOTH) glLineWidth(self.bordersize * 2) drawPolygon((self.x, self.y, v1.x, v1.y, v2.x, v2.y), style=GL_LINE_LOOP) # draw background drawRoundedRectangle( pos=(self.x - self.padding + rx, self.y - self.padding + ry), size=(self.width + self.padding * 2, self.height + self.padding * 2), radius=self.radius, color=self.bgcolor ) drawPolygon((self.x, self.y, v1.x, v1.y, v2.x, v2.y)) # hack to translate label position with gx_matrix: glTranslatef(rx, ry, 0) super(MTSpeechBubble, self).draw()
def __draw(self, widget, event): x = self.__distance * sin(self.__angle) z = self.__distance * cos(self.__angle) gldrawable = widget.get_gl_drawable() glcontext = widget.get_gl_context() # OpenGL begin. if not gldrawable.gl_begin(glcontext): return glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity () gluLookAt(x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) #========================== glPushMatrix() glLineWidth(3) glRotatef(self.__arm_angles[0], 1., 0., 0.) glRotatef(self.__arm_angles[1], 0., 1., 0.) glRotatef(self.__arm_angles[2], 0., 0., 1.) glTranslatef(self.__upper_arm, 0., 0.) #========================== glPushMatrix() glColor3f(30./255., 126./255., 30./255.) glScalef(self.__upper_arm, 0.4, 1.0) self.__draw_cube() # shoulder glPopMatrix() #========================== glTranslatef(self.__upper_arm, 0., 0.) glRotatef(self.__arm_angles[3] , 0., 0., 1.) glTranslatef(self.__forearm, 0., 0.) glPushMatrix() #========================== glScalef(self.__forearm, 0.3, 0.75) glColor3f(126./255., 30./255., 30./255.) self.__draw_cube() # elbow glPopMatrix() glPopMatrix() #========================== if gldrawable.is_double_buffered(): gldrawable.swap_buffers() else: glFlush() gldrawable.gl_end() # OpenGL end return
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if not OPENGL_PAINT_BOX>0: return glDisable(GL_TEXTURE_RECTANGLE_ARB) glDisable(GL_FRAGMENT_PROGRAM_ARB) glLineWidth(OPENGL_PAINT_BOX+0.5) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def draw(self, time, line_width=None): if self.hidden: return time = time * 1e-9 pos_start = self.start_pos + (constants.c * (-self.time) * self.dir) if time >= self.time: pos_end = self.pos else: path = constants.c * (time - self.time) * self.dir pos_end = self.pos + path glPushMatrix() glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix()
def startPatternedDrawing(highlight = False, select = False): """ Start drawing with a patterned style, if either highlight or select is passed as True, and the corresponding preference is set to select a patterned drawing style. This is common code for two different prefs keys, each of which has its own set of settings constants... Return value is True if one of the patterned styles is selected. """ (key, style, solid, pattern, edges, halos) = \ _decodePatternPrefs(highlight, select) if solid: # Nothing to do here for solid colors. return False # Set up stipple-patterned drawing styles. if pattern is not None: glEnable(GL_POLYGON_STIPPLE) glPolygonStipple(pattern) return True # Both polygon edges and halos are drawn in line-mode. if edges or halos: glPolygonMode(GL_FRONT, GL_LINE) glPolygonMode(GL_BACK, GL_LINE) if halos: # Draw wide, unshaded lines, offset a little bit away from the # viewer so that only the silhouette edges are visible. glDisable(GL_LIGHTING) glLineWidth(env.prefs[haloWidth_prefs_key]) glEnable(GL_POLYGON_OFFSET_LINE) glPolygonOffset(0.0, 5.e4) # Constant offset. pass pass return True
def drawAxis(color, pos1, pos2, width = 2): #Ninad 060907 """ Draw chunk or jig axis """ #ninad060907 Note that this is different than draw # I may need this function to draw axis line. see its current implementation # in branch "ninad_060908_drawAxis_notAsAPropOfObject" glDisable(GL_LIGHTING) glColor3fv(color) glLineStipple(3, 0x1C47) # dash-dot-dash line glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) glBegin(GL_LINES) glVertex(pos1[0], pos1[1], pos1[2]) glVertex(pos2[0], pos2[1], pos2[2]) glEnd() if width != 1: glLineWidth(1.0) # restore default state glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return