// Given a bin's list of client proxies, traverse the list and invoke // the given lqCallBackFunction on each object that falls within the // search radius. public ArrayList GetBinClientObjectList(LqBin bin, float x, float y, float z, float radiusSquared) { //List<lqClientProxy> tList = new List<lqClientProxy>(); ArrayList tList = new ArrayList(); for (int i = 0; i < bin.clientList.Count; i++) { //bin.clientList..clientList.ForEach(delegate(lqClientProxy tClientObject) { LqClientProxy tClientObject = (LqClientProxy)bin.clientList[i]; /* compute distance (squared) from this client */ /* object to given locality sphere's centerpoint */ float dx = x - tClientObject.x; float dy = y - tClientObject.y; float dz = z - tClientObject.z; float distanceSquared = (dx * dx) + (dy * dy) + (dz * dz); /* apply function if client object within sphere */ if (distanceSquared < radiusSquared) { tList.Add(tClientObject); } //(*func) (co->object, distanceSquared, state); } //}); return(tList); }
public Vector3 GetMostPopulatedBinCenter() { LqBin mostPopulatedBin = GetMostPopulatedBin(); if (mostPopulatedBin != null) { return(mostPopulatedBin.center); } else { return(Vector3.zero); } }
// Call for each client object every time its location changes. For // example, in an animation application, this would be called each // frame for every moving object. public void LqUpdateForNewLocation(LqClientProxy clientObject, float x, float y, float z) { // find bin for new location LqBin newBin = LqBinForLocation(x, y, z); // store location in client object, for future reference clientObject.x = x; clientObject.y = y; clientObject.z = z; /* has object moved into a new bin? */ if (newBin != clientObject.bin) { LqRemoveFromBin(clientObject); LqAddToBin(clientObject, newBin); } }
public LqBin GetMostPopulatedBin() { int i; int bincount = divx * divy * divz; int largestPopulation = 0; LqBin mostPopulatedBin = null; for (i = 0; i < bincount; i++) { if (bins[i].clientList.Count > largestPopulation) { largestPopulation = bins[i].clientList.Count; mostPopulatedBin = bins[i]; } } // We will ignore other for now. Hope that works out ok return(mostPopulatedBin); }
public LocationQueryDatabase(float _originx, float _originy, float _originz, float _sizex, float _sizey, float _sizez, int _divx, int _divy, int _divz) { originx = _originx; originy = _originy; originz = _originz; sizex = _sizex; sizey = _sizey; sizez = _sizez; divx = _divx; divy = _divy; divz = _divz; int i; bincount = divx * divy * divz; bins = new LqBin[bincount];// List<lqBin>(); for (int x = 0; x < divx; x++) { for (int y = 0; y < divy; y++) { for (int z = 0; z < divz; z++) { i = (int)((x * divy * divz) + (y * divz) + z); float tx = originx + ((float)x) * ((float)sizex / (float)divx); // -(sizex / 2f); float ty = originy + ((float)y) * ((float)sizey / (float)divy); // -(sizey / 2f); float tz = originz + ((float)z) * ((float)sizez / (float)divz); // -(sizez / 2f); Vector3 binCenter = new Vector3(tx, ty, tz); bins[i] = new LqBin(binCenter); } } } other = new LqBin(Vector3.zero); }
/* ------------------------------------------------------------------ */ /* internal helper function */ public void LqRemoveAllObjectsInBin(LqBin bin) { bin.clientList.Clear(); }
// Adds a given client object to a given bin, linking it into the bin // contents list. public void LqAddToBin(LqClientProxy clientObject, LqBin bin) { bin.clientList.Add(clientObject); clientObject.bin = bin; }