Bug Fix
This commit is contained in:
71
Tests/Line2d.cs
Normal file
71
Tests/Line2d.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Line2d : Line2D
|
||||
{
|
||||
private TestScene Test { get; set; }
|
||||
public Vector2 Start => Test.A.Position;
|
||||
public Vector2 End => Test.B.Position;
|
||||
public float CurveRate { get; set; } = 20;
|
||||
public int CDir { get; set; } = 1;
|
||||
|
||||
private void MakeCurve(float curveRate=20f, int cDir = 1)
|
||||
{
|
||||
Vector2[] xs = new Vector2[17];
|
||||
int[] x2 = new[] { 4, 12 };
|
||||
int[] x3 = new[] { 2, 6, 10, 14};
|
||||
int[] x4 = new[] { 1, 3, 5, 7, 9, 11, 13, 15 };
|
||||
Vector2 vd = End - Start;
|
||||
Vector2 nor = vd.Rotated(Mathf.Pi / 2 * cDir);
|
||||
Vector2 center = vd / 2 + 4f * nor / curveRate;
|
||||
xs[0] = Start;
|
||||
xs[16] = End;
|
||||
xs[8] = center + xs[0];
|
||||
foreach (int i in x2)
|
||||
{
|
||||
Vector2 v = xs[i + 4] - xs[i - 4];
|
||||
Vector2 n = v.Rotated(Mathf.Pi / 2 * cDir);
|
||||
Vector2 w = v / 2 + 2f * n / curveRate;
|
||||
xs[i] = w + xs[i - 4];
|
||||
}
|
||||
|
||||
foreach (int i in x3)
|
||||
{
|
||||
Vector2 v = xs[i + 2] - xs[i - 2];
|
||||
Vector2 n = v.Rotated(Mathf.Pi / 2 * cDir);
|
||||
Vector2 w = v / 2 + n / curveRate;
|
||||
xs[i] = w + xs[i - 2];
|
||||
}
|
||||
|
||||
foreach (int i in x4)
|
||||
{
|
||||
Vector2 v = xs[i + 1] - xs[i - 1];
|
||||
Vector2 n = v.Rotated(Mathf.Pi / 2 * cDir);
|
||||
Vector2 w = v / 2 + n / curveRate;
|
||||
xs[i] = w + xs[i - 1];
|
||||
}
|
||||
|
||||
Points = xs;
|
||||
}
|
||||
|
||||
private void T()
|
||||
{
|
||||
Points = new[] { new Vector2(1, 1), new Vector2(2, 3) };
|
||||
GD.Print(Points.Length);
|
||||
}
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
Test = GetParent<TestScene>();
|
||||
|
||||
GD.Print("Ready");
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
//T();
|
||||
MakeCurve(CurveRate, CDir);
|
||||
}
|
||||
}
|
||||
12
Tests/Test2.cs
Normal file
12
Tests/Test2.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Godot;
|
||||
|
||||
public partial class Test2 : Node2D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
GD.Print("READY ddd");
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
37
Tests/TestScene.cs
Normal file
37
Tests/TestScene.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class TestScene : Node2D
|
||||
{
|
||||
public Marker2D A { get; set; }
|
||||
public Marker2D B { get; set; }
|
||||
|
||||
public Line2d L1 { get; set; }
|
||||
|
||||
public Line2d L2 { get; set; }
|
||||
public Line2d L3 { get; set; }
|
||||
public Line2d L4 { get; set; }
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
A = GetNode<Marker2D>("A");
|
||||
B = GetNode<Marker2D>("B");
|
||||
L1 = GetNode<Line2d>("L1");
|
||||
L2 = GetNode<Line2d>("L2");
|
||||
L3 = GetNode<Line2d>("L3");
|
||||
L4 = GetNode<Line2d>("L4");
|
||||
L1.CurveRate = 20;
|
||||
L1.CDir = 1;
|
||||
L2.CurveRate = 10;
|
||||
L1.CDir = 1;
|
||||
L3.CurveRate = 10;
|
||||
L3.CDir = -1;
|
||||
L4.CurveRate = 20;
|
||||
L4.CDir = -1;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user