Пример #1
0
        /// <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>
        ///     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);
        }