/// <summary>
        ///     Queues a raycast
        /// </summary>
        /// <param name="position">Origin of Ray</param>
        /// <param name="direction">Ray normal</param>
        /// <param name="length">Ray length</param>
        /// <param name="retMethod">Return method to send the results</param>
        public void QueueRequest(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
        {
            lock (m_PendingRequests)
            {
                ODERayCastRequest req = new ODERayCastRequest
                                            {
                                                callbackMethod = retMethod,
                                                length = length,
                                                Normal = direction,
                                                Origin = position
                                            };

                m_PendingRequests.Add(req);
            }
        }
        /// <summary>
        ///     Method that actually initiates the raycast
        /// </summary>
        /// <param name="req"></param>
        private void RayCast(ODERayCastRequest req)
        {
            // Create the ray
            IntPtr ray = d.CreateRay(m_scene.space, req.length);
            d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);

            // Collide test
            d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);

            // Remove Ray
            d.GeomDestroy(ray);

            // Define default results
            bool hitYN = false;
            uint hitConsumerID = 0;
            float distance = 999999999999f;
            Vector3[] closestcontact = {new Vector3(99999f, 99999f, 99999f)};
            Vector3 snormal = Vector3.Zero;

            // Find closest contact and object.
            lock (m_contactResults)
            {
                foreach (
                    ContactResult cResult in
                        m_contactResults.Where(
                            cResult =>
                            Vector3.Distance(req.Origin, cResult.Pos) < Vector3.Distance(req.Origin, closestcontact[0]))
                    )
                {
                    closestcontact[0] = cResult.Pos;
                    hitConsumerID = cResult.ConsumerID;
                    distance = cResult.Depth;
                    hitYN = true;
                    snormal = cResult.Normal;
                }

                m_contactResults.Clear();
            }

            // Return results
            if (req.callbackMethod != null)
                req.callbackMethod(hitYN, closestcontact[0], hitConsumerID, distance, snormal);
        }
        /// <summary>
        ///     Process all queued raycast requests
        /// </summary>
        /// <returns>Time in MS the raycasts took to process.</returns>
        public int ProcessQueuedRequests()
        {
            int time = Environment.TickCount;
            ODERayCastRequest[] reqs = new ODERayCastRequest[0];
            lock (m_PendingRequests)
            {
                if (m_PendingRequests.Count > 0)
                {
                    reqs = m_PendingRequests.ToArray();
                    m_PendingRequests.Clear();
                }
            }
            for (int i = 0; i < reqs.Length; i++)
            {
                if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
                    RayCast(reqs[i]); // if there isn't anyone to send results
            }

            ODERayRequest[] rayReqs = new ODERayRequest[0];
            lock (m_PendingRayRequests)
            {
                if (m_PendingRayRequests.Count > 0)
                {
                    rayReqs = m_PendingRayRequests.ToArray();
                    m_PendingRayRequests.Clear();
                }
            }
            for (int i = 0; i < rayReqs.Length; i++)
            {
                if (rayReqs[i].callbackMethod != null) // quick optimization here, don't raycast
                    RayCast(rayReqs[i]); // if there isn't anyone to send results
            }

            lock (m_contactResults)
                m_contactResults.Clear();

            return Environment.TickCount - time;
        }