private void ForeachAround(EntitiesHashMap.MyData me, ref float3 correction, ref CollisionParameters collision)
        {
            var position = me.position;
            var key      = QuadrantVariables.GetPositionHashMapKey(position);

            Foreach(key, me, ref correction, ref collision);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            Foreach(key, me, ref correction, ref collision);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            Foreach(key, me, ref correction, ref collision);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            Foreach(key, me, ref correction, ref collision);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            Foreach(key, me, ref correction, ref collision);


            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 1));
            Foreach(key, me, ref correction, ref collision);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 1));
            Foreach(key, me, ref correction, ref collision);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, -1));
            Foreach(key, me, ref correction, ref collision);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, -1));
            Foreach(key, me, ref correction, ref collision);
        }
        private void ForeachAround2(CollisionParameters collision, Translation translation, ref float3 correction)
        {
            var position = translation.Value;
            var key      = QuadrantVariables.GetPositionHashMapKey(position);

            Foreach(key, collision, translation, ref correction);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            Foreach(key, collision, translation, ref correction);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            Foreach(key, collision, translation, ref correction);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            Foreach(key, collision, translation, ref correction);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            Foreach(key, collision, translation, ref correction);


            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 1));
            Foreach(key, collision, translation, ref correction);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 1));
            Foreach(key, collision, translation, ref correction);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, -1));
            Foreach(key, collision, translation, ref correction);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, -1));
            Foreach(key, collision, translation, ref correction);
        }
示例#3
0
        private void Add(float3 position, float3 prev, float maxdistance)
        {
            var keyDistance = QuadrantVariables.IndexFromPosition(position, prev, max);

            if (keyDistance.key < 0)
            {
                return;
            }
            quadrantHashMap[keyDistance.key] += math.max(0f, (maxdistance - keyDistance.distance) / maxdistance);
        }
示例#4
0
        private void ForeachAround(float3 position, Fighter me, ref Condition condition)
        {
            var key = QuadrantVariables.GetPositionHashMapKey(position);

            Foreach(key, position, me, ref condition);
            QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            Foreach(key, position, me, ref condition);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            Foreach(key, position, me, ref condition);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            Foreach(key, position, me, ref condition);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            Foreach(key, position, me, ref condition);
        }
示例#5
0
        private void ForeachAround(float3 position, Condition condition, float3 direction, FoodHierarchie hierarchie, ref FoodHierarchieHashMap.MyData foundFood, ref bool found)
        {
            var key = QuadrantVariables.GetPositionHashMapKey(position);

            Foreach(key, position, condition, direction, hierarchie, ref foundFood, ref found);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            Foreach(key, position, condition, direction, hierarchie, ref foundFood, ref found);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            Foreach(key, position, condition, direction, hierarchie, ref foundFood, ref found);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            Foreach(key, position, condition, direction, hierarchie, ref foundFood, ref found);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            Foreach(key, position, condition, direction, hierarchie, ref foundFood, ref found);
        }
        public void Execute([ReadOnly] ref PathFindingData data, [ReadOnly] ref CollisionParameters collision,
                            ref Walker walker, [ReadOnly] ref Translation translation)
        {
            if (!(data.avoidMethod == CollisionAvoidanceMethod.DensityGrid))
            {
                return;
            }

            var distance = data.decidedGoal - translation.Value;

            if (math.length(distance) < data.radius)
            {
                data.decidedForce *= 0.5f;
            }

            var group = oneLayer * walker.broId;

            var force = float3.zero;

            for (int i = 0; i < Angels; i++)
            {
                var vector = GetDirection(walker.direction, i * math.PI * 2f / Angels) * collision.innerRadius;
                var index  = QuadrantVariables.BilinearInterpolation(translation.Value + vector, max);

                var density0 = densityMap[group + index.Index0] * index.percent0;
                var density1 = densityMap[group + index.Index1] * index.percent1;
                var density2 = densityMap[group + index.Index2] * index.percent2;
                var density3 = densityMap[group + index.Index3] * index.percent3;
                var density  = density0 + density1 + density2 + density3;

                density0 = densityMap[index.Index0] * index.percent0;
                density1 = densityMap[index.Index1] * index.percent1;
                density2 = densityMap[index.Index2] * index.percent2;
                density3 = densityMap[index.Index3] * index.percent3;
                var densityOwn = density0 + density1 + density2 + density3;
                if (density > 0)
                {
                    var direction = -vector / collision.outerRadius;
                    force += (math.normalizesafe(direction) - direction) * (density);
                }
                if (densityOwn > 3)
                {
                    var direction = -vector / collision.outerRadius;
                    force += (math.normalizesafe(direction) - direction) * (densityOwn - 3f);
                }
            }

            walker.force = force + data.decidedForce;
        }
示例#7
0
        private void ForeachAround(Circle me, ref float2 avoidanceForce, ref float minTime)
        {
            var position = me.Position;
            var key      = QuadrantVariables.GetPositionHashMapKey(position);

            Foreach(key, me, ref avoidanceForce, ref minTime);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            Foreach(key, me, ref avoidanceForce, ref minTime);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            Foreach(key, me, ref avoidanceForce, ref minTime);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            Foreach(key, me, ref avoidanceForce, ref minTime);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            Foreach(key, me, ref avoidanceForce, ref minTime);
        }
示例#8
0
        private void ForeachAround(QuadrantData me, ref float3 avoidanceForce, float radius)
        {
            var position = me.position;
            var key      = QuadrantVariables.GetPositionHashMapKey(position);

            Foreach(key, me, ref avoidanceForce, radius);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            Foreach(key, me, ref avoidanceForce, radius);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            Foreach(key, me, ref avoidanceForce, radius);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            Foreach(key, me, ref avoidanceForce, radius);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            Foreach(key, me, ref avoidanceForce, radius);
        }
示例#9
0
        private void ForeachAround(ref Infection infection, ref Translation translation)
        {
            var position = translation.Value;
            var key      = QuadrantVariables.GetPositionHashMapKey(position);

            Foreach(key, ref infection, ref translation);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            Foreach(key, ref infection, ref translation);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            Foreach(key, ref infection, ref translation);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            Foreach(key, ref infection, ref translation);
            key = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            Foreach(key, ref infection, ref translation);
        }
示例#10
0
        private bool ForeachAround(float3 position, ref FightersHashMap.MyData output, Fighter myBroId)
        {
            var found = false;
            var key   = QuadrantVariables.GetPositionHashMapKey(position);

            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            found = found || Foreach(key, position, ref output, found, myBroId);
            return(found);
        }
示例#11
0
        private void Add(float3 position, float3 prev, float maxdistance, int gid)
        {
            var keyDistance = QuadrantVariables.IndexFromPosition(position, prev, max);

            if (keyDistance.key < 0)
            {
                return;
            }
            for (int group = 0; group < maxGroup; group++)
            {
                if (group != gid)
                {
                    quadrantHashMap[oneLayer * group + keyDistance.key] += math.max(0f, (maxdistance - keyDistance.distance) / maxdistance);
                }
            }
        }
        public void Execute(ref PhysicsCollider collider, ref LocalToWorld localToWorld)
        {
            var aabb = collider.Value.Value.CalculateAabb();

            for (int group = 0; group < maxGroup; group++)
            {
                for (int j = 0; j < heightPoints - 1; j++)
                {
                    for (int i = 0; i < widthPoints - 1; i++)
                    {
                        var point    = QuadrantVariables.ConvertToWorld(new float3(i, 0, j), max);
                        var localPos = point - localToWorld.Position;
                        localPos = math.mul(math.inverse(localToWorld.Rotation), localPos);
                        if (aabb.Min.x - distance > localPos.x)
                        {
                            continue;
                        }
                        if (aabb.Min.z - distance > localPos.z)
                        {
                            continue;
                        }
                        if (aabb.Max.x + distance < localPos.x)
                        {
                            continue;
                        }
                        if (aabb.Max.z + distance < localPos.z)
                        {
                            continue;
                        }

                        if (collider.Value.Value.CalculateDistance(new PointDistanceInput()
                        {
                            Position = localPos,
                            MaxDistance = float.MaxValue,
                            Filter = CollisionFilter.Default
                        }, out DistanceHit hit))
                        {
                            if (distance - hit.Distance > 0f)
                            {
                                densityMatrix[group * oneLayer + QuadrantVariables.Index(i, j, max)] += math.max(0f, distance - hit.Distance);
                            }
                        }
                    }
                }
            }
        }