Пример #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);
        }
 public void lqRemoveFromBin(lqClientProxy clientObject)
 {
     if (clientObject.bin != null)
     {
         clientObject.bin.clientList.Remove(clientObject);
     }
 }
Пример #3
0
        /* ------------------------------------------------------------------ */

        /* Search the database to find the object whose key-point is nearest
         * to a given location yet within a given radius.  That is, it finds
         * the object (if any) within a given search sphere which is nearest
         * to the sphere's center.  The ignoreObject argument can be used to
         * exclude an object from consideration (or it can be NULL).  This is
         * useful when looking for the nearest neighbor of an object in the
         * database, since otherwise it would be its own nearest neighbor.
         * The function returns a void* pointer to the nearest object, or
         * NULL if none is found.  */



        public lqClientProxy lqFindNearestNeighborWithinRadius(
            float x, float y, float z,
            float radius,
            System.Object ignoreObject)
        {
            float minDistanceSquared = float.MaxValue;

            // map search helper function over all objects within radius
            ArrayList foundList = getAllObjectsInLocality(x, y, z, radius);

            lqClientProxy nearestObject = null;

            for (int i = 0; i < foundList.Count; i++)
            {
                lqClientProxy tProxyObject = (lqClientProxy)foundList[i];
                //foundList.ForEach(delegate(lqClientProxy tProxyObject)
                //{
                if (tProxyObject != ignoreObject)
                {
                    float dx = tProxyObject.x - x;
                    float dy = tProxyObject.y - y;
                    float dz = tProxyObject.z - z;

                    float distanceSquared = dx * dx + dy * dy + dz * dz;
                    if (distanceSquared < minDistanceSquared)
                    {
                        nearestObject      = tProxyObject;
                        minDistanceSquared = distanceSquared;
                    }
                }
            }
            //});
            return(nearestObject);
        }
Пример #4
0
            public override void findNeighbors(Vector3 center, float radius, ArrayList results)
            {
                ArrayList allObjectsInLocality = this.lq.getAllObjectsInLocality(center.x, center.y, center.z, radius);

                for (int i = 0; i < allObjectsInLocality.get_Count(); i++)
                {
                    lqClientProxy lqClientProxy = (lqClientProxy)allObjectsInLocality.get_Item(i);
                    results.Add((SteeringVehicle)lqClientProxy.clientObject);
                }
            }
Пример #5
0
        public override SteeringVehicle getNearestVehicle(Vector3 position, float radius)
        {
            lqClientProxy   tProxy   = lq.lqFindNearestNeighborWithinRadius(position.x, position.y, position.z, radius, null);
            SteeringVehicle tVehicle = null;

            if (tProxy != null)
            {
                tVehicle = (SteeringVehicle)tProxy.clientObject;
            }
            return(tVehicle);
        }
Пример #6
0
        public override SteeringVehicle getNearestVehicle(Vector3 position, float radius)
        {
            lqClientProxy   lqClientProxy = this.lq.lqFindNearestNeighborWithinRadius(position.x, position.y, position.z, radius, null);
            SteeringVehicle result        = null;

            if (lqClientProxy != null)
            {
                result = (SteeringVehicle)lqClientProxy.clientObject;
            }
            return(result);
        }
        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);
            }
        }
Пример #8
0
            // find all neighbors within the given sphere (as center and radius)
            public override void findNeighbors(Vector3 center, float radius, ArrayList results)
            {
                //lqMapOverAllObjectsInLocality(lq,

                ArrayList tList = lq.getAllObjectsInLocality(center.x, center.y, center.z, radius);

                for (int i = 0; i < tList.Count; i++)
                {
                    lqClientProxy tProxy = (lqClientProxy)tList[i];
                    //tList.ForEach(delegate(lqClientProxy tProxy)
                    //{
                    results.Add((SteeringVehicle)tProxy.clientObject);
                    //});
                }
            }
Пример #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);
            }
        }
        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);
        }
        public lqClientProxy lqFindNearestNeighborWithinRadius(float x, float y, float z, float radius, object ignoreObject)
        {
            float         num = 3.40282347E+38f;
            ArrayList     allObjectsInLocality = this.getAllObjectsInLocality(x, y, z, radius);
            lqClientProxy result = null;

            for (int i = 0; i < allObjectsInLocality.get_Count(); i++)
            {
                lqClientProxy lqClientProxy = (lqClientProxy)allObjectsInLocality.get_Item(i);
                if (lqClientProxy != ignoreObject)
                {
                    float num2 = lqClientProxy.x - x;
                    float num3 = lqClientProxy.y - y;
                    float num4 = lqClientProxy.z - z;
                    float num5 = num2 * num2 + num3 * num3 + num4 * num4;
                    if (num5 < num)
                    {
                        result = lqClientProxy;
                        num    = num5;
                    }
                }
            }
            return(result);
        }
Пример #12
0
 // constructor
 public tokenType(System.Object parentObject, LQProximityDatabase lqsd)
 {
     proxy = new lqClientProxy(parentObject);// lqInitClientProxy(proxy, parentObject);
     lq    = lqsd.lq;
 }
 public void lqAddToBin(lqClientProxy clientObject, lqBin bin)
 {
     bin.clientList.Add(clientObject);
     clientObject.bin = bin;
 }
Пример #14
0
 public tokenType(object parentObject, LQProximityDatabase lqsd)
 {
     this.proxy = new lqClientProxy(parentObject);
     this.lq    = lqsd.lq;
 }
Пример #15
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);
            }
        }
Пример #16
0
 // Removes a given client object from its current bin, unlinking it
 //   from the bin contents list.
 public void lqRemoveFromBin(lqClientProxy clientObject)
 {
     if (clientObject.bin!=null) {
         clientObject.bin.clientList.Remove(clientObject);
     }
 }
Пример #17
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;
 }
Пример #18
0
 // constructor
 public tokenType(System.Object parentObject, LQProximityDatabase lqsd)
 {
     proxy = new lqClientProxy(parentObject);// lqInitClientProxy(proxy, parentObject);
     lq = lqsd.lq;
 }