public void Execute(TreeCrayon crayon, Random rnd) { foreach (TreeCrayonInstruction instruction in instructions) { instruction.Execute(crayon, rnd); } }
public void Execute(TreeCrayon crayon, Random rnd) { Matrix transform = crayon.GetTransform(); Vector3 branchDir = transform.Up; Vector3 axis = Vector3.Up; float dot = Vector3.Dot(axis, branchDir); // If branch is almost perpendicular to alignment axis, // just do nothing if (Math.Abs(dot) > 0.999f) return; // project axis onto the crayon's XZ plane Vector3 axisXZ = axis - dot*branchDir; axisXZ.Normalize(); float cosAngle = Vector3.Dot(transform.Backward, axisXZ); // The dot product of two normalized vectors is always in range [-1,1], // but to account for rounding errors, we have to clamp it. // Otherwise, Acos will return NaN in some cases. cosAngle = MathHelper.Clamp(cosAngle, -1, 1); // calculate the angle between the old Z-axis and axisXZ // this is also the twist angle required to align the crayon var rotation = (float) Math.Acos(cosAngle); // finally, perform the twist crayon.Twist(rotation); }
public void Execute(TreeCrayon crayon, Random rnd) { Matrix transform = crayon.GetTransform(); Vector3 branchDir = transform.Up; Vector3 axis = Vector3.Up; float dot = Vector3.Dot(axis, branchDir); // If branch is almost perpendicular to alignment axis, // just do nothing if (Math.Abs(dot) > 0.999f) { return; } // project axis onto the crayon's XZ plane Vector3 axisXZ = axis - dot * branchDir; axisXZ.Normalize(); float cosAngle = Vector3.Dot(transform.Backward, axisXZ); // The dot product of two normalized vectors is always in range [-1,1], // but to account for rounding errors, we have to clamp it. // Otherwise, Acos will return NaN in some cases. cosAngle = MathHelper.Clamp(cosAngle, -1, 1); // calculate the angle between the old Z-axis and axisXZ // this is also the twist angle required to align the crayon float rotation = (float)Math.Acos(cosAngle); // finally, perform the twist crayon.Twist(rotation); }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.PushState(); foreach (TreeCrayonInstruction instruction in instructions) { instruction.Execute(crayon, rnd); } crayon.PopState(); }
public void Execute(TreeCrayon crayon, Random rnd) { if (crayon.Level >= Level && Type == CompareType.Greater || crayon.Level <= Level && Type == CompareType.Less) { foreach (TreeCrayonInstruction instruction in Instructions) { instruction.Execute(crayon, rnd); } } }
public void Execute(TreeCrayon crayon, Random rnd) { if (rnd.NextDouble() < chance) { foreach (TreeCrayonInstruction child in instructions) { child.Execute(crayon, rnd); } } }
public void Execute(TreeCrayon crayon, Random rnd) { if (crayon.Level == 0) { float rotation = 0.0f; if (crayon.Skeleton.LeafAxis == null) rotation = (float) rnd.NextDouble()*MathHelper.TwoPi; crayon.Leaf(rotation, size + sizeVariation*(2.0f*(float) rnd.NextDouble() - 1.0f), color + colorVariation*(2.0f*(float) rnd.NextDouble() - 1.0f), AxisOffset); } }
public void Execute(TreeCrayon crayon, Random rnd) { if (productions.Count == 0) throw new InvalidOperationException("No productions exist for call."); if (crayon.Level + deltaLevel < 0) return; crayon.Level = crayon.Level + deltaLevel; int i = rnd.Next(0, productions.Count); productions[i].Execute(crayon, rnd); crayon.Level = crayon.Level - deltaLevel; }
public void Execute(TreeCrayon crayon, Random rnd) { if (crayon.Level == 0) { float rotation = 0.0f; if (crayon.Skeleton.LeafAxis == null) { rotation = (float)rnd.NextDouble() * MathHelper.TwoPi; } crayon.Leaf(rotation, size + sizeVariation * (2.0f * (float)rnd.NextDouble() - 1.0f), color + colorVariation * (2.0f * (float)rnd.NextDouble() - 1.0f), AxisOffset); } }
public void Execute(TreeCrayon crayon, Random rnd) { if (productions.Count == 0) { throw new InvalidOperationException("No productions exist for call."); } if (crayon.Level + deltaLevel < 0) { return; } crayon.Level = crayon.Level + deltaLevel; int i = rnd.Next(0, productions.Count); productions[i].Execute(crayon, rnd); crayon.Level = crayon.Level - deltaLevel; }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Forward(distance + variation*((float) rnd.NextDouble()*2 - 1), radiusScale); }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Twist(Util.Random(rnd, angle, variation)); }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Scale(Util.Random(rnd, scale, variation)); }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Level = crayon.Level + deltaLevel; }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Bone(Delta); }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Backward(Util.Random(rnd, distance, distanceVariation)); }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Pitch(Util.Random(rnd, angle, variation)); }
public void Execute(TreeCrayon crayon, Random rnd) { crayon.Forward(distance + variation * ((float)rnd.NextDouble() * 2 - 1), radiusScale); }