コード例 #1
0
 def drawLinePlot(self, colourFades, dataPoints):
     ac.glBegin(1)
     for dataPoint, colour in zip(dataPoints, colourFades):
         ac.glColor4f(*colour)
         x, y = self.gPlotter.plotG(dataPoint['x'], dataPoint['z'])
         ac.glVertex2f(x,y)
     ac.glEnd()
コード例 #2
0
 def drawCircumference(self, radius, center):
     ac.glBegin(1)
     nlines = max(4, int(100.*radius))
     for i in range(nlines+1):
         x, y = self.gPlotter.plotG(center['x'] + (sin(2*pi*i/nlines)*radius), center['z'] + (cos(2*pi*i/nlines)*radius))
         ac.glVertex2f(x, y)
     ac.glEnd()
コード例 #3
0
def drawClutchGauge():
	global posting, post_time_elapsed, post_total_time
	inner_min_rad = math.asin((clutch_gauge_root_y-clutch_gauge_min_y)/clutch_gauge_inner_radius)
	inner_max_rad = math.asin((clutch_gauge_root_y-clutch_gauge_max_y+1)/clutch_gauge_inner_radius)
	outer_min_rad = math.asin((clutch_gauge_root_y-clutch_gauge_min_y)/clutch_gauge_outer_radius)
	outer_max_rad = math.asin((clutch_gauge_root_y-clutch_gauge_max_y+1)/clutch_gauge_outer_radius)
	for i in range(0,int((1-ac.getCarState(0,acsys.CS.Clutch))*100),1):
		# p1 = inner, p2 = outer
		# p3 = inner, p4 = outer
		rad1 = (inner_max_rad-inner_min_rad)/100*(100-i)     - inner_max_rad + (math.pi if clutch_gauge_right else 0)
		rad2 = (outer_max_rad-outer_min_rad)/100*(100-i)     - outer_max_rad + (math.pi if clutch_gauge_right else 0)
		rad3 = (inner_max_rad-inner_min_rad)/100*(100 - i+1) - inner_max_rad + (math.pi if clutch_gauge_right else 0)
		rad4 = (outer_max_rad-outer_min_rad)/100*(100 - i+1) - outer_max_rad + (math.pi if clutch_gauge_right else 0)
		
		p1_x = math.cos(rad1)*clutch_gauge_inner_radius + clutch_gauge_root_x
		p1_y = clutch_gauge_root_y - math.sin(rad1)*clutch_gauge_inner_radius
		p2_x = math.cos(rad2)*clutch_gauge_outer_radius + clutch_gauge_root_x
		p2_y = clutch_gauge_root_y - math.sin(rad2)*clutch_gauge_outer_radius
		p3_x = math.cos(rad3)*clutch_gauge_inner_radius + clutch_gauge_root_x
		p3_y = clutch_gauge_root_y - math.sin(rad3)*clutch_gauge_inner_radius
		p4_x = math.cos(rad4)*clutch_gauge_outer_radius + clutch_gauge_root_x
		p4_y = clutch_gauge_root_y - math.sin(rad4)*clutch_gauge_outer_radius
		
		ac.glBegin(2)
		ac.glColor4f(clutch_gauge_color[0],clutch_gauge_color[1],clutch_gauge_color[2],clutch_gauge_color[3])
		ac.glVertex2f(p1_x,p1_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p3_x,p3_y)
		ac.glEnd()
		ac.glBegin(2)
		ac.glColor4f(clutch_gauge_color[0],clutch_gauge_color[1],clutch_gauge_color[2],clutch_gauge_color[3])
		ac.glVertex2f(p3_x,p3_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p4_x,p4_y)
		ac.glEnd()
コード例 #4
0
def drawBrakeGauge():
	global posting, post_time_elapsed, post_total_time
	inner_min_rad = math.asin((brake_gauge_root_y-brake_gauge_min_y)/brake_gauge_inner_radius)
	inner_max_rad = math.asin((brake_gauge_root_y-brake_gauge_max_y)/brake_gauge_inner_radius)
	outer_min_rad = math.asin((brake_gauge_root_y-brake_gauge_min_y)/brake_gauge_outer_radius)
	outer_max_rad = math.asin((brake_gauge_root_y-brake_gauge_max_y)/brake_gauge_outer_radius)
	for i in range(0,int((ac.getCarState(0,acsys.CS.Brake))*100),1):
		# p1 = inner, p2 = outer
		# p3 = inner, p4 = outer
		rad1 = (inner_max_rad-inner_min_rad)/100*i     + inner_min_rad + (math.pi if brake_gauge_right else 0)
		rad2 = (outer_max_rad-outer_min_rad)/100*i     + outer_min_rad + (math.pi if brake_gauge_right else 0)
		rad3 = (inner_max_rad-inner_min_rad)/100*(i+1) + inner_min_rad + (math.pi if brake_gauge_right else 0)
		rad4 = (outer_max_rad-outer_min_rad)/100*(i+1) + outer_min_rad + (math.pi if brake_gauge_right else 0)
		
		p1_x = math.cos(rad1)*brake_gauge_inner_radius + brake_gauge_root_x
		p1_y = brake_gauge_root_y - math.sin(rad1)*brake_gauge_inner_radius
		p2_x = math.cos(rad2)*brake_gauge_outer_radius + brake_gauge_root_x
		p2_y = brake_gauge_root_y - math.sin(rad2)*brake_gauge_outer_radius
		p3_x = math.cos(rad3)*brake_gauge_inner_radius + brake_gauge_root_x
		p3_y = brake_gauge_root_y - math.sin(rad3)*brake_gauge_inner_radius
		p4_x = math.cos(rad4)*brake_gauge_outer_radius + brake_gauge_root_x
		p4_y = brake_gauge_root_y - math.sin(rad4)*brake_gauge_outer_radius
		
		ac.glBegin(2)
		ac.glColor4f(brake_gauge_color[0],brake_gauge_color[1],brake_gauge_color[2],brake_gauge_color[3])
		ac.glVertex2f(p1_x,p1_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p3_x,p3_y)
		ac.glEnd()
		ac.glBegin(2)
		ac.glColor4f(brake_gauge_color[0],brake_gauge_color[1],brake_gauge_color[2],brake_gauge_color[3])
		ac.glVertex2f(p3_x,p3_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p4_x,p4_y)
		ac.glEnd()
コード例 #5
0
def draw_triangle(points, color=[1, 1, 1]):
    r, g, b = color
    ac.glColor4f(r, g, b, 1)
    ac.glBegin(acsys.GL.Triangles)
    for x_y_tuple in points:
        x, y = x_y_tuple
        ac.glVertex2f(x, y)
    ac.glEnd()
コード例 #6
0
 def drawCross(self, radius):
     ac.glBegin(1)
     ac.glVertex2f(*self.gPlotter.plotG(-radius, 0))
     ac.glVertex2f(*self.gPlotter.plotG(+radius, 0))
     ac.glEnd()
     ac.glBegin(1)
     ac.glVertex2f(*self.gPlotter.plotG(0, -radius))
     ac.glVertex2f(*self.gPlotter.plotG(0, +radius))
     ac.glEnd()
コード例 #7
0
def draw_bar(points, color=[1, 1, 1]):
    global rectangle_corners
    r, g, b = color
    ac.glColor4f(r, g, b, 1)
    ac.glBegin(acsys.GL.Quads)
    for corner in rectangle_corners:
        x, y = points[corner]
        ac.glVertex2f(x, y)
    ac.glEnd()
コード例 #8
0
def draw_colored_bars_with_points(slip, tyre):
    global max_slip, rectangle_corners
    r, g, b = get_color(slip)
    ac.glColor4f(r, g, b, 1)
    ac.glBegin(acsys.GL.Quads)
    for corner in rectangle_corners:
        x, y = tyre[corner]
        ac.glVertex2f(x, y)
    ac.glEnd()
コード例 #9
0
def drawboostBars(x,y):
    ac.glColor4f(1,0.31,0,1)
    ac.glQuad(0,42,percentage_boost*4.35,8)
    #ac.glQuad(960,42,-percentage_boost*4.35,8)
    ac.glBegin(acsys.GL.Quads)
    ac.glVertex2f(960,42)
    ac.glVertex2f(960-percentage_boost*4.35,42)
    ac.glVertex2f(960-percentage_boost*4.35,50)
    ac.glVertex2f(960,50)
    ac.glEnd()
コード例 #10
0
 def drawCircle(self, radius, center):
     ac.glBegin(acsys.GL.Triangles)
     prevx, prevy = self.gPlotter.plotG(center['x'], center['z'])
     ntriangles = max(4, int(100.*radius))
     for i in range(ntriangles+1):
         ac.glVertex2f(*self.gPlotter.plotG(center['x'], center['z']))
         ac.glVertex2f(prevx, prevy)
         x, y = self.gPlotter.plotG(center['x'] + (sin(2*pi*i/ntriangles)*radius), center['z'] + (cos(2*pi*i/ntriangles)*radius))
         ac.glVertex2f(x, y)
         prevx, prevy = x, y
     ac.glEnd()
コード例 #11
0
def drawGMeter():
	global posting, post_time_elapsed, post_total_time
	# Colors
	c1 = [0.0,200/255,1.0,g_meter_opacity] # Middle one
	c2 = [0.0,150/255,1.0,g_meter_opacity] # Inner
	c3 = [0.0,125/255,1.0,g_meter_opacity] # Middle inner
	c4 = [0.0,100/255,1.0,g_meter_opacity] # Outer
	g = ac.getCarState(0,acsys.CS.AccG)[0]
	# Neg range: 660..511
	# Pos range: 660..809
	l_x = r_x = 0
	pixels = int(abs(g)*(g_meter_range/2.52))
	if abs(g) >= 2.52:
		pixels = g_meter_range # ALL OF THEM
	if g < 0:
		r_x = g_meter_x_anchor
		l_x = r_x - pixels
	else:
		l_x = g_meter_x_anchor
		r_x = l_x + pixels
	t_y = g_meter_y_anchor
	for i in range(0,11,1):
		c = []
		offset = 0
		if i == 0 or i == 1 or i == 9 or i == 10:
			c = c4
			offset = 4
		elif i == 2 or i == 8:
			c = c3
			offset = 2
		elif i == 3 or i == 7:
			c = c3
			offset = 1
		elif i == 4 or i == 6:
			c = c2
			offset = 1
		else:
			c = c1
		if g > 0 and r_x - offset <= l_x:
			continue
		elif g < 0 and l_x + offset >= r_x:
			continue
		l_offset = r_offset = 0
		if g > 0:
			r_offset = - offset
		if g < 0:
			l_offset = offset
		ac.glBegin(0)
		ac.glColor4f(c[0],c[1],c[2],c[3])
		ac.glVertex2f(l_x+l_offset,t_y+i)
		ac.glVertex2f(r_x+r_offset,t_y+i)
		ac.glEnd()
コード例 #12
0
 def _draw_polygon(p1, p2, p3, p4, reversed_normal):
   ac.glBegin(3)
   if not reversed_normal:
     ac.glVertex2f(*p1)
     ac.glVertex2f(*p2)
     ac.glVertex2f(*p3)
     ac.glVertex2f(*p4)
   else:
     ac.glVertex2f(*p1)
     ac.glVertex2f(*p4)
     ac.glVertex2f(*p3)
     ac.glVertex2f(*p2)
   ac.glEnd()
コード例 #13
0
def drawrpmBars(x,y):
    if(abs(percentage_rpm)<max_user_rpm):ac.glColor4f(1,1,1,1)
    if(abs(percentage_rpm)>max_user_rpm):ac.glColor4f(1,0,0,1)
    if(percentage_rpm <min_user_rpm):
        ac.glQuad(0,20,0,20)
        ac.glQuad(960,20,0,20)
    if(percentage_rpm >min_user_rpm):
        ac.glQuad(0,20,abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm),20)
        #ac.glQuad(960,20,-(abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm)),20)
        ac.glBegin(acsys.GL.Quads)
        ac.glVertex2f(960,20)
        ac.glVertex2f(960-abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm),20)
        ac.glVertex2f(960-abs(percentage_rpm-min_user_rpm)*435/(100-min_user_rpm),40)
        ac.glVertex2f(960, 40)
        ac.glEnd()
コード例 #14
0
def drawSpeedometer():
	speed = ac.getCarState(0,acsys.CS.DriveTrainSpeed)/dt_ratio #Drivetrain speed seems to be about 75-90% of the real speed wtf
	if imperial:
		speed = speed / 1.632
	# degree range: 190..-10
	r = abs(speedo_min_angle - speedo_max_angle)
	speed_deg = speedo_max_angle - (speed/indicated_max_speed)*r
	speed_rad = math.radians(speed_deg)
	for i in range(0,indicated_max_speed+1,5):
		if i % 20 == 0:
			rad  = math.radians(speedo_max_angle - (i/indicated_max_speed)*r)
			p1_x = math.cos(rad)*speedo_radius+speed_pivot_x
			p1_y = -math.sin(rad)*speedo_radius+speed_pivot_y
			p2_x = math.cos(rad)*(speedo_radius*4/5)+speed_pivot_x
			p2_y = -math.sin(rad)*(speedo_radius*4/5)+speed_pivot_y
			ac.glBegin(0)
			ac.glColor4f(speedo_bigline_color[0],speedo_bigline_color[1],speedo_bigline_color[2],speedo_bigline_color[3])
			ac.glVertex2f(p1_x,p1_y)
			ac.glVertex2f(p2_x,p2_y)
			ac.glEnd()
		elif i % 5 == 0 and i != 0:
			rad  = math.radians(speedo_max_angle - (i/indicated_max_speed)*r)
			p1_x = math.cos(rad)*speedo_radius+speed_pivot_x
			p1_y = -math.sin(rad)*speedo_radius+speed_pivot_y
			p2_x = math.cos(rad)*(speedo_radius*9.25/10)+speed_pivot_x
			p2_y = -math.sin(rad)*(speedo_radius*9.25/10)+speed_pivot_y
			ac.glBegin(0)
			ac.glColor4f(speedo_smallline_color[0],speedo_smallline_color[1],speedo_smallline_color[2],speedo_smallline_color[3])
			ac.glVertex2f(p1_x,p1_y)
			ac.glVertex2f(p2_x,p2_y)
			ac.glEnd()
	# Needle
	speed_x       = math.cos(speed_rad)*(speedo_radius-3)+speed_pivot_x
	speed_y       = -math.sin(speed_rad)*(speedo_radius-3)+speed_pivot_y
	speed_end_x   = math.cos(speed_rad+math.pi)*speedo_needle_end+speed_pivot_x
	speed_end_y   = -math.sin(speed_rad+math.pi)*speedo_needle_end+speed_pivot_y
	
	speed_p1_x     = speed_x + math.cos(speed_rad-math.pi/2)*1.5
	speed_p1_y     = speed_y - math.sin(speed_rad-math.pi/2)*1.5
	speed_p2_x     = speed_x + math.cos(speed_rad+math.pi/2)*1.5
	speed_p2_y     = speed_y - math.sin(speed_rad+math.pi/2)*1.5
	speed_end_p1_x = speed_end_x + math.cos(speed_rad+math.pi/2)*3
	speed_end_p1_y = speed_end_y - math.sin(speed_rad+math.pi/2)*3
	speed_end_p2_x = speed_end_x + math.cos(speed_rad-math.pi/2)*3
	speed_end_p2_y = speed_end_y - math.sin(speed_rad-math.pi/2)*3
	ac.glBegin(2)
	ac.glColor4f(speedo_needle_color1[0],speedo_needle_color1[1],speedo_needle_color1[2],speedo_needle_color1[3])
	ac.glVertex2f(speed_p1_x,speed_p1_y)
	ac.glVertex2f(speed_end_p1_x,speed_end_p1_y)
	ac.glVertex2f(speed_end_p2_x,speed_end_p2_y)
	ac.glEnd()
	ac.glBegin(2)
	ac.glColor4f(speedo_needle_color1[0],speedo_needle_color1[1],speedo_needle_color1[2],speedo_needle_color1[3])
	ac.glVertex2f(speed_p1_x,speed_p1_y)
	ac.glVertex2f(speed_end_p2_x,speed_end_p2_y)
	ac.glVertex2f(speed_p2_x,speed_p2_y)
	ac.glEnd()
コード例 #15
0
ファイル: AccAnalogSpeedometer.py プロジェクト: acclub/apps
def drawNeedle(delta_t):
    speed = ac.getCarState(0, acsys.CS.SpeedKMH)
    if limited and speed > speedMaximum: speed = speedMaximum
    radValue = speed / speedMaximum * radRange + radStartingPoint

    dx = math.sin(radValue)
    dy = math.cos(radValue)
    tx = halfWidth - dx * halfWidth
    ty = halfHeight + dy * halfHeight
    ax = dx * halfArrowWidth
    ay = dy * halfArrowWidth

    ac.glColor4f(1.0, 0.2, 0.2, 0.8) # color
    ac.glBegin(acsys.GL.Quads)
    ac.glVertex2f(halfWidth + ay, halfHeight + ax)
    ac.glVertex2f(halfWidth - ay, halfHeight - ax)
    ac.glVertex2f(tx - ay, ty - ax)
    ac.glVertex2f(tx + ay, ty + ax)
    ac.glEnd()
コード例 #16
0
def onWindowRender(deltaT):
	ac.log("Rendering window")
	global debug_label, indicated_max_rpm, max_rpm, indicated_max_speed, shift_light_drawn, sl_timer
	global tach_radius, rpm_pivot_x, rpm_pivot_y, speedo_radius, speed_pivot_x, speed_pivot_y
	global speedo_tl_x, speedo_tl_y, speedo_total_width, speedo_total_height, gear_color, gear_background, speedo_color, speedo_background
	global abs_label, abs_off_label, tcs_label, tcs_off_label
	global draw_abs_status, draw_tcs_status
	global telemetry_client
	if draw_abs_status:
		if telemetry_client.abs_enabled:
			ac.setPosition(abs_off_label,-10000,-10000)
		else:
			ac.setPosition(abs_off_label,0,0)
		if telemetry_client.abs_in_action:
			ac.setPosition(abs_label,0,0)
		else:
			ac.setPosition(abs_label,-10000,-10000)
	if draw_tcs_status:
		if telemetry_client.tc_enabled:
			ac.setPosition(tcs_off_label,-10000,-10000)
		else:
			ac.setPosition(tcs_off_label,0,0)
		if telemetry_client.tc_in_action:
			ac.setPosition(tcs_label,0,0)
		else:
			ac.setPosition(tcs_label,-10000,-10000)
	rpm = ac.getCarState(0,acsys.CS.RPM)
	# Distance covered
	if draw_odometer:
		drawOdometer()
	# Tach
	if draw_tachometer:
		drawTachometer(deltaT)
	# Speedo
	if draw_speedometer:
		drawSpeedometer()
	# Shift light
	if draw_shift_light:
		sl_center_x = shift_light_x
		sl_center_y = shift_light_y
		sl_radius   = shift_light_radius
		if sl_timer > 0.1:
			shift_light_drawn = not shift_light_drawn
			sl_timer = 0
		else:
			sl_timer = sl_timer + deltaT
		if max_rpm - rpm <= 500 and shift_light_drawn:
			color = shift_light_on_color
		else:
			color = shift_light_off_color
		for i in range(0,360,15):
			ac.glBegin(2)
			ac.glColor4f(color[0],color[1],color[2],color[3])
			ac.glVertex2f(sl_center_x + math.cos(math.radians(i+15))*sl_radius,sl_center_y + math.sin(math.radians(i+15))*sl_radius)
			ac.glVertex2f(sl_center_x + math.cos(math.radians(i))*sl_radius,sl_center_y + math.sin(math.radians(i))*sl_radius)
			ac.glVertex2f(sl_center_x,sl_center_y)
			ac.glEnd()
	# Gear
	if draw_gear_indicator:
		gear = ac.getCarState(0,acsys.CS.Gear)
		digit = ''
		if gear > 1:
			digit = "%d" % (gear - 1)
		elif gear == 1:
			digit = "N"
		elif gear == 0:
			digit = "R"
		drawNineSegment(gear_x,gear_y,gear_width,gear_height,digit,gear_color,gear_background)
	# Digital speedo
	if draw_digital_speedo:
		# First Digit
		hundred = ''
		speed = ac.getCarState(0,acsys.CS.SpeedKMH) # Actual speed instead of drivetrain speed
		if imperial:
			speed = ac.getCarState(0,acsys.CS.SpeedMPH)
		if speed >= 100:
			hundred = "%d" % ((speed - (speed % 100))/100)
		drawNineSegment(speedo_tl_x,speedo_tl_y,speedo_total_width/3,speedo_total_height,hundred,speed_color,speed_background)
		# Second Digit
		ten = ''
		if speed >= 10:
			ten = "%d" % (((speed % 100) - (speed % 10))/10)
		drawNineSegment(speedo_tl_x+speedo_total_width/3,speedo_tl_y,speedo_total_width/3,speedo_total_height,ten,speed_color,speed_background)
		# Third Digit
		dec = "%d" % (speed % 10)
		drawNineSegment(speedo_tl_x+2*(speedo_total_width/3),speedo_tl_y,speedo_total_width/3,speedo_total_height,dec,speed_color,speed_background)
	
	# Brake Gauge
	if draw_brake_gauge:
		drawBrakeGauge()
	# Throttle Gauge
	if draw_throttle_gauge:
		drawThrottleGauge()
	# Clutch Gauge
	if draw_clutch_gauge:
		drawClutchGauge()
	# G Meter
	if draw_g_meter:
		drawGMeter()
	# Tyre Monitor
	if draw_tyre_monitor:
		drawTyreMonitor()
	# BOOOOOST
	if draw_boost_gauge:
		drawBoostGauge()
	# Fuel
	if draw_fuel_gauge:
		drawFuelGauge()
コード例 #17
0
def drawBoostGauge():
	global max_boost
	boost = ac.getCarState(0,acsys.CS.TurboBoost)
	if boost > max_boost:
		max_boost = boost
	rad = (boost/max_boost)*math.pi # 180 deg range so it's easy
	outer_radius = boost_radius
	inner_radius = outer_radius - 4
	for i in range(0,int((boost/max_boost)*100),1):
		# p3 p4 - rad2
		# p1 p2 - rad1
		rad1 = math.pi - math.pi*(i/100)
		rad2 = math.pi - math.pi*((i+1)/100)
		
		p1_x = math.cos(rad1)*outer_radius + boost_pivot_x
		p1_y = boost_pivot_y - math.sin(rad1)*outer_radius
		p2_x = math.cos(rad1)*inner_radius + boost_pivot_x
		p2_y = boost_pivot_y - math.sin(rad1)*inner_radius
		p3_x = math.cos(rad2)*outer_radius + boost_pivot_x
		p3_y = boost_pivot_y - math.sin(rad2)*outer_radius
		p4_x = math.cos(rad2)*inner_radius + boost_pivot_x
		p4_y = boost_pivot_y - math.sin(rad2)*inner_radius
		
		ac.glBegin(2)
		ac.glColor4f(boost_bar_color[0],boost_bar_color[1],boost_bar_color[2],boost_bar_color[3])
		ac.glVertex2f(p1_x,p1_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p3_x,p3_y)
		ac.glEnd()
		ac.glBegin(2)
		ac.glColor4f(boost_bar_color[0],boost_bar_color[1],boost_bar_color[2],boost_bar_color[3])
		ac.glVertex2f(p3_x,p3_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p4_x,p4_y)
		ac.glEnd()
	# Needle
	rad = math.pi - rad
	bigend_x    = math.cos(rad)*boost_radius + boost_pivot_x
	bigend_y    = boost_pivot_y - math.sin(rad)*boost_radius
	littleend_x = math.cos(rad+math.pi)*boost_needle_end + boost_pivot_x
	littleend_y = boost_pivot_y - math.sin(rad+math.pi)*boost_needle_end
	# p1 p2 = big end
	# p3 p4 = little end
	p1_x = math.cos(rad+math.pi/2) + bigend_x
	p1_y = bigend_y - math.sin(rad+math.pi/2)
	p2_x = math.cos(rad-math.pi/2) + bigend_x
	p2_y = bigend_y - math.sin(rad-math.pi/2)
	p3_x = math.cos(rad+math.pi/2) + littleend_x
	p3_y = littleend_y - math.sin(rad+math.pi/2)
	p4_x = math.cos(rad-math.pi/2) + littleend_x
	p4_y = littleend_y - math.sin(rad-math.pi/2)
	
	ac.glBegin(2)
	ac.glColor4f(boost_needle_color[0],boost_needle_color[1],boost_needle_color[2],boost_needle_color[3])
	ac.glVertex2f(p1_x,p1_y)
	ac.glVertex2f(p3_x,p3_y)
	ac.glVertex2f(p4_x,p4_y)
	ac.glEnd()
	ac.glBegin(2)
	ac.glColor4f(boost_needle_color[0],boost_needle_color[1],boost_needle_color[2],boost_needle_color[3])
	ac.glVertex2f(p1_x,p1_y)
	ac.glVertex2f(p4_x,p4_y)
	ac.glVertex2f(p2_x,p2_y)
	ac.glEnd()
コード例 #18
0
def drawFuelGauge():
	global max_fuel, fuel_warning_label
	fuel = sim_info.physics.fuel
	rad = (fuel/max_fuel)*math.pi # 180 deg range so it's easy
	outer_radius = fuel_radius 
	inner_radius = outer_radius - 4
	if fuel/max_fuel > 0.125:
		ac.setPosition(fuel_warning_label,-10000,0)
	else:
		ac.setPosition(fuel_warning_label,fuel_pivot_x - 6,fuel_pivot_y - 30)
	for i in range(0,int((fuel/max_fuel)*100),1):
		# p3 p4 - rad2
		# p1 p2 - rad1
		rad1 = math.pi - math.pi*(i/100)
		rad2 = math.pi - math.pi*((i+1)/100)
		
		p1_x = math.cos(rad1)*outer_radius + fuel_pivot_x
		p1_y = fuel_pivot_y - math.sin(rad1)*outer_radius
		p2_x = math.cos(rad1)*inner_radius + fuel_pivot_x
		p2_y = fuel_pivot_y - math.sin(rad1)*inner_radius
		p3_x = math.cos(rad2)*outer_radius + fuel_pivot_x
		p3_y = fuel_pivot_y - math.sin(rad2)*outer_radius
		p4_x = math.cos(rad2)*inner_radius + fuel_pivot_x
		p4_y = fuel_pivot_y - math.sin(rad2)*inner_radius
		
		ac.glBegin(2)
		ac.glColor4f(fuel_bar_color[0],fuel_bar_color[1],fuel_bar_color[2],fuel_bar_color[3])
		ac.glVertex2f(p1_x,p1_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p3_x,p3_y)
		ac.glEnd()
		ac.glBegin(2)
		ac.glColor4f(fuel_bar_color[0],fuel_bar_color[1],fuel_bar_color[2],fuel_bar_color[3])
		ac.glVertex2f(p3_x,p3_y)
		ac.glVertex2f(p2_x,p2_y)
		ac.glVertex2f(p4_x,p4_y)
		ac.glEnd()
	# Needle
	rad = math.pi - rad
	bigend_x    = math.cos(rad)*fuel_radius + fuel_pivot_x
	bigend_y    = fuel_pivot_y - math.sin(rad)*fuel_radius
	littleend_x = math.cos(rad+math.pi)*fuel_needle_end + fuel_pivot_x
	littleend_y = fuel_pivot_y - math.sin(rad+math.pi)*fuel_needle_end
	# p1 p2 = big end
	# p3 p4 = little end
	p1_x = math.cos(rad+math.pi/2) + bigend_x
	p1_y = bigend_y - math.sin(rad+math.pi/2)
	p2_x = math.cos(rad-math.pi/2) + bigend_x
	p2_y = bigend_y - math.sin(rad-math.pi/2)
	p3_x = math.cos(rad+math.pi/2) + littleend_x
	p3_y = littleend_y - math.sin(rad+math.pi/2)
	p4_x = math.cos(rad-math.pi/2) + littleend_x
	p4_y = littleend_y - math.sin(rad-math.pi/2)
	
	ac.glBegin(2)
	ac.glColor4f(fuel_needle_color[0],fuel_needle_color[1],fuel_needle_color[2],fuel_needle_color[3])
	ac.glVertex2f(p1_x,p1_y)
	ac.glVertex2f(p3_x,p3_y)
	ac.glVertex2f(p4_x,p4_y)
	ac.glEnd()
	ac.glBegin(2)
	ac.glColor4f(fuel_needle_color[0],fuel_needle_color[1],fuel_needle_color[2],fuel_needle_color[3])
	ac.glVertex2f(p1_x,p1_y)
	ac.glVertex2f(p4_x,p4_y)
	ac.glVertex2f(p2_x,p2_y)
	ac.glEnd()
コード例 #19
0
def drawTachometer(deltaT):
	rpm = ac.getCarState(0,acsys.CS.RPM)
	# degree range: 190..-10
	r = abs(tach_min_angle - tach_max_angle)
	rpm_deg = tach_max_angle - (rpm/indicated_max_rpm)*r
	rpm_rad = math.radians(rpm_deg)
	# Redline
	redline_start = (max_rpm - 500) - (max_rpm % 250)
	for i in range(0,indicated_max_rpm+1,250):
		if i >= redline_start and i+250 <= indicated_max_rpm:
			rad1 = math.radians(tach_max_angle - (i/indicated_max_rpm)*r)
			rad2 = math.radians(tach_max_angle - ((i+250)/indicated_max_rpm)*r)
			p1_x = math.cos(rad1)*tach_radius+rpm_pivot_x
			p1_y = -math.sin(rad1)*tach_radius+rpm_pivot_y
			p2_x = math.cos(rad1)*(tach_radius*9/10)+rpm_pivot_x
			p2_y = -math.sin(rad1)*(tach_radius*9/10)+rpm_pivot_y
			p3_x = math.cos(rad2)*tach_radius+rpm_pivot_x
			p3_y = -math.sin(rad2)*tach_radius+rpm_pivot_y
			p4_x = math.cos(rad2)*(tach_radius*9/10)+rpm_pivot_x
			p4_y = -math.sin(rad2)*(tach_radius*9/10)+rpm_pivot_y
			ac.glBegin(2)
			ac.glColor4f(tach_redline_color[0],tach_redline_color[1],tach_redline_color[2],tach_redline_color[3])
			ac.glVertex2f(p1_x,p1_y)
			ac.glVertex2f(p2_x,p2_y)
			ac.glVertex2f(p3_x,p3_y)
			ac.glEnd()
			ac.glBegin(2)
			ac.glColor4f(tach_redline_color[0],tach_redline_color[1],tach_redline_color[2],tach_redline_color[3])
			#ac.glColor4f(1,1,1,1)
			ac.glVertex2f(p3_x,p3_y)
			ac.glVertex2f(p2_x,p2_y)
			ac.glVertex2f(p4_x,p4_y)
			ac.glEnd()
		if i % 1000 == 0:
			rad  = math.radians(tach_max_angle - (i/indicated_max_rpm)*r)
			p1_x = math.cos(rad)*tach_radius+rpm_pivot_x
			p1_y = -math.sin(rad)*tach_radius+rpm_pivot_y
			p2_x = math.cos(rad)*(tach_radius*4/5)+rpm_pivot_x
			p2_y = -math.sin(rad)*(tach_radius*4/5)+rpm_pivot_y
			ac.glBegin(0)
			ac.glColor4f(tach_bigline_color[0],tach_bigline_color[1],tach_bigline_color[2],tach_bigline_color[3])
			ac.glVertex2f(p1_x,p1_y)
			ac.glVertex2f(p2_x,p2_y)
			ac.glEnd()
		elif i % 250 == 0 and i != 0:
			rad  = math.radians(tach_max_angle - (i/indicated_max_rpm)*r)
			p1_x = math.cos(rad)*tach_radius+rpm_pivot_x
			p1_y = -math.sin(rad)*tach_radius+rpm_pivot_y
			p2_x = math.cos(rad)*(tach_radius*9.25/10)+rpm_pivot_x
			p2_y = -math.sin(rad)*(tach_radius*9.25/10)+rpm_pivot_y
			ac.glBegin(0)
			ac.glColor4f(tach_smallline_color[0],tach_smallline_color[1],tach_smallline_color[2],tach_smallline_color[3])
			ac.glVertex2f(p1_x,p1_y)
			ac.glVertex2f(p2_x,p2_y)
			ac.glEnd()
	# Needle
	rpm_x       = math.cos(rpm_rad)*(tach_radius-3)+rpm_pivot_x
	rpm_y       = -math.sin(rpm_rad)*(tach_radius-3)+rpm_pivot_y
	rpm_end_x   = math.cos(rpm_rad+math.pi)*tach_needle_end+rpm_pivot_x
	rpm_end_y   = -math.sin(rpm_rad+math.pi)*tach_needle_end+rpm_pivot_y
	
	rpm_p1_x     = rpm_x + math.cos(rpm_rad-math.pi/2)*1.5
	rpm_p1_y     = rpm_y - math.sin(rpm_rad-math.pi/2)*1.5
	rpm_p2_x     = rpm_x + math.cos(rpm_rad+math.pi/2)*1.5
	rpm_p2_y     = rpm_y - math.sin(rpm_rad+math.pi/2)*1.5
	rpm_end_p1_x = rpm_end_x + math.cos(rpm_rad-math.pi/2)*3
	rpm_end_p1_y = rpm_end_y - math.sin(rpm_rad-math.pi/2)*3
	rpm_end_p2_x = rpm_end_x + math.cos(rpm_rad+math.pi/2)*3
	rpm_end_p2_y = rpm_end_y - math.sin(rpm_rad+math.pi/2)*3
	ac.glBegin(2)
	ac.glColor4f(tach_needle_color1[0],tach_needle_color1[1],tach_needle_color1[2],tach_needle_color1[3])
	ac.glVertex2f(rpm_p1_x,rpm_p1_y)
	ac.glVertex2f(rpm_p2_x,rpm_p2_y)
	ac.glVertex2f(rpm_end_p1_x,rpm_end_p1_y)
	ac.glEnd()
	ac.glBegin(2)
	ac.glColor4f(tach_needle_color1[0],tach_needle_color1[1],tach_needle_color1[2],tach_needle_color1[3])
	#ac.glColor4f(1,1,1,1)
	ac.glVertex2f(rpm_p2_x,rpm_p2_y)
	ac.glVertex2f(rpm_end_p2_x,rpm_end_p2_y)
	ac.glVertex2f(rpm_end_p1_x,rpm_end_p1_y)
	ac.glEnd()
コード例 #20
0
def drawNineSegment(x,y,x_size,y_size,digit,colors,background):
	# Background
	ac.glBegin(2)
	ac.glColor4f(background[0],background[1],background[2],background[3])
	ac.glVertex2f(x,y)
	ac.glVertex2f(x+x_size,y+y_size)
	ac.glVertex2f(x+x_size,y)
	ac.glEnd()
	ac.glBegin(2)
	ac.glColor4f(background[0],background[1],background[2],background[3])
	#ac.glColor4f(1,1,1,1)
	ac.glVertex2f(x,y+y_size)
	ac.glVertex2f(x+x_size,y+y_size)
	ac.glVertex2f(x,y)
	ac.glEnd()
	# 2px padding
	root_x = x + 2
	root_y = y + 2
	max_x  = x + x_size - 2
	max_y  = y + y_size - 2
	# Definitions (DIFFERENT FOR SEGMENTS 8 AND 9)
	segment_width  = (max_y - root_y)/9
	segment_height = (max_x - root_x)/6
	
	i = 1
	segment_dict = {
		'1' : [ False, True, True, False, False, False, False, False, False],
		'2' : [ True, True, False, True, True, False, True, False, False],
		'3' : [ True, True, True, True, False, False, True, False, False],
		'4' : [ False, True, True, False, False, True, True, False, False],
		'5' : [ True, False, True, True, False, True, True, False, False],
		'6' : [ True, False, True, True, True, True, True, False, False],
		'7' : [ True, True, True, False, False, True, False, False, False],
		'8' : [ True, True, True, True, True, True, True, False, False],
		'9' : [ True, True, True, True, False, True, True, False, False],
		'0' : [ True, True, True, True, True, True, False, False, False],
		'N' : [ False, True, True, False, True, True, False, True, True],
		'R' : [ True, True, False, False, True, True, True, False, True],
		''  : [ False, False, False, False, False, False, False, False, False]}
	segments = segment_dict.get(digit,[True, True, True, True, True, True, True, True, True])
	for segment in segments:
		if segment:
			if i == 1 or i == 4 or i == 7: # horizontal segments
				l_x = segment_height + 1
				t_y = 0
				if i == 1:
					t_y = 1
				elif i == 7:
					t_y = segment_width*4 + 1
				elif i == 4:
					t_y = segment_width*8 + 1
				r_x = l_x + segment_height*4 - 2
				b_y = t_y + segment_width - 2
				# left/right triangle vertexes
				lt_x = l_x - segment_height/2 + 1
				tr_y = t_y + segment_width/2  - 1
				rt_x = r_x + segment_height/2 - 1
				# Adding the base coords
				l_x  = l_x + root_x
				r_x  = r_x + root_x
				t_y  = t_y + root_y
				b_y  = b_y + root_y
				lt_x = lt_x + root_x
				rt_x = rt_x + root_x
				tr_y = tr_y + root_y
				# Drawing the triangles
				# Left
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(lt_x,tr_y)
				ac.glVertex2f(l_x,b_y)
				ac.glVertex2f(l_x,t_y)
				ac.glEnd()
				# Right
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(rt_x,tr_y)
				ac.glVertex2f(r_x,t_y)
				ac.glVertex2f(r_x,b_y)
				ac.glEnd()
				# Middle top lt lb rt
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(l_x,t_y)
				ac.glVertex2f(l_x,b_y)
				ac.glVertex2f(r_x,t_y)
				ac.glEnd()
				# Middle bottom lb rt rb
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(l_x,b_y)
				ac.glVertex2f(r_x,b_y)
				ac.glVertex2f(r_x,t_y)
				ac.glEnd()
			elif i == 2 or i == 3 or i == 5 or i == 6:
				# (2 and 3) and (5 and 6) have same X coords
				# (2 and 6) and (3 and 5) have same Y coords
				l_x = r_x = t_y = b_y = tr_x = tt_y = bt_y = 0
				# X coords
				if i == 2 or i == 3:
					l_x  = segment_height*5 + 1
					r_x  = l_x + segment_height - 2
					tr_x = segment_height*5 + (segment_height - 2)/2 + 1
				elif i == 5 or i == 6:
					l_x  = 1
					r_x  = l_x + segment_height - 2
					tr_x = (segment_height - 2)/2 + 1
				# Y coords
				if i == 2 or i == 6:
					t_y  = segment_width + 1
					b_y  = segment_width*4 - 1
					tt_y = t_y - (segment_width - 2)/2 + 1
					bt_y = b_y + (segment_width - 2)/2 - 1
				elif i == 3 or i == 5:
					t_y  = segment_width*5 + 1
					b_y  = segment_width*8 - 1
					tt_y = t_y - (segment_width - 2)/2 + 1
					bt_y = b_y + (segment_width - 2)/2 - 1
				# Adding the base coords
				l_x  = l_x  + root_x
				r_x  = r_x  + root_x
				t_y  = t_y  + root_y
				b_y  = b_y  + root_y
				tr_x = tr_x + root_x
				tt_y = tt_y + root_y
				bt_y = bt_y + root_y
				# Drawing the triangles
				# Top
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(tr_x,tt_y)
				ac.glVertex2f(l_x,t_y)
				ac.glVertex2f(r_x,t_y)
				ac.glEnd()
				# Bottom
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(l_x,b_y)
				ac.glVertex2f(tr_x,bt_y)
				ac.glVertex2f(r_x,b_y)
				ac.glEnd()
				# Middle top lt lb rt
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(l_x,t_y)
				ac.glVertex2f(l_x,b_y)
				ac.glVertex2f(r_x,t_y)
				ac.glEnd()
				# Middle bottom lb rt rb
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(l_x,b_y)
				ac.glVertex2f(r_x,b_y)
				ac.glVertex2f(r_x,t_y)
				ac.glEnd()
			elif i == 8: # Top diagonal
				t1_x  = segment_height + segment_width/4
				t2_x  = segment_height
				t1_y = segment_width
				t2_y = t1_y + segment_width/4
				b1_x = segment_height*3
				b2_x = b1_x - segment_width/2
				b_y  = segment_width*4
				# Adding the base
				t1_x = t1_x + root_x
				t2_x = t2_x + root_x
				t1_y = t1_y + root_y
				t2_y = t2_y + root_y
				b1_x = b1_x + root_x
				b2_x = b2_x + root_x
				b_y  = b_y  + root_y
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(t1_x,t1_y)
				ac.glVertex2f(t2_x,t2_y)
				ac.glVertex2f(b1_x,b_y)
				ac.glEnd()
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(b2_x,b_y)
				ac.glVertex2f(b1_x,b_y)
				ac.glVertex2f(t2_x,t2_y)
				ac.glEnd()
			elif i == 9: # Bottom diagonal
				t_x  = segment_height*5
				t1_y = segment_width*8 - segment_width/2
				t2_y = t1_y + segment_width/2
				b1_x = segment_height*3 + segment_width/2
				b2_x = b1_x - segment_width/2
				b_y  = segment_width*5
				# Adding the base
				t_x  = t_x  + root_x
				t1_y = t1_y + root_y
				t2_y = t2_y + root_y
				b1_x = b1_x + root_x
				b2_x = b2_x + root_x
				b_y  = b_y  + root_y
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				ac.glVertex2f(t_x,t2_y)
				ac.glVertex2f(t_x,t1_y)
				ac.glVertex2f(b1_x,b_y)
				ac.glEnd()
				ac.glBegin(2)
				ac.glColor4f(colors[0],colors[1],colors[2],colors[3])
				#ac.glColor4f(1,1,1,1)
				ac.glVertex2f(b1_x,b_y)
				ac.glVertex2f(b2_x,b_y)
				ac.glVertex2f(t_x,t2_y)
				ac.glEnd()
		i = i + 1