Browse Source

expanding the gridSphere to account for the offset of the zoneLOD sphere from the center of the grid

Josh Wilson 17 years ago
parent
commit
26ea36a23b
1 changed files with 13 additions and 1 deletions
  1. 13 1
      direct/src/distributed/CartesianGridBase.py

+ 13 - 1
direct/src/distributed/CartesianGridBase.py

@@ -1,4 +1,4 @@
-
+from pandac.PandaModules import Vec3
 # Utility functions that are useful to both AI and client CartesianGrid code
 # Utility functions that are useful to both AI and client CartesianGrid code
 
 
 class CartesianGridBase:
 class CartesianGridBase:
@@ -42,6 +42,18 @@ class CartesianGridBase:
         sphereRadius = max(sphereRadius, gridRadius*cellWidth)
         sphereRadius = max(sphereRadius, gridRadius*cellWidth)
         return 2 * (sphereRadius // cellWidth)
         return 2 * (sphereRadius // cellWidth)
 
 
+    def getGridSizeFromSphere(self, sphereRadius, spherePos, cellWidth, gridRadius):
+        # NOTE: This ensures that the grid is at least a "gridRadius" number
+        # of cells larger than the trigger sphere that loads the grid.  This
+        # gives us some room to start setting interest to the grid before we
+        # expect to see any objects on it.
+        xMax = abs(spherePos[0])+sphereRadius
+        yMax = abs(spherePos[1])+sphereRadius
+        sphereRadius = Vec3(xMax,yMax,0).length()
+        
+        # sphereRadius = max(sphereRadius, gridRadius*cellWidth)
+        return 2 * (sphereRadius // cellWidth)
+
     def getZoneCellOrigin(self, zoneId):
     def getZoneCellOrigin(self, zoneId):
         # It returns the origin of the zoneCell
         # It returns the origin of the zoneCell
         # Origin is the top-left corner of zoneCell
         # Origin is the top-left corner of zoneCell