Exemplo n.º 1
0
        /// <summary>
        /// Moves forward while painting a branch here.
        /// </summary>
        /// <param name="length">Length of the new branch. The current scale will be applied to this.</param>
        /// <param name="radiusEndScale">How much smaller the ending radius should be. The equation is: StartRadius * RadiusEndScale = EndRadius.</param>
        /// <remarks>
        /// The crayon always moves along its local Y-axis, which is initially upwards.
        /// </remarks>
        public void Forward(float length, float radiusEndScale)
        {
            // Run the constraints
            if (constraints != null && !constraints.ConstrainForward(this, ref length, ref radiusEndScale))
            {
                return;
            }

            // Create the branch
            TreeBranch branch = new TreeBranch(
                state.Rotation,
                length * state.Scale,
                GetRadiusAt(state.ParentIndex, state.ParentPosition) * state.RadiusScale,
                GetRadiusAt(state.ParentIndex, state.ParentPosition) * state.RadiusScale * radiusEndScale,
                state.ParentIndex,
                state.ParentPosition);

            branch.BoneIndex = state.ParentBoneIndex;
            skeleton.Branches.Add(branch);
            branchTransforms.Add(GetTransform());

            // Set newest branch to parent
            state.ParentIndex = skeleton.Branches.Count - 1;

            // Rotation is relative to the current parent, so set to identity
            // to maintain original orientation
            state.Rotation = Quaternion.Identity;

            // Move to the end of the branch
            state.ParentPosition = 1.0f;

            // Move radius scale back to one, since the radius will now be relative to the new parent
            state.RadiusScale = 1.0f;
        }
Exemplo n.º 2
0
 public bool ConstrainForward(TreeCrayon crayon, ref float distance, ref float radiusEndScale)
 {
     foreach (TreeContraints c in constaints)
     {
         if (!c.ConstrainForward(crayon, ref distance, ref radiusEndScale))
         {
             return(false);
         }
     }
     if (userConstraint != null)
     {
         return(userConstraint.ConstrainForward(crayon, ref distance, ref radiusEndScale));
     }
     return(true);
 }