From 9362e32d6fcc971bb149ea996cf9d0de7d6bcd95 Mon Sep 17 00:00:00 2001 From: Justin Butler Date: Fri, 27 Jun 2008 00:43:47 +0000 Subject: [PATCH] forgot to commit this for dynamic ray of light in pirates --- direct/src/distributed/CartesianGridBase.py | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/direct/src/distributed/CartesianGridBase.py b/direct/src/distributed/CartesianGridBase.py index 8fc2d9dcce..0c549c3e71 100755 --- a/direct/src/distributed/CartesianGridBase.py +++ b/direct/src/distributed/CartesianGridBase.py @@ -79,3 +79,47 @@ class CartesianGridBase: return (x, y, 0) + #-------------------------------------------------------------------------- + # Function: utility function to get all zones in a ring of given radius + # around the given zoneId (so if given a zoneId 34342 and a + # radius of 3, a list of all zones exactly 3 grids away from + # zone 34342 will be returned) + # Parameters: zoneId, center zone to find surrounding zones of + # radius, how far from zoneId to find zones of for it them + # Changes: + # Returns: + #-------------------------------------------------------------------------- + def getConcentricZones(self, zoneId, radius): + zones = [] + #currZone = zoneId + radius + #numZones = (2 * radius * 8) + 2 + # start at upper left + zone = zoneId - self.startingZone + row = zone // self.gridSize + col = zone % self.gridSize + + leftOffset = min(col, radius) + rightOffset = min(self.gridSize - (col + 1), radius) + topOffset = min(row, radius) + bottomOffset = min(self.gridSize - (row + 1), radius) + + #print "starting examination of grid circle of radius %s"%radius + ulZone = zoneId - leftOffset - topOffset * self.gridSize + #print "left offset is %s and radius is %s"%(leftOffset,radius) + for currCol in range(int(rightOffset + leftOffset + 1)): + if ((currCol == 0 and leftOffset == radius) or (currCol == rightOffset + leftOffset and rightOffset == radius)): + # at either left or right edge of area, look at all rows + possibleRows = range(int(bottomOffset + topOffset + 1)) + else: + # in a middle column, only look at top and bottom rows + possibleRows = [] + if (topOffset == radius): + possibleRows.append(0) + if (bottomOffset == radius): + possibleRows.append(bottomOffset + topOffset) + #print "on column %s and looking at rows %s"%(currCol,possibleRows) + for currRow in possibleRows: + newZone = ulZone + (currRow * self.gridSize) + currCol + zones.append(int(newZone)) + #print " examining zone %s"%newZone + return zones