private OctagonalVector AllocateLowerBoundRoot(OctagonalVector v) { OctagonalVector dV = v - _rootVector; OctagonalVector oldRoot = new OctagonalVector( (dV.X < 0) ? ((-dV.X - 1) >> _depth) + 1 : 0, (dV.Y < 0) ? ((-dV.Y - 1) >> _depth) + 1 : 0, (dV.Z < 0) ? ((-dV.Z - 1) >> _depth) + 1 : 0); List <int> oldRootPath = oldRoot.CalculatePath(); int oldRootPathLength = oldRootPath.Count(); if (oldRootPathLength > 0) { for (int i = 0; i < oldRootPathLength; i++) { _root = new Octant(oldRootPath[i], _root); } _rootVector -= oldRoot << _depth; _depth += oldRootPathLength; } return(dV); }
public VertexPositionColor[] GetPathLines(List <int> path, Color color) { int size = 1 << (_depth - path.Count); var vector = OctagonalVector.CalculateVector(path) * size + _rootVector; var result = new VertexPositionColor[24]; for (int i = 0; i < 24; i++) { result[i].Color = color; result[i].Position = Octagonal.Mesh.Cube.VectorsLineList[i] * size + (Vector3)vector; } return(result); }
static public OctagonalVector CalculateVector(List <int> path) { int pathLength = path.Count; int bit = 0; OctagonalVector v = new OctagonalVector(0, 0, 0); while (bit < pathLength) { v.X |= ((path[bit] & (1 << BIT_X)) >> BIT_X) << bit; v.Y |= ((path[bit] & (1 << BIT_Y)) >> BIT_Y) << bit; v.Z |= ((path[bit] & (1 << BIT_Z)) >> BIT_Z) << bit; bit++; } return(v); }
public OctagonalVector AllocateNode(OctagonalVector v, OctantNode node) { lock (this) { if (_root == null) { _rootVector = v; _depth = 0; _root = node; return(new OctagonalVector(0, 0, 0)); } OctagonalVector dV = AllocateLowerBoundRoot(v); AllocateVector(dV.CalculatePath(), node); return(dV); } }
internal Vector3 ToWorldVector(OctagonalVector oVector) { return(oVector + _rootVector); }