draw_polyline works on 3.1.2
This commit is contained in:
parent
5a4def27b0
commit
0fd8abf53b
2
Menu.gd
2
Menu.gd
|
@ -1,4 +1,4 @@
|
||||||
tool
|
#tool
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
var song_defs = {}
|
var song_defs = {}
|
||||||
|
|
77
Receptors.gd
77
Receptors.gd
|
@ -1,4 +1,4 @@
|
||||||
tool
|
#tool
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
var ring_px := 4
|
var ring_px := 4
|
||||||
|
@ -7,7 +7,7 @@ var shadow_px := 5
|
||||||
var shadow_color := Color.black
|
var shadow_color := Color.black
|
||||||
var center := Vector2(0.0, 0.0)
|
var center := Vector2(0.0, 0.0)
|
||||||
|
|
||||||
func make_ring_mesh(inner_vertices: int, thickness: float, radius: float, skew=0.5):
|
func make_ring_mesh(inner_vertices: int, thickness: float, radius: float, skew:=0.5, repeat_start:=true):
|
||||||
# This makes a trianglestrip around the ring, consisting of chords on the inside and tangents on the outside.
|
# This makes a trianglestrip around the ring, consisting of chords on the inside and tangents on the outside.
|
||||||
# The goal is to exchange some fragment and vertex processing load:
|
# The goal is to exchange some fragment and vertex processing load:
|
||||||
# - a full quad of the ring would be the maximum fragment load and minimum vertex load
|
# - a full quad of the ring would be the maximum fragment load and minimum vertex load
|
||||||
|
@ -30,16 +30,30 @@ func make_ring_mesh(inner_vertices: int, thickness: float, radius: float, skew=0
|
||||||
var r2 = (radius + thickness*0.5)/sin((PI-angle_increment)/2)
|
var r2 = (radius + thickness*0.5)/sin((PI-angle_increment)/2)
|
||||||
|
|
||||||
var vertex_list = PoolVector2Array()
|
var vertex_list = PoolVector2Array()
|
||||||
|
var inner_list = PoolVector2Array()
|
||||||
|
var outer_list = PoolVector2Array()
|
||||||
for i in inner_vertices:
|
for i in inner_vertices:
|
||||||
var angle_i = i * angle_increment
|
var angle_i = i * angle_increment
|
||||||
var angle_o = angle_i + angle_outer_offset
|
var angle_o = angle_i + angle_outer_offset
|
||||||
vertex_list.push_back(polar2cartesian(r1, angle_i))
|
vertex_list.push_back(polar2cartesian(r1, angle_i))
|
||||||
vertex_list.push_back(polar2cartesian(r2, angle_o))
|
vertex_list.push_back(polar2cartesian(r2, angle_o))
|
||||||
return vertex_list
|
inner_list.push_back(vertex_list[-2])
|
||||||
|
outer_list.push_back(vertex_list[-1])
|
||||||
|
if repeat_start:
|
||||||
|
vertex_list.push_back(vertex_list[0])
|
||||||
|
vertex_list.push_back(vertex_list[1])
|
||||||
|
inner_list.push_back(vertex_list[0])
|
||||||
|
outer_list.push_back(vertex_list[1])
|
||||||
|
return [vertex_list, inner_list, outer_list]
|
||||||
|
|
||||||
func triangle_area(a: Vector2, b: Vector2, c: Vector2) -> float:
|
func triangle_area(a: Vector2, b: Vector2, c: Vector2) -> float:
|
||||||
return 0.5 * abs((a.x-c.x)*(b.y-a.y) - (a.x-b.x)*(c.y-a.y))
|
return 0.5 * abs((a.x-c.x)*(b.y-a.y) - (a.x-b.x)*(c.y-a.y))
|
||||||
|
|
||||||
|
func inscribe_polygon_area(r: float, sides: int) -> float:
|
||||||
|
return 0.5 * sides * r * r * sin(TAU/sides)
|
||||||
|
func circumscribe_polygon_area(r: float, sides: int) -> float:
|
||||||
|
return sides * r * r * tan(PI/sides)
|
||||||
|
|
||||||
func arc_point_list(center: Vector2, radius: float, angle_from:=0.0, angle_to:=360.0, points:=90) -> PoolVector2Array:
|
func arc_point_list(center: Vector2, radius: float, angle_from:=0.0, angle_to:=360.0, points:=90) -> PoolVector2Array:
|
||||||
var point_list = PoolVector2Array()
|
var point_list = PoolVector2Array()
|
||||||
for i in range(points):
|
for i in range(points):
|
||||||
|
@ -48,38 +62,45 @@ func arc_point_list(center: Vector2, radius: float, angle_from:=0.0, angle_to:=3
|
||||||
point_list.push_back(center + polar2cartesian(radius, angle))
|
point_list.push_back(center + polar2cartesian(radius, angle))
|
||||||
return point_list
|
return point_list
|
||||||
|
|
||||||
func _draw():
|
func draw_old(circles:=true, shadows:=true): # Receptor ring
|
||||||
# Receptor ring
|
|
||||||
var receptor_circle := arc_point_list(center, GameTheme.receptor_ring_radius, 0.0, 360.0, 360)
|
var receptor_circle := arc_point_list(center, GameTheme.receptor_ring_radius, 0.0, 360.0, 360)
|
||||||
var receptor_centers := arc_point_list(center, GameTheme.receptor_ring_radius, Rules.FIRST_COLUMN_ANGLE_DEG, Rules.FIRST_COLUMN_ANGLE_DEG+360.0-Rules.COLS_ANGLE_DEG, Rules.COLS)
|
var receptor_centers := arc_point_list(center, GameTheme.receptor_ring_radius, Rules.FIRST_COLUMN_ANGLE_DEG, Rules.FIRST_COLUMN_ANGLE_DEG+360.0-Rules.COLS_ANGLE_DEG, Rules.COLS)
|
||||||
|
|
||||||
# # Shadows
|
if shadows:
|
||||||
# for i in range(len(receptor_circle)-1):
|
#draw_polyline(receptor_circle, shadow_color, ring_px + shadow_px, true)
|
||||||
# draw_line(receptor_circle[i], receptor_circle[i+1], shadow_color, ring_px + shadow_px, true)
|
draw_polyline(receptor_circle, Color.darkblue, ring_px + shadow_px, true)
|
||||||
## draw_line(receptor_circle[i], receptor_circle[i+1], shadow_color)
|
if circles:
|
||||||
# for i in range(len(receptor_centers)):
|
for i in range(len(receptor_centers)):
|
||||||
# draw_circle(receptor_centers[i], (receptor_px + shadow_px)/2, shadow_color)
|
# draw_circle(receptor_centers[i], (receptor_px + shadow_px)/2, shadow_color)
|
||||||
#
|
draw_circle(receptor_centers[i], (receptor_px + shadow_px)/2, Color.darkblue)
|
||||||
# # Foregrounds
|
|
||||||
for i in range(len(receptor_circle)-1):
|
draw_polyline(receptor_circle, GameTheme.receptor_color, ring_px, true)
|
||||||
draw_line(receptor_circle[i], receptor_circle[i+1], GameTheme.receptor_color, ring_px, true)
|
if circles:
|
||||||
# draw_line(receptor_circle[i], receptor_circle[i+1], GameTheme.receptor_color)
|
for i in range(len(receptor_centers)):
|
||||||
for i in range(len(receptor_centers)):
|
draw_circle(receptor_centers[i], receptor_px/2, GameTheme.receptor_color)
|
||||||
draw_circle(receptor_centers[i], receptor_px/2, GameTheme.receptor_color)
|
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
draw_old(true, true)
|
||||||
var mesh_v = $VerticesSlider.value
|
var mesh_v = $VerticesSlider.value
|
||||||
var skew = $SkewSlider.value
|
var skew = $SkewSlider.value
|
||||||
var dbg_color = Color.red
|
var dbg_color = Color.red
|
||||||
var ring_vertices = make_ring_mesh(mesh_v, receptor_px + shadow_px, GameTheme.receptor_ring_radius, skew)
|
var ring_thickness = receptor_px + shadow_px
|
||||||
var estimated_area = 0.0
|
var ring_vertices = make_ring_mesh(mesh_v, ring_thickness, GameTheme.receptor_ring_radius, skew)
|
||||||
|
var estimated_area = circumscribe_polygon_area(GameTheme.receptor_ring_radius+ring_thickness*0.5, mesh_v) - inscribe_polygon_area(GameTheme.receptor_ring_radius-ring_thickness*0.5, mesh_v)
|
||||||
var ideal_ring_area = PI * (pow(GameTheme.receptor_ring_radius+(receptor_px+shadow_px)/2, 2) - pow(GameTheme.receptor_ring_radius-(receptor_px+shadow_px)/2, 2))
|
var ideal_ring_area = PI * (pow(GameTheme.receptor_ring_radius+(receptor_px+shadow_px)/2, 2) - pow(GameTheme.receptor_ring_radius-(receptor_px+shadow_px)/2, 2))
|
||||||
var l = len(ring_vertices)
|
|
||||||
for i in l:
|
draw_polyline(ring_vertices[0], dbg_color)
|
||||||
draw_line(ring_vertices[i], ring_vertices[(i+1)%l], dbg_color)
|
draw_polyline(ring_vertices[1], dbg_color)
|
||||||
draw_line(ring_vertices[i], ring_vertices[(i+2)%l], dbg_color, 2.0)
|
draw_polyline(ring_vertices[2], dbg_color)
|
||||||
estimated_area += triangle_area(ring_vertices[i], ring_vertices[(i+1)%l], ring_vertices[(i+2)%l])
|
|
||||||
|
# var l = len(ring_vertices)
|
||||||
|
# for i in l:
|
||||||
|
## estimated_area += triangle_area(ring_vertices[i], ring_vertices[(i+1)%l], ring_vertices[(i+2)%l])
|
||||||
var quad_area = 4*pow(GameTheme.receptor_ring_radius+(receptor_px+shadow_px)/2, 2)
|
var quad_area = 4*pow(GameTheme.receptor_ring_radius+(receptor_px+shadow_px)/2, 2)
|
||||||
$"/root/main/InputHandler".text = "Vertices: %d*2 Skew: %.3f\nArea: %.0f\n(%.0f%% ideal ring)\n(%.0f%% quad)"%[mesh_v, skew, estimated_area, 100.0*estimated_area/ideal_ring_area, 100.0*estimated_area/quad_area]
|
var fps = Performance.get_monitor(Performance.TIME_FPS)
|
||||||
|
$"/root/main/InputHandler".text = "Vertices: %d*2 Skew: %.3f\nArea: %.0f\n(%.0f%% ideal ring)\n(%.0f%% quad)\nFPS: %.0f"%[mesh_v, skew, estimated_area, 100.0*estimated_area/ideal_ring_area, 100.0*estimated_area/quad_area, fps]
|
||||||
|
# ._draw()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
$"/root".connect("size_changed", self, "update")
|
$"/root".connect("size_changed", self, "update")
|
||||||
|
|
|
@ -62,7 +62,7 @@ __meta__ = {
|
||||||
[node name="ScreenFilter" type="Node2D" parent="."]
|
[node name="ScreenFilter" type="Node2D" parent="."]
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="Receptors" type="Node2D" parent="."]
|
[node name="Receptors" type="MeshInstance2D" parent="."]
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
[node name="SkewSlider" type="HSlider" parent="Receptors"]
|
[node name="SkewSlider" type="HSlider" parent="Receptors"]
|
||||||
|
@ -86,9 +86,8 @@ margin_right = 200.0
|
||||||
margin_bottom = -84.0
|
margin_bottom = -84.0
|
||||||
min_value = 3.0
|
min_value = 3.0
|
||||||
max_value = 72.0
|
max_value = 72.0
|
||||||
value = 8.0
|
value = 36.0
|
||||||
tick_count = 2
|
tick_count = 2
|
||||||
ticks_on_borders = false
|
|
||||||
|
|
||||||
[node name="NoteHandler" type="Node2D" parent="."]
|
[node name="NoteHandler" type="Node2D" parent="."]
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
|
@ -105,6 +104,7 @@ material = SubResource( 1 )
|
||||||
material = SubResource( 2 )
|
material = SubResource( 2 )
|
||||||
|
|
||||||
[node name="Menu" type="Node2D" parent="."]
|
[node name="Menu" type="Node2D" parent="."]
|
||||||
|
visible = false
|
||||||
script = ExtResource( 9 )
|
script = ExtResource( 9 )
|
||||||
|
|
||||||
[node name="ScoreText" type="Node2D" parent="Menu"]
|
[node name="ScoreText" type="Node2D" parent="Menu"]
|
||||||
|
|
Loading…
Reference in New Issue