public void DebugDrawVelocityGrid() { if (mVelGrid != null) { Vector3 cellExtent = mVelGrid.GetCellExtent(); Vector3 gridExtent = mVelGrid.GetExtent(); Vector3 numCells = new Vector3(mVelGrid.GetNumCells(0), mVelGrid.GetNumCells(1), mVelGrid.GetNumCells(2)); Vector3 gridOrigin = mVelGrid.GetMinCorner(); for (int i = 0; i < numCells.x; ++i) { for (int j = 0; j < numCells.y; ++j) { for (int k = 0; k < numCells.z; ++k) { uint[] indices = { (uint)i, (uint)j, (uint)k }; uint offset = mVelGrid.OffsetFromIndices(indices); Vector3 center = mVelGrid.PositionFromIndices(indices) + cellExtent / 2; if (mVelGrid[offset].v.magnitude == 0) { break; } Color color = new Vector4(0.8f, 0.8f, 1, 1); DebugExtension.DrawArrow(center, mVelGrid[offset].v / 8, color); } } } } }
/* * Compute decimations, in each direction, for specified parent layer * * decimations - (out) ratio of dimensions between child layer and its parent. * iParentLayer - index of parent layer. * Child has index iParentLayer-1. * Layer 0 has no child so providing "0" is invalid. * * This method effectively gives the number of child cells in each * grid cluster that a parent cell represents. * * Each non-leaf layer in this NestedGrid is a decimation of its child * layer. Typically that decimation is 2 in each direction, but the * decimation can also be 1, or, more atypically, any other integer. * Each child typically has twice as many cells in each direction as * its parent. * * This assumes each parent has an integer decimation of its child. */ uint[] ComputeDecimations(uint iParentLayer) { uint[] decimations = new uint[3]; UniformGrid <ItemT> parent = (this)[iParentLayer]; UniformGrid <ItemT> child = (this)[iParentLayer - 1]; decimations[0] = child.GetNumCells(0) / parent.GetNumCells(0); decimations[1] = child.GetNumCells(1) / parent.GetNumCells(1); decimations[2] = child.GetNumCells(2) / parent.GetNumCells(2); return(decimations); }
public void DebugDrawInfluenceGrid() { if (mInfluenceTree != null && mInfluenceTree.mLayers.Count != 0) { for (int u = 0; u < mInfluenceTree.mLayers.Count; ++u) { //if (u != 0) continue; UniformGrid <Vorton> grid = mInfluenceTree.mLayers[u]; //Gizmos.color = new Vector4(1, 1 - 1 / ((float)u + 1), 1 - 1 / ((float)u + 1), 1.1f - 1 / ((float)u + 1)); Vector3 cellExtent = grid.GetCellExtent(); Vector3 gridExtent = grid.GetExtent(); Vector3 numCells = new Vector3(grid.GetNumCells(0), grid.GetNumCells(1), grid.GetNumCells(2)); Vector3 gridOrigin = grid.GetMinCorner(); for (int i = 0; i < numCells.x; ++i) { for (int j = 0; j < numCells.y; ++j) { for (int k = 0; k < numCells.z; ++k) { if (mInfluenceTree[0][0] == null) { break; } uint[] indices = { (uint)i, (uint)j, (uint)k }; uint offset = mInfluenceTree[(uint)u].OffsetFromIndices(indices); float vorticity = mInfluenceTree[(uint)u][offset].vorticity.magnitude; Gizmos.color = new Vector4(vorticity, u / mInfluenceTree.mLayers.Count, u / mInfluenceTree.mLayers.Count, vorticity); Gizmos.DrawWireCube(gridOrigin + new Vector3(cellExtent.x * i + cellExtent.x / 2, cellExtent.y * j + cellExtent.y / 2, cellExtent.z * k + cellExtent.z / 2), cellExtent); } } } } } }