private void scaledMap()
 {
     foreach (Vector3 target in targets)
     {
         Vector3 targetVector = MapOperations.VectorToTarget(my_position, target);
         float   distance     = targetVector.magnitude;
         if (distance < range)
         {
             Vector3 mapVector = InitialVector();
             for (int i = 0; i < Weights.Length; i++)
             {
                 Weights[i] += Vector3.Dot(mapVector, targetVector.normalized) * Mathf.Abs((invertScale * 1f) - (distance / range)) * weight;
                 mapVector   = MapOperations.RotateAroundAxis(axis, angle) * mapVector;
             }
         }
     }
 }
        private void standardMap()
        {
            sqrRange = range * range;

            foreach (Vector3 target in targets)
            {
                Vector3 targetVector = MapOperations.VectorToTarget(my_position, target);
                float   distance     = targetVector.sqrMagnitude;
                if (distance < sqrRange)
                {
                    Vector3 mapVector = InitialVector();
                    for (int i = 0; i < Weights.Length; i++)
                    {
                        Weights[i] += Vector3.Dot(mapVector, targetVector.normalized) * weight;

                        mapVector = MapOperations.RotateAroundAxis(axis, angle) * mapVector;
                    }
                }
            }
        }
        public Vector3 GetDirection(float[] contextMap)
        {
            float resolutionAngle = steeringParams.ResolutionAngle;

            float maxValue = 0f;
            int   maxIndex = 0;

            for (int i = 0; i < contextMap.Length; i++)
            {
                if (contextMap[i] > maxValue)
                {
                    maxValue = contextMap[i];
                    maxIndex = i;
                }
            }

            Vector3 direction = Vector3.forward * maxValue;

            if (maxValue == 0f)
            {
                return(lastVector); // Keep last direction if no better direction is found
            }

            Vector3 nextVector = MapOperations.RotateAroundAxis(steeringParams.ContextMapRotationAxis, resolutionAngle * maxIndex) * direction;
            float   dot        = Mathf.Clamp(Vector3.Dot(lastVector.normalized, nextVector.normalized), -1f, 1f);

            // next direction is within direction change
            if (dot > MinDot)
            {
                lastVector = nextVector;
                return(lastVector);
            }


            float desiredAngleRad = Mathf.Acos(MinDot);

            lastVector = Vector3.RotateTowards(lastVector, nextVector, desiredAngleRad, 1);
            return(lastVector);
        }
        public Vector3 GetDirection(float[] contextMap)
        {
            float resolutionAngle = steeringParams.ResolutionAngle;

            float maxValue = 0f;
            int   maxIndex = 0;

            for (int i = 0; i < contextMap.Length; i++)
            {
                if (contextMap[i] > maxValue)
                {
                    maxValue = contextMap[i];
                    maxIndex = i;
                }
            }

            Vector3 direction = Vector3.forward * maxValue;

            if (maxValue == 0f)
            {
                if (allowVectorZero)
                {
                    return(Vector3.zero);
                }

                return(lastVector); // return last direction if no better direction is found
            }

            if (steeringParams == null)
            {
                throw new UnassignedReferenceException("The direction selection algorithm does not know what axis to use, check constructor (PlanarSteeringParameters).");
            }

            // Update cache & return new direction.
            lastVector = MapOperations.RotateAroundAxis(steeringParams.ContextMapRotationAxis, resolutionAngle * maxIndex) * direction;
            return(lastVector);
        }
Example #5
0
 protected Quaternion rotateAroundAxis(float resolutionAngle)
 {
     return(MapOperations.RotateAroundAxis(steeringParameters.ContextMapRotationAxis, resolutionAngle));
 }