Exemplo n.º 1
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,
            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);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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.º 4
0
        public override AbstractVehicle getNearestVehicle(Vector3 position, float radius)
        {
            lqClientProxy   tProxy   = lq.lqFindNearestNeighborWithinRadius(position.x, position.y, position.z, radius, null);
            AbstractVehicle tVehicle = null;

            if (tProxy != null)
            {
                tVehicle = (AbstractVehicle)tProxy.clientObject;
            }
            return(tVehicle);
        }
Exemplo n.º 5
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((AbstractVehicle)tProxy.clientObject);
                    //});
                }
            }
Exemplo n.º 6
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.º 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
 // constructor
 public tokenType(Object parentObject, LQProximityDatabase lqsd)
 {
     proxy = new lqClientProxy(parentObject);// lqInitClientProxy(proxy, parentObject);
     lq    = lqsd.lq;
 }
Exemplo n.º 9
0
 // constructor
 public tokenType(Object parentObject, LQProximityDatabase lqsd)
 {
     proxy = new lqClientProxy(parentObject);// lqInitClientProxy(proxy, parentObject);
     lq = lqsd.lq;
 }
Exemplo n.º 10
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.º 11
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);
     }
 }
Exemplo n.º 12
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;
 }