Exemple #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,
            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);
        }
Exemple #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);
     }
 }
Exemple #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);
        }
Exemple #4
0
            // find all neighbors within the given sphere (as center and radius)
            public override void FindNeighbors(Vector3 center, float radius, ref List <ProximityDatabaseItem> results)
            {
                ArrayList tList = lq.GetAllObjectsInLocality(center.x, center.y, center.z, radius);

                for (int i = 0; i < tList.Count; i++)
                {
                    LqClientProxy tProxy = (LqClientProxy)tList[i];
                    results.Add(tProxy.clientObject);
                }
            }
Exemple #5
0
        public override ProximityDatabaseItem GetNearestVehicle(Vector3 position, float radius)
        {
            LqClientProxy         tProxy = lq.LqFindNearestNeighborWithinRadius(position.x, position.y, position.z, radius, null);
            ProximityDatabaseItem tItem  = null;

            if (tProxy != null)
            {
                tItem = tProxy.clientObject;
            }

            return(tItem);
        }
Exemple #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);
            }
        }
Exemple #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;
 }
Exemple #8
0
 // constructor
 public TokenType(ProximityDatabaseItem parentObject, LQProximityDatabase lqsd)
 {
     proxy = new LqClientProxy(parentObject);
     lq    = lqsd.lq;
 }