Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public Vector3 getMostPopulatedBinCenter()
        {
            lqBin mostPopulatedBin = getMostPopulatedBin();

            if (mostPopulatedBin != null)
            {
                return(mostPopulatedBin.center);
            }
            else
            {
                return(Vector3.Zero);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /* ------------------------------------------------------------------ */
        /* internal helper function */


        public void lqRemoveAllObjectsInBin(lqBin bin)
        {
            bin.clientList.Clear();
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 /* ------------------------------------------------------------------ */
 /* internal helper function */
 public void lqRemoveAllObjectsInBin(lqBin bin)
 {
     bin.clientList.Clear();
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
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;
        }