mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
forgot to commit this for dynamic ray of light in pirates
This commit is contained in:
parent
52a60b7f2f
commit
9362e32d6f
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user