def create_objects(self): self.mcp = RenderObject(gl.GL_TRIANGLES, vertex=np.array(rect(-1, -1, 2, 2), dtype=np.float32)) self.mcp_texture = load_texture('mcp737.png') self.btn_tex = load_texture('btn_led.png') self.lcd_tex = load_lcd_font() v_mcp_text = [] for pos in [ 0.0, 0.03, 0.06, 0.31, 0.34, 0.37, 0.4, 0.43, 0.644, 0.674, 0.704, 0.955, 0.985, 1.015, 1.045, 1.075, 1.22, 1.25, 1.28, 1.31, 1.34, 1.69, 1.72, 1.75 ]: v, t = Font.char(-0.886 + pos, 0.45, 0.03, 0.25) v_mcp_text += v self.mcp_text = RenderObject(gl.GL_TRIANGLES, vertex=np.array(v_mcp_text, dtype=np.float32)) self.lcd_charcoords = np.zeros(24 * 6, dtype=np.float32) self.lcdbuf = self.mcp_text.bind_attrib(1, 1, self.lcd_charcoords, datatype=gl.GL_FLOAT) btn_leds = [] for pos in [(-0.74, -0.75), (-0.645, -0.75), (-0.37, -0.75), (-0.232, -0.75), (-0.09, -0.75), (0.105, -0.75), (0.2, -0.75), (-0.37, 0.5), (-0.09, 0.5), (-0.09, -0.125), (0.575, 0.34), (0.575, -0.34), (0.684, 0.34), (0.684, -0.34)]: btn_leds += rect(pos[0], pos[1], 0.055, 0.075) btn_color = np.zeros(14 * 6 * 4, dtype=np.uint8) self.btn_leds = RenderObject(gl.GL_TRIANGLES, vertex=np.array(btn_leds, dtype=np.float32), color=btn_color) # Button up/down indicator w, h, offset = 0.04, 0.16, 0.04 triangles = np.array([ -w, offset, 0.0, offset + h, w, offset, -w, -offset, 0.0, -offset - h, w, -offset ], dtype=np.float32) col_triangles = np.array(6 * [255, 255, 255, 180], dtype=np.uint8) self.updown = RenderObject(gl.GL_TRIANGLES, vertex=triangles, color=col_triangles) # Use the same font as the radarwidget self.font = Font() self.font.create_font_array('../../data/graphics/font/') self.font.init_shader(self.text_shader) edge = np.zeros(120, dtype=np.float32) edge[0:120:2] = 1.4 * np.sin(np.radians(np.arange(-60, 60, 2))) edge[1:120:2] = 1.4 * np.cos(np.radians(np.arange(-60, 60, 2))) self.edge = RenderObject(gl.GL_LINE_STRIP, vertex=edge, color=white) arcs = [] for i in range(1, 4): for angle in range(-60, 60, max(2, 6 - 2 * i)): arcs.append(float(i) * 0.35 * sin(radians(angle))) arcs.append(float(i) * 0.35 * cos(radians(angle))) if i == 4: arcs.append(float(i) * 0.35 * sin(radians(angle + 2))) arcs.append(float(i) * 0.35 * cos(radians(angle + 2))) arcs = np.array(arcs, dtype=np.float32) self.arcs = RenderObject(gl.GL_LINES, vertex=arcs, color=white) mask = [] for angle in range(-60, 60, 2): mask.append(1.4 * sin(radians(angle))) mask.append(10.0) mask.append(1.4 * sin(radians(angle))) mask.append(1.4 * cos(radians(angle))) mask = np.array(mask, dtype=np.float32) self.mask = RenderObject(gl.GL_TRIANGLE_STRIP, vertex=mask, color=black) ticks = np.zeros(288, dtype=np.float32) for i in range(72): ticktop = 1.46 if i % 6 == 0 else (1.44 if i % 2 == 0 else 1.42) ticks[4 * i:4 * i + 2] = (1.4 * sin(radians(i * 5)), 1.4 * cos(radians(i * 5))) ticks[4 * i + 2:4 * i + 4] = (ticktop * sin(radians(i * 5)), ticktop * cos(radians(i * 5))) self.ticks = RenderObject(gl.GL_LINES, vertex=ticks, color=white) ticklbls = np.zeros(24 * 36, dtype=np.float32) texcoords = np.zeros(36 * 36, dtype=np.float32) for i in range(36): if i % 3 == 0: w, h, y = 0.045, 0.09, 1.48 else: w, h, y = 0.035, 0.07, 1.46 tmp = [(-w, h + y), (-w, y), (0.0, h + y), (0.0, h + y), (-w, y), (0.0, y), (0.0, h + y), (0.0, y), (w, h + y), (w, h + y), (0.0, y), (w, y)] # numerics start at ASCII 48 c1 = i / 10 + 48 c2 = i % 10 + 48 texcoords[36 * i:36 * i + 18] = [ 0, 0, c1, 0, 1, c1, 1, 0, c1, 1, 0, c1, 0, 1, c1, 1, 1, c1 ] texcoords[36 * i + 18:36 * i + 36] = [ 0, 0, c2, 0, 1, c2, 1, 0, c2, 1, 0, c2, 0, 1, c2, 1, 1, c2 ] angle = radians(10 * (36 - i)) rot = np.array([[cos(angle), -sin(angle)], [sin(angle), cos(angle)]]) for j in range(12): ticklbls[24 * i + 2 * j:24 * i + 2 * j + 2] = rot.dot(tmp[j]) self.ticklbls = RenderObject(gl.GL_TRIANGLES, vertex=ticklbls, color=white, texcoords=texcoords) vown = np.array([ 0.0, 0.0, 0.0, -0.12, 0.065, -0.03, -0.065, -0.03, 0.022, -0.1, -0.022, -0.1 ], dtype=np.float32) self.ownship = RenderObject(gl.GL_LINES, vertex=vown, color=yellow) self.spdlabel_text = self.font.prepare_text_string( 'GS TAS', 0.05, white, (-0.98, 1.6)) self.spdlabel_val = self.font.prepare_text_string( ' 000 000', 0.05, green, (-0.97, 1.6)) self.initialized = True # Unbind everything RenderObject.unbind_all()
def create_objects(self): self.mcp = RenderObject(gl.GL_TRIANGLES, vertex=np.array(rect(-1, -1, 2, 2), dtype=np.float32)) self.mcp_texture = load_texture('mcp737.png') self.btn_tex = load_texture('btn_led.png') self.lcd_tex = load_lcd_font() v_mcp_text = [] for pos in [0.0, 0.03, 0.06, 0.31, 0.34, 0.37, 0.4, 0.43, 0.644, 0.674, 0.704, 0.955, 0.985, 1.015, 1.045, 1.075, 1.22, 1.25, 1.28, 1.31, 1.34, 1.69, 1.72, 1.75]: v, t = Font.char(-0.886 + pos, 0.45, 0.03, 0.25) v_mcp_text += v self.mcp_text = RenderObject(gl.GL_TRIANGLES, vertex=np.array(v_mcp_text, dtype=np.float32)) self.lcd_charcoords = np.zeros(24 * 6, dtype=np.float32) self.lcdbuf = self.mcp_text.bind_attrib(1, 1, self.lcd_charcoords, datatype=gl.GL_FLOAT) btn_leds = [] for pos in [(-0.74, -0.75), (-0.645, -0.75), (-0.37, -0.75), (-0.232, -0.75), (-0.09, -0.75), (0.105, -0.75), (0.2, -0.75), (-0.37, 0.5), (-0.09, 0.5), (-0.09, -0.125), (0.575, 0.34), (0.575, -0.34), (0.684, 0.34), (0.684, -0.34)]: btn_leds += rect(pos[0], pos[1], 0.055, 0.075) btn_color = np.zeros(14 * 6 * 4, dtype=np.uint8) self.btn_leds = RenderObject(gl.GL_TRIANGLES, vertex=np.array(btn_leds, dtype=np.float32), color=btn_color) # Button up/down indicator w, h, offset = 0.04, 0.16, 0.04 triangles = np.array([-w, offset, 0.0, offset + h, w, offset, -w, -offset, 0.0, -offset - h, w, -offset], dtype=np.float32) col_triangles = np.array(6 * [255, 255, 255, 180], dtype=np.uint8) self.updown = RenderObject(gl.GL_TRIANGLES, vertex=triangles, color=col_triangles) # Use the same font as the radarwidget self.font = Font() self.font.create_font_array('../../data/graphics/font/') self.font.init_shader(self.text_shader) edge = np.zeros(120, dtype=np.float32) edge[0:120:2] = 1.4 * np.sin(np.radians(np.arange(-60, 60, 2))) edge[1:120:2] = 1.4 * np.cos(np.radians(np.arange(-60, 60, 2))) self.edge = RenderObject(gl.GL_LINE_STRIP, vertex=edge, color=white) arcs = [] for i in range(1, 4): for angle in range(-60, 60, max(2, 6 - 2 * i)): arcs.append(float(i) * 0.35 * sin(radians(angle))) arcs.append(float(i) * 0.35 * cos(radians(angle))) if i == 4: arcs.append(float(i) * 0.35 * sin(radians(angle + 2))) arcs.append(float(i) * 0.35 * cos(radians(angle + 2))) arcs = np.array(arcs, dtype=np.float32) self.arcs = RenderObject(gl.GL_LINES, vertex=arcs, color=white) mask = [] for angle in range(-60, 60, 2): mask.append(1.4 * sin(radians(angle))) mask.append(10.0) mask.append(1.4 * sin(radians(angle))) mask.append(1.4 * cos(radians(angle))) mask = np.array(mask, dtype=np.float32) self.mask = RenderObject(gl.GL_TRIANGLE_STRIP, vertex=mask, color=black) ticks = np.zeros(288, dtype=np.float32) for i in range(72): ticktop = 1.46 if i % 6 == 0 else (1.44 if i % 2 == 0 else 1.42) ticks[4*i :4*i+2] = (1.4 * sin(radians(i * 5)), 1.4 * cos(radians(i * 5))) ticks[4*i+2:4*i+4] = (ticktop * sin(radians(i * 5)), ticktop * cos(radians(i * 5))) self.ticks = RenderObject(gl.GL_LINES, vertex=ticks, color=white) ticklbls = np.zeros(24 * 36, dtype=np.float32) texcoords = np.zeros(36 * 36, dtype=np.float32) for i in range(36): if i % 3 == 0: w, h, y = 0.045, 0.09, 1.48 else: w, h, y = 0.035, 0.07, 1.46 tmp = [(-w, h+y), (-w, y), (0.0, h+y), (0.0, h+y), (-w, y), (0.0, y), (0.0, h+y), (0.0, y), (w, h+y), (w, h+y), (0.0, y), (w, y)] # numerics start at ASCII 48 c1 = i / 10 + 48 c2 = i % 10 + 48 texcoords[36*i:36*i+18] = [0, 0, c1, 0, 1, c1, 1, 0, c1, 1, 0, c1, 0, 1, c1, 1, 1, c1] texcoords[36*i+18:36*i+36] = [0, 0, c2, 0, 1, c2, 1, 0, c2, 1, 0, c2, 0, 1, c2, 1, 1, c2] angle = radians(10 * (36 - i)) rot = np.array([[cos(angle), -sin(angle)], [sin(angle), cos(angle)]]) for j in range(12): ticklbls[24*i+2*j:24*i+2*j+2] = rot.dot(tmp[j]) self.ticklbls = RenderObject(gl.GL_TRIANGLES, vertex=ticklbls, color=white, texcoords=texcoords) vown = np.array([0.0, 0.0, 0.0, -0.12, 0.065, -0.03, -0.065, -0.03, 0.022, -0.1, -0.022, -0.1], dtype=np.float32) self.ownship = RenderObject(gl.GL_LINES, vertex=vown, color=yellow) self.spdlabel_text = self.font.prepare_text_string('GS TAS', 0.05, white, (-0.98, 1.6)) self.spdlabel_val = self.font.prepare_text_string(' 000 000', 0.05, green, (-0.97, 1.6)) self.initialized = True # Unbind everything RenderObject.unbind_all()