Exemplo n.º 1
0
        // basic flocking
        public Vector3 SteerToFlock()
        {
            const float separationRadius = 5.0f;
            const float separationAngle  = -0.707f;
            const float separationWeight = 12.0f;

            const float alignmentRadius = 7.5f;
            const float alignmentAngle  = 0.7f;
            const float alignmentWeight = 8.0f;

            const float cohesionRadius = 9.0f;
            const float cohesionAngle  = -0.15f;
            const float cohesionWeight = 8.0f;

            float maxRadius = Math.Max(separationRadius, Math.Max(alignmentRadius, cohesionRadius));

            // find all flockmates within maxRadius using proximity database
            neighbors.Clear();
            proximityToken.FindNeighbors(Position, maxRadius, ref neighbors);

            // determine each of the three component behaviors of flocking
            Vector3 separation = SteerForSeparation(separationRadius, separationAngle, neighbors);
            Vector3 alignment  = SteerForAlignment(alignmentRadius, alignmentAngle, neighbors);
            Vector3 cohesion   = SteerForCohesion(cohesionRadius, cohesionAngle, neighbors);

            // apply weights to components (save in variables for annotation)
            Vector3 separationW = separation * separationWeight;
            Vector3 alignmentW  = alignment * alignmentWeight;
            Vector3 cohesionW   = cohesion * cohesionWeight;

            Vector3 avoidance = SteerToAvoidObstacles(Boid.AvoidancePredictTimeMin, AllObstacles);

            // saved for annotation
            bool    Avoiding = (avoidance != Vector3.Zero);
            Vector3 steer    = separationW + alignmentW + cohesionW;

            if (Avoiding)
            {
                steer = avoidance;
                System.Diagnostics.Debug.WriteLine(String.Format("Avoiding: [{0}, {1}, {2}]", avoidance.X, avoidance.Y, avoidance.Z));
            }
#if IGNORED
            // annotation
            const float s = 0.1f;
            AnnotationLine(Position, Position + (separationW * s), Color.Red);
            AnnotationLine(Position, Position + (alignmentW * s), Color.Orange);
            AnnotationLine(Position, Position + (cohesionW * s), Color.Yellow);
#endif
            return(steer);
        }
Exemplo n.º 2
0
        // basic flocking
        public Vector3 SteerToFlock()
        {
            const float separationRadius = 5.0f;
            const float separationAngle  = -0.707f;
            const float separationWeight = 12.0f;

            const float alignmentRadius = 7.5f;
            const float alignmentAngle  = 0.7f;
            const float alignmentWeight = 8.0f;

            const float cohesionRadius = 9.0f;
            const float cohesionAngle  = -0.15f;
            const float cohesionWeight = 8.0f;

            float maxRadius = Math.Max(separationRadius, Math.Max(alignmentRadius, cohesionRadius));

            // find all flockmates within maxRadius using proximity database
            neighbors.Clear();
            proximityToken.FindNeighbors(Position, maxRadius, ref neighbors);

            // determine each of the three component behaviors of flocking
            Vector3 separation = SteerForSeparation(separationRadius, separationAngle, neighbors);
            Vector3 alignment  = SteerForAlignment(alignmentRadius, alignmentAngle, neighbors);
            Vector3 cohesion   = SteerForCohesion(cohesionRadius, cohesionAngle, neighbors);

            // apply weights to components (save in variables for annotation)
            Vector3 separationW = separation * separationWeight;
            Vector3 alignmentW  = alignment * alignmentWeight;
            Vector3 cohesionW   = cohesion * cohesionWeight;

#if IGNORED
            // annotation
            const float s = 0.1f;
            AnnotationLine(Position, Position + (separationW * s), Color.Red);
            AnnotationLine(Position, Position + (alignmentW * s), Color.Orange);
            AnnotationLine(Position, Position + (cohesionW * s), Color.Yellow);
#endif
            return(separationW + alignmentW + cohesionW);
        }