コード例 #1
0
            // Iterate over all colliders and store those whose cell span has changed.
            public void Execute(int i)
            {
                float size  = bounds[i].AverageAxisLength();
                int   level = NativeMultilevelGrid <int> .GridLevelForSize(size);

                float cellSize = NativeMultilevelGrid <int> .CellSizeOfLevel(level);

                // get new collider bounds cell coordinates:
                BurstCellSpan newSpan = new BurstCellSpan(new int4(GridHash.Quantize(bounds[i].min.xyz, cellSize), level),
                                                          new int4(GridHash.Quantize(bounds[i].max.xyz, cellSize), level));

                // if the collider is 2D, project it to the z = 0 cells.
                if (colliders[i].is2D != 0)
                {
                    newSpan.min[2] = 0;
                    newSpan.max[2] = 0;
                }

                // if the collider is at the tail (removed), we will only remove it from its current cellspan.
                // if the new cellspan and the current one are different, we must remove it from its current cellspan and add it to its new one.
                if (i >= colliderCount || cellIndices[i] != newSpan)
                {
                    // Add the collider to the list of moving colliders:
                    movingColliders.Enqueue(new MovingCollider()
                    {
                        oldSpan = cellIndices[i],
                        newSpan = newSpan,
                        entity  = i
                    });

                    // Update previous coords:
                    cellIndices[i] = newSpan;
                }
            }
コード例 #2
0
            // Iterate over all colliders and store those whose cell span has changed.
            public void Execute(int i)
            {
                BurstAabb velocityBounds = bounds[i];

                // Expand bounds by rigidbody's linear velocity:
                if (shapes[i].rigidbodyIndex >= 0)
                {
                    velocityBounds.Sweep(rigidbodies[shapes[i].rigidbodyIndex].velocity * dt);
                }

                // Expand bounds by collision material's stick distance:
                if (shapes[i].materialIndex >= 0)
                {
                    velocityBounds.Expand(collisionMaterials[shapes[i].materialIndex].stickDistance);
                }

                float size  = velocityBounds.AverageAxisLength();
                int   level = NativeMultilevelGrid <int> .GridLevelForSize(size);

                float cellSize = NativeMultilevelGrid <int> .CellSizeOfLevel(level);

                // get new collider bounds cell coordinates:
                BurstCellSpan newSpan = new BurstCellSpan(new int4(GridHash.Quantize(velocityBounds.min.xyz, cellSize), level),
                                                          new int4(GridHash.Quantize(velocityBounds.max.xyz, cellSize), level));

                // if the collider is 2D, project it to the z = 0 cells.
                if (shapes[i].is2D != 0)
                {
                    newSpan.min[2] = 0;
                    newSpan.max[2] = 0;
                }

                // if the collider is at the tail (removed), we will only remove it from its current cellspan.
                // if the new cellspan and the current one are different, we must remove it from its current cellspan and add it to its new one.
                if (i >= colliderCount || cellIndices[i] != newSpan)
                {
                    // Add the collider to the list of moving colliders:
                    movingColliders.Enqueue(new MovingCollider()
                    {
                        oldSpan = cellIndices[i],
                        newSpan = newSpan,
                        entity  = i
                    });

                    // Update previous coords:
                    cellIndices[i] = newSpan;
                }
            }
コード例 #3
0
        public void AddToCells(BurstCellSpan span, T content)
        {
            for (int x = span.min[0]; x <= span.max[0]; ++x)
            {
                for (int y = span.min[1]; y <= span.max[1]; ++y)
                {
                    for (int z = span.min[2]; z <= span.max[2]; ++z)
                    {
                        int cellIndex = GetOrCreateCell(new int4(x, y, z, span.level));

                        var newCell = usedCells[cellIndex];
                        newCell.Add(content);
                        usedCells[cellIndex] = newCell;
                    }
                }
            }
        }
コード例 #4
0
 public void RemoveFromCells(BurstCellSpan span, T content)
 {
     for (int x = span.min[0]; x <= span.max[0]; ++x)
     {
         for (int y = span.min[1]; y <= span.max[1]; ++y)
         {
             for (int z = span.min[2]; z <= span.max[2]; ++z)
             {
                 int cellIndex;
                 if (TryGetCellIndex(new int4(x, y, z, span.level), out cellIndex))
                 {
                     var oldCell = usedCells[cellIndex];
                     oldCell.Remove(content);
                     usedCells[cellIndex] = oldCell;
                 }
             }
         }
     }
 }