TreeScene: allow for ideal vs actual orientation
This commit is contained in:
parent
7358bc0b24
commit
0dbc6bdd8c
@ -59,11 +59,17 @@ namespace SemiColinGames {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class TreeNode {
|
public class TreeNode {
|
||||||
public float Orientation; // relative to parent
|
// Ideal orientation, relative to its parent.
|
||||||
public float Length;
|
public readonly float Orientation;
|
||||||
public float InWidth;
|
// Orientation in world space.
|
||||||
public float OutWidth;
|
public float WorldOrientation;
|
||||||
|
|
||||||
|
public readonly float Length;
|
||||||
|
public readonly float InWidth;
|
||||||
|
public readonly float OutWidth;
|
||||||
public readonly List<TreeNode> Children;
|
public readonly List<TreeNode> Children;
|
||||||
|
|
||||||
|
// Position of in-vertex in world space.
|
||||||
public Vector2 Position;
|
public Vector2 Position;
|
||||||
|
|
||||||
public TreeNode(float orientation, float length, float inWidth, float outWidth) :
|
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) {
|
public TreeNode(float orientation, float length, float inWidth, float outWidth, List<TreeNode> children) {
|
||||||
Orientation = orientation;
|
Orientation = orientation;
|
||||||
|
WorldOrientation = orientation;
|
||||||
Length = length;
|
Length = length;
|
||||||
InWidth = inWidth;
|
InWidth = inWidth;
|
||||||
OutWidth = outWidth;
|
OutWidth = outWidth;
|
||||||
@ -94,8 +101,8 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) {
|
public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) {
|
||||||
var tree =
|
var tree =
|
||||||
new TreeNode(-0.2f, 100, 10, 6,
|
new TreeNode(0.0f, 100, 10, 6,
|
||||||
new TreeNode(-0.2f, 100, 10, 6,
|
new TreeNode(0.0f, 100, 10, 6,
|
||||||
new TreeNode(-0.2f, 100, 10, 6,
|
new TreeNode(-0.2f, 100, 10, 6,
|
||||||
new TreeNode(-0.3f, 100, 6, 4,
|
new TreeNode(-0.3f, 100, 6, 4,
|
||||||
new TreeNode(-0.1f, 100, 6, 4,
|
new TreeNode(-0.1f, 100, 6, 4,
|
||||||
@ -113,12 +120,18 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
LinkedList<TreeNode> queue = new LinkedList<TreeNode>();
|
LinkedList<TreeNode> queue = new LinkedList<TreeNode>();
|
||||||
queue.AddLast(tree);
|
queue.AddLast(tree);
|
||||||
|
Debug.WriteLine("---------------------");
|
||||||
while (queue.Count > 0) {
|
while (queue.Count > 0) {
|
||||||
TreeNode parent = queue.First.Value;
|
TreeNode parent = queue.First.Value;
|
||||||
queue.RemoveFirst();
|
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);
|
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.
|
// 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.
|
// The TreeNode.Length is the distance from A to B.
|
||||||
//
|
//
|
||||||
@ -139,13 +152,14 @@ namespace SemiColinGames {
|
|||||||
t.p2 = new Vector2(parent.InWidth, 0);
|
t.p2 = new Vector2(parent.InWidth, 0);
|
||||||
t.p3 = new Vector2(-parent.OutWidth, parent.Length * sideLengthFudge);
|
t.p3 = new Vector2(-parent.OutWidth, parent.Length * sideLengthFudge);
|
||||||
t.p4 = 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);
|
t.Translate(parent.Position);
|
||||||
|
|
||||||
segments.Add(t);
|
segments.Add(t);
|
||||||
foreach (TreeNode child in parent.Children) {
|
foreach (TreeNode child in parent.Children) {
|
||||||
child.Position = outPosition;
|
child.Position = outPosition;
|
||||||
child.Orientation += parent.Orientation;
|
float orientation = parent.WorldOrientation + child.Orientation;
|
||||||
|
child.WorldOrientation = orientation;
|
||||||
queue.AddLast(child);
|
queue.AddLast(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user