Hello I'm trying to implement an octree, but when I query the centre positions they all return zero, but these should be offset from zero. Here is my code:
class Octree:
def __init__( self, _centre, _size ):
'''
Class to create an Octree
@param: _centre: [float,float,float], position in world space for centre of octree
@param: _size: float, length of one edge of the first cube, should be big enough to fit all data
'''
self.centre = _centre
self.size = _size
self.octreeNodes = []
def subdivideOctree( self, _subdivisions ):
'''
subdivides octree
@param: _subdivisions: int, number of times to subdivide octree
'''
for i in range(8):
newCentre = self.centre
if ((i&2) == 2):
newCentre[0] += self.size * 0.25
else:
newCentre[0] -= self.size * 0.25
if ((i&4) == 4):
newCentre[1] += self.size * 0.25
else:
newCentre[1] -= self.size * 0.25
if ((i&1) == 1):
newCentre[2] += self.size * 0.25
else:
newCentre[2] -= self.size * 0.25
print newCentre
self.octreeNodes.append(Octree( newCentre, self.size * 0.5 ))
if( _subdivisions > 0 ):
self.octreeNodes[i].subdivideOctree( _subdivisions - 1 )
def isLeaf( self ):
return self.octreeNodes == None
def getCentre( self ):
return self.centre
def getSize( self ):
return self.size
a = Octree([0,0,0], 2.0)
a.subdivideOctree(2)
print a.getCentre()
print a.octreeNodes[0].getCentre()
print a.octreeNodes[0]
for n in a.octreeNodes:
for b in n.octreeNodes:
print b.getCentre()