コード例 #1
0
        /// <summary>
        ///     Method that actually initiates the raycast
        /// </summary>
        /// <param name="req"></param>
        void RayCast(ODERayRequest 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);

            // Find closest contact and object.
            lock (m_contactResults)
            {
                m_contactResults.Sort(delegate(ContactResult a, ContactResult b)
                {
                    return(a.Depth.CompareTo(b.Depth));
                });

                // Return results
                if (req.CallbackMethod != null)
                {
                    req.CallbackMethod(m_contactResults.Take(req.Count).ToList());
                }
            }
        }
コード例 #2
0
        /// <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="count">Ray count</param>
        /// <param name="retMethod">Return method to send the results</param>
        public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
        {
            lock (m_PendingRayRequests)
            {
                ODERayRequest req = new ODERayRequest
                {
                    CallbackMethod = retMethod,
                    Length         = length,
                    Normal         = direction,
                    Origin         = position,
                    Count          = count
                };

                m_PendingRayRequests.Add(req);
            }
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <summary>
        ///     Method that actually initiates the raycast
        /// </summary>
        /// <param name="req"></param>
        void RayCast(ODERayRequest 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);

            // Find closest contact and object.
            lock (m_contactResults)
            {
                m_contactResults.Sort(delegate(ContactResult a, ContactResult b)
                {
                    return a.Depth.CompareTo(b.Depth);
                });
                
                // Return results
                if (req.CallbackMethod != null)
                    req.CallbackMethod(m_contactResults.Take(req.Count).ToList());
            }
        }
コード例 #5
0
        /// <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;
        }
コード例 #6
0
        /// <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="count">Ray count</param>
        /// <param name="retMethod">Return method to send the results</param>
        public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
        {
            lock (m_PendingRayRequests)
            {
                ODERayRequest req = new ODERayRequest
                                        {
                                            CallbackMethod = retMethod,
                                            Length = length,
                                            Normal = direction,
                                            Origin = position,
                                            Count = count
                                        };

                m_PendingRayRequests.Add(req);
            }
        }