Browse Source

TreeScene: allow for ideal vs actual orientation

main
Colin McMillen 3 years ago
parent
commit
0dbc6bdd8c
  1. 32
      Shared/TreeScene.cs

32
Shared/TreeScene.cs

@ -59,11 +59,17 @@ namespace SemiColinGames {
}
public class TreeNode {
public float Orientation; // relative to parent
public float Length;
public float InWidth;
public float OutWidth;
// Ideal orientation, relative to its parent.
public readonly float Orientation;
// Orientation in world space.
public float WorldOrientation;
public readonly float Length;
public readonly float InWidth;
public readonly float OutWidth;
public readonly List<TreeNode> Children;
// Position of in-vertex in world space.
public Vector2 Position;
public TreeNode(float orientation, float length, float inWidth, float outWidth) :
@ -84,6 +90,7 @@ namespace SemiColinGames {
public TreeNode(float orientation, float length, float inWidth, float outWidth, List<TreeNode> children) {
Orientation = orientation;
WorldOrientation = orientation;
Length = length;
InWidth = inWidth;
OutWidth = outWidth;
@ -94,8 +101,8 @@ namespace SemiColinGames {
public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) {
var tree =
new TreeNode(-0.2f, 100, 10, 6,
new TreeNode(-0.2f, 100, 10, 6,
new TreeNode(0.0f, 100, 10, 6,
new TreeNode(0.0f, 100, 10, 6,
new TreeNode(-0.2f, 100, 10, 6,
new TreeNode(-0.3f, 100, 6, 4,
new TreeNode(-0.1f, 100, 6, 4,
@ -113,12 +120,18 @@ namespace SemiColinGames {
LinkedList<TreeNode> queue = new LinkedList<TreeNode>();
queue.AddLast(tree);
Debug.WriteLine("---------------------");
while (queue.Count > 0) {
TreeNode parent = queue.First.Value;
queue.RemoveFirst();
Vector2 outVector = new Vector2(0, parent.Length).Rotate(parent.Orientation);
Vector2 outVector = new Vector2(0, parent.Length).Rotate(parent.WorldOrientation);
Vector2 outPosition = Vector2.Add(parent.Position, outVector);
outVector.Normalize();
Vector2 wind = new Vector2(1.0f, 0.0f);
float windAmount = Vector2.Dot(wind, outVector);
Debug.WriteLine("" + windAmount);
// We want a trapezoid with 4 points. A is the in position, B is the out position.
// The TreeNode.Length is the distance from A to B.
//
@ -139,13 +152,14 @@ namespace SemiColinGames {
t.p2 = new Vector2(parent.InWidth, 0);
t.p3 = new Vector2(-parent.OutWidth, parent.Length * sideLengthFudge);
t.p4 = new Vector2(parent.OutWidth, parent.Length * sideLengthFudge);
t.Rotate(parent.Orientation);
t.Rotate(parent.WorldOrientation);
t.Translate(parent.Position);
segments.Add(t);
foreach (TreeNode child in parent.Children) {
child.Position = outPosition;
child.Orientation += parent.Orientation;
float orientation = parent.WorldOrientation + child.Orientation;
child.WorldOrientation = orientation;
queue.AddLast(child);
}
}

Loading…
Cancel
Save