public locationQueryDatabase(float _originx, float _originy, float _originz, float _sizex, float _sizey, float _sizez, int _divx, int _divy, int _divz)
 {
     this.originx  = _originx;
     this.originy  = _originy;
     this.originz  = _originz;
     this.sizex    = _sizex;
     this.sizey    = _sizey;
     this.sizez    = _sizez;
     this.divx     = _divx;
     this.divy     = _divy;
     this.divz     = _divz;
     this.bincount = this.divx * this.divy * this.divz;
     this.bins     = new lqBin[this.bincount];
     for (int i = 0; i < this.divx; i++)
     {
         for (int j = 0; j < this.divy; j++)
         {
             for (int k = 0; k < this.divz; k++)
             {
                 int     num       = i * this.divy * this.divz + j * this.divz + k;
                 float   num2      = this.originx + (float)i * (this.sizex / (float)this.divx);
                 float   num3      = this.originy + (float)j * (this.sizey / (float)this.divy);
                 float   num4      = this.originz + (float)k * (this.sizez / (float)this.divz);
                 Vector3 binCenter = new Vector3(num2, num3, num4);
                 this.bins[num] = new lqBin(binCenter);
             }
         }
     }
     this.other = new lqBin(Vector3.get_zero());
 }
Example #2
0
        // 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 ArrayList getAllClientObjectsInLocalityClipped(float x, float y, float z, float radius, int minBinX, int minBinY, int minBinZ, int maxBinX, int maxBinY, int maxBinZ)
        {
            int       num           = this.divy * this.divz;
            int       num2          = this.divz;
            int       num3          = minBinX * num;
            int       num4          = minBinY * num2;
            float     radiusSquared = radius * radius;
            ArrayList arrayList     = new ArrayList();
            int       num5          = num3;

            for (int i = minBinX; i <= maxBinX; i++)
            {
                int num6 = num4;
                for (int j = minBinY; j <= maxBinY; j++)
                {
                    int num7 = minBinZ;
                    for (int k = minBinZ; k <= maxBinZ; k++)
                    {
                        lqBin     bin = this.bins[num5 + num6 + num7];
                        ArrayList binClientObjectList = this.getBinClientObjectList(bin, x, y, z, radiusSquared);
                        arrayList.AddRange(binClientObjectList);
                        num7++;
                    }
                    num6 += num2;
                }
                num5 += num;
            }
            return(arrayList);
        }
        public Vector3 getMostPopulatedBinCenter()
        {
            lqBin mostPopulatedBin = this.getMostPopulatedBin();

            if (mostPopulatedBin != null)
            {
                return(mostPopulatedBin.center);
            }
            return(Vector3.get_zero());
        }
        public void lqUpdateForNewLocation(lqClientProxy clientObject, float x, float y, float z)
        {
            lqBin lqBin = this.lqBinForLocation(x, y, z);

            clientObject.x = x;
            clientObject.y = y;
            clientObject.z = z;
            if (lqBin != clientObject.bin)
            {
                this.lqRemoveFromBin(clientObject);
                this.lqAddToBin(clientObject, lqBin);
            }
        }
Example #6
0
        public Vector3 getMostPopulatedBinCenter()
        {
            lqBin mostPopulatedBin = getMostPopulatedBin();

            if (mostPopulatedBin != null)
            {
                return(mostPopulatedBin.center);
            }
            else
            {
                return(Vector3.zero);
            }
        }
Example #7
0
        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);
                        //Console.WriteLine("Bin is " + i);
                    }
                }
            }

            /*
             *  for (i=0; i<bincount; i++) {
             *
             *  ix = (int)(((x - originx) / sizex) * divx);
             *  iy = (int)(((y - originy) / sizey) * divy);
             *  iz = (int)(((z - originz) / sizez) * divz);
             *  //return (int) ((ix * divy * divz) + (iy * divz) + iz);
             *  bins[i]=new lqBin();
             * }
             */
            other = new lqBin(Vector3.zero);
        }
        public lqBin getMostPopulatedBin()
        {
            int   num    = this.divx * this.divy * this.divz;
            int   num2   = 0;
            lqBin result = null;

            for (int i = 0; i < num; i++)
            {
                if (this.bins[i].clientList.get_Count() > num2)
                {
                    num2   = this.bins[i].clientList.get_Count();
                    result = this.bins[i];
                }
            }
            return(result);
        }
Example #9
0
        // 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);
            }
        }
Example #10
0
        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 ArrayList getBinClientObjectList(lqBin bin, float x, float y, float z, float radiusSquared)
        {
            ArrayList arrayList = new ArrayList();

            for (int i = 0; i < bin.clientList.get_Count(); i++)
            {
                lqClientProxy lqClientProxy = (lqClientProxy)bin.clientList.get_Item(i);
                float         num           = x - lqClientProxy.x;
                float         num2          = y - lqClientProxy.y;
                float         num3          = z - lqClientProxy.z;
                float         num4          = num * num + num2 * num2 + num3 * num3;
                if (num4 < radiusSquared)
                {
                    arrayList.Add(lqClientProxy);
                }
            }
            return(arrayList);
        }
Example #12
0
        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);
                        //Console.WriteLine("Bin is " + i);
                    }
                }
            }
            /*
            for (i=0; i<bincount; i++) {

                ix = (int)(((x - originx) / sizex) * divx);
                iy = (int)(((y - originy) / sizey) * divy);
                iz = (int)(((z - originz) / sizez) * divz);
                //return (int) ((ix * divy * divz) + (iy * divz) + iz);
                bins[i]=new lqBin();
            }
            */
            other = new lqBin(Vector3.zero);
        }
Example #13
0
 /* ------------------------------------------------------------------ */
 /* internal helper function */
 public void lqRemoveAllObjectsInBin(lqBin bin)
 {
     bin.clientList.Clear();
 }
Example #14
0
 // 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;
 }
Example #15
0
        // 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 void lqAddToBin(lqClientProxy clientObject, lqBin bin)
 {
     bin.clientList.Add(clientObject);
     clientObject.bin = bin;
 }
 public void lqRemoveAllObjectsInBin(lqBin bin)
 {
     bin.clientList.Clear();
 }