//---------------------------------- public void createRealLOSRepQuadTree(uint numXVerts, uint numZVerts) { Vector3 min = new Vector3(0, 0, 0); Vector3 max = new Vector3(numXVerts * mTileScale, 10, numZVerts * mTileScale); uint numLevels = 1; uint numXNodes = mWidth;// (uint)(TerrainGlobals.getTerrain().getNumXVerts() / BTerrainQuadNode.cMaxWidth); // while (numXNodes > 1) { numXNodes = numXNodes >> 1; numLevels++; } base.createSpatialQuadTree(new float3(min), new float3(max), numXNodes, numXNodes);//numLevels); mNumXVertsPerCell = mWidth / mNumXLeafCells; mNumZVertsPerCell = mHeight / mNumZLeafCells; //initalize our leaf nodes for (uint i = 0; i < mNumXLeafCells; i++) { for (uint j = 0; j < mNumZLeafCells; j++) { SpatialQuadTreeCell cell = getLeafCellAtGridLoc(i, j); if (cell != null) { cell.mExternalData = new RealLOSRepQuadCell(); ((RealLOSRepQuadCell)cell.mExternalData).mMinXVert = (int)(i * mNumXVertsPerCell); ((RealLOSRepQuadCell)cell.mExternalData).mMinZVert = (int)(j * mNumZVertsPerCell); } } } }
public void recalculateVisuals() { for (uint minx = 0; minx < mNumXLeafCells; minx++) { for (uint minz = 0; minz < mNumZLeafCells; minz++) { SpatialQuadTreeCell spatialCell = getLeafCellAtGridLoc(minx, minz); RealLOSRepQuadCell cell = ((RealLOSRepQuadCell)spatialCell.mExternalData); updateVisualHandle(ref cell.mVisualHandle, cell.mMinXVert, cell.mMinZVert); } } }
//---------------------------------- public void recalculateBBs() { for (uint minx = 0; minx < mNumXLeafCells; minx++) { for (uint minz = 0; minz < mNumZLeafCells; minz++) { SpatialQuadTreeCell spatialCell = getLeafCellAtGridLoc(minx, minz); recalculateCellBB(spatialCell); } } mRootCell.updateBoundsFromChildren(); }
void recalculateCellBB(SpatialQuadTreeCell spatialCell) { BBoundingBox bb = new BBoundingBox(); bb.empty(); RealLOSRepQuadCell cell = ((RealLOSRepQuadCell)spatialCell.mExternalData); for (uint i = (uint)cell.mMinXVert; i <= cell.mMinXVert + mNumXVertsPerCell; i++) { for (uint j = (uint)cell.mMinZVert; j <= cell.mMinZVert + mNumZVertsPerCell; j++) { if (i >= mWidth || j >= mHeight) { continue; } float3 worldPos = getWorldspacePoint((int)i, (int)j); bb.addPoint(worldPos.toVec3()); } } spatialCell.setBounds(new float3(bb.min), new float3(bb.max)); bb = null; }
//---------------------------------- public void createSimHeightRepQuadTree(uint numXVerts, uint numZVerts) { Vector3 min = new Vector3(0, 0, 0); Vector3 max = new Vector3(numXVerts * mTileScale, 10, numZVerts * mTileScale); uint numvertspercell = (uint)(BTerrainQuadNode.cMaxWidth * TerrainGlobals.getEditor().getSimRep().getVisToSimScale()); uint numNodesTest = numXVerts / numvertspercell; if (numNodesTest * numvertspercell < mWidth) { numNodesTest++; } uint numXNodes = numNodesTest;// (uint)(TerrainGlobals.getTerrain().getNumXVerts() / BTerrainQuadNode.cMaxWidth);// +1; // while (numXNodes > 1) { numXNodes = numXNodes >> 1; numLevels++; } base.createSpatialQuadTree(new float3(min), new float3(max), numXNodes, numXNodes); //numLevels); mNumXVertsPerCell = numvertspercell; // mWidth / mNumXLeafCells; mNumZVertsPerCell = numvertspercell; //mHeight / mNumZLeafCells; //initalize our leaf nodes for (uint i = 0; i < mNumXLeafCells; i++) { for (uint j = 0; j < mNumZLeafCells; j++) { SpatialQuadTreeCell cell = getLeafCellAtGridLoc(i, j); if (cell != null) { cell.mExternalData = new SimHeightRepQuadCell(); ((SimHeightRepQuadCell)cell.mExternalData).mMinXVert = (int)(i * mNumXVertsPerCell); ((SimHeightRepQuadCell)cell.mExternalData).mMinZVert = (int)(j * mNumZVertsPerCell); } } } }
public void updateAfterPainted(int minX, int minZ, int maxX, int maxZ) { //verts are in our local stride. //find any chunks intersecting these numbers and update them. uint minXCell = (uint)BMathLib.Clamp((minX / mNumXVertsPerCell) - 1, 0, mNumXLeafCells); uint minZCell = (uint)BMathLib.Clamp((minZ / mNumZVertsPerCell) - 1, 0, mNumXLeafCells); uint maxXCell = (uint)BMathLib.Clamp((maxX / mNumXVertsPerCell) + 1, 0, mNumXLeafCells); uint maxZCell = (uint)BMathLib.Clamp((maxZ / mNumZVertsPerCell) + 1, 0, mNumXLeafCells); for (uint minx = minXCell; minx < maxXCell; minx++) { for (uint minz = minZCell; minz < maxZCell; minz++) { SpatialQuadTreeCell spatialCell = getLeafCellAtGridLoc(minx, minz); RealLOSRepQuadCell cell = ((RealLOSRepQuadCell)spatialCell.mExternalData); updateVisualHandle(ref cell.mVisualHandle, cell.mMinXVert, cell.mMinZVert); recalculateCellBB(spatialCell); } } mRootCell.updateBoundsFromChildren(); }