예제 #1
0
 public DirectionGoal(Triple firstNodePosition, Triple secondNodePosition, Triple targetDirection, float weight = 1f)
 {
     TargetDirection   = targetDirection.Normalise();
     Weight            = weight;
     StartingPositions = new[] { firstNodePosition, secondNodePosition };
     Moves             = new Triple[2];
 }
        public override void Compute(List <Node> allNodes)
        {
            int    lineCount       = NodeCount / 2;
            Triple targetDirection = Triple.Zero;

            for (int i = 0; i < lineCount; i++)
            {
                targetDirection += (allNodes[NodeIndices[2 * i + 1]].Position - allNodes[NodeIndices[2 * i]].Position).Normalise();
            }

            targetDirection =
                targetDirection.IsAlmostZero()
                    ? Triple.BasisX
                    : targetDirection.Normalise();


            for (int i = 0; i < lineCount; i++)
            {
                Triple v = allNodes[NodeIndices[2 * i + 1]].Position - allNodes[NodeIndices[2 * i]].Position;
                Moves[2 * i]     = 0.5f * (v - v.Dot(targetDirection) * targetDirection);
                Moves[2 * i + 1] = -Moves[2 * i];
            }
        }