示例#1
0
        static void WallSteering(ref SteeringForce steering, float facingAngle, float3 position,
                                 NativeArray <Translation> obstaclePositions, NativeArray <Radius> obstacleRadii, BucketData bucketData)
        {
            steering.Value = 0;
            var wallCheckDistance = 1f / bucketData.BucketResolution;

            for (var i = -1; i <= 1; i += 2)
            {
                float angle = facingAngle + i * math.PI * .25f;
                position += math.mul(quaternion.Euler(0, 0, angle), new float3(wallCheckDistance, 0, 0));
                var bucket     = bucketData.GetBucket(position);
                var bucketAABB = bucketData.GetBucketAABB(bucket);

                for (var j = 0; j < obstaclePositions.Length; j++)
                {
                    var obstacleAABB = new AABB
                    {
                        Center  = obstaclePositions[j].Value,
                        Extents = new float3(1, 1, 0) * obstacleRadii[j].Value
                    };

                    if (bucketAABB.Overlaps(obstacleAABB))
                    {
                        steering.Value -= i;
                        break;
                    }
                }
            }
        }
示例#2
0
        static void PheromoneSteering(ref SteeringForce steering, float facingAngle, float3 position,
                                      NativeArray <Strength> pheromoneStrengths, BucketData bucketData)
        {
            steering.Value = 0;
            var checkDistance = 1f / bucketData.BucketResolution;

            for (var i = -1; i <= 1; i += 2)
            {
                float angle = facingAngle + i * math.PI * .25f;
                position += math.mul(quaternion.Euler(0, 0, angle), new float3(checkDistance, 0, 0));
                var bucket = math.clamp(bucketData.GetBucket(position), int2.zero, new int2(bucketData.BucketResolution - 1));

                steering.Value = pheromoneStrengths[bucket.x + bucket.y * bucketData.BucketResolution].Value * i;
            }

            steering.Value = math.sign(steering.Value);
        }