Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2 come from b2RayCastInput.
示例#1
0
 /// <summary>
 /// Cast a ray against this shape.
 /// </summary>
 /// <param name="output">the ray-cast results.</param>
 /// <param name="input">the ray-cast input parameters.</param>
 /// <param name="childIndex"></param>
 public bool Raycast(RayCastOutput output, RayCastInput input, int childIndex)
 {
     return Shape.Raycast(output, input, Body.Xf, childIndex);
 }
示例#2
0
文件: AABB.cs 项目: thdtjsdn/box2dnet
 /// <deprecated> please use {@link #raycast(RayCastOutput, RayCastInput, IWorldPool)} for better performance
 /// </deprecated>
 /// <param name="output"></param>
 /// <param name="input"></param>
 /// <returns></returns>
 public bool raycast(RayCastOutput output, RayCastInput input)
 {
     return raycast(output, input, new DefaultWorldPool(4, 4));
 }
示例#3
0
文件: AABB.cs 项目: thdtjsdn/box2dnet
        /// <summary>
        /// From Real-time Collision Detection, p179.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="input"></param>
        public bool raycast(RayCastOutput output, RayCastInput input, IWorldPool argPool)
        {
            //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Float.MIN_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
            float tmin = Single.Epsilon;
            float tmax = Single.MaxValue;

            Vec2 p = argPool.popVec2();
            Vec2 d = argPool.popVec2();
            Vec2 absD = argPool.popVec2();
            Vec2 normal = argPool.popVec2();

            p.set_Renamed(input.p1);
            d.set_Renamed(input.p2).subLocal(input.p1);
            Vec2.absToOut(d, absD);

            // x then y
            if (absD.x < Settings.EPSILON)
            {
                // Parallel.
                if (p.x < lowerBound.x || upperBound.x < p.x)
                {
                    argPool.pushVec2(4);
                    return false;
                }
            }
            else
            {
                float inv_d = 1.0f / d.x;
                float t1 = (lowerBound.x - p.x) * inv_d;
                float t2 = (upperBound.x - p.x) * inv_d;

                // Sign of the normal vector.
                float s = -1.0f;

                if (t1 > t2)
                {
                    float temp = t1;
                    t1 = t2;
                    t2 = temp;
                    s = 1.0f;
                }

                // Push the min up
                if (t1 > tmin)
                {
                    normal.setZero();
                    normal.x = s;
                    tmin = t1;
                }

                // Pull the max down
                tmax = MathUtils.min(tmax, t2);

                if (tmin > tmax)
                {
                    argPool.pushVec2(4);
                    return false;
                }
            }

            if (absD.y < Settings.EPSILON)
            {
                // Parallel.
                if (p.y < lowerBound.y || upperBound.y < p.y)
                {
                    argPool.pushVec2(4);
                    return false;
                }
            }
            else
            {
                float inv_d = 1.0f / d.y;
                float t1 = (lowerBound.y - p.y) * inv_d;
                float t2 = (upperBound.y - p.y) * inv_d;

                // Sign of the normal vector.
                float s = -1.0f;

                if (t1 > t2)
                {
                    float temp = t1;
                    t1 = t2;
                    t2 = temp;
                    s = 1.0f;
                }

                // Push the min up
                if (t1 > tmin)
                {
                    normal.setZero();
                    normal.y = s;
                    tmin = t1;
                }

                // Pull the max down
                tmax = MathUtils.min(tmax, t2);

                if (tmin > tmax)
                {
                    argPool.pushVec2(4);
                    return false;
                }
            }

            // Does the ray start inside the box?
            // Does the ray intersect beyond the max fraction?
            if (tmin < 0.0f || input.maxFraction < tmin)
            {
                argPool.pushVec2(4);
                return false;
            }

            // Intersection.
            output.fraction = tmin;
            output.normal.x = normal.x;
            output.normal.y = normal.y;
            argPool.pushVec2(4);
            return true;
        }
示例#4
0
        /// <summary>
        /// From Real-time Collision Detection, p179.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="input"></param>
        /// <param name="argPool"></param>
        public bool Raycast(RayCastOutput output, RayCastInput input, IWorldPool argPool)
        {
            //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Float.MIN_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
            float tmin = Single.Epsilon;
            float tmax = Single.MaxValue;

            Vec2 p      = argPool.PopVec2();
            Vec2 d      = argPool.PopVec2();
            Vec2 absD   = argPool.PopVec2();
            Vec2 normal = argPool.PopVec2();

            p.Set(input.P1);
            d.Set(input.P2).SubLocal(input.P1);
            Vec2.AbsToOut(d, absD);

            // x then y
            if (absD.X < Settings.EPSILON)
            {
                // Parallel.
                if (p.X < LowerBound.X || UpperBound.X < p.X)
                {
                    argPool.PushVec2(4);
                    return(false);
                }
            }
            else
            {
                float inv_d = 1.0f / d.X;
                float t1    = (LowerBound.X - p.X) * inv_d;
                float t2    = (UpperBound.X - p.X) * inv_d;

                // Sign of the normal vector.
                float s = -1.0f;

                if (t1 > t2)
                {
                    float temp = t1;
                    t1 = t2;
                    t2 = temp;
                    s  = 1.0f;
                }

                // Push the min up
                if (t1 > tmin)
                {
                    normal.SetZero();
                    normal.X = s;
                    tmin     = t1;
                }

                // Pull the max down
                tmax = MathUtils.Min(tmax, t2);

                if (tmin > tmax)
                {
                    argPool.PushVec2(4);
                    return(false);
                }
            }

            if (absD.Y < Settings.EPSILON)
            {
                // Parallel.
                if (p.Y < LowerBound.Y || UpperBound.Y < p.Y)
                {
                    argPool.PushVec2(4);
                    return(false);
                }
            }
            else
            {
                float inv_d = 1.0f / d.Y;
                float t1    = (LowerBound.Y - p.Y) * inv_d;
                float t2    = (UpperBound.Y - p.Y) * inv_d;

                // Sign of the normal vector.
                float s = -1.0f;

                if (t1 > t2)
                {
                    float temp = t1;
                    t1 = t2;
                    t2 = temp;
                    s  = 1.0f;
                }

                // Push the min up
                if (t1 > tmin)
                {
                    normal.SetZero();
                    normal.Y = s;
                    tmin     = t1;
                }

                // Pull the max down
                tmax = MathUtils.Min(tmax, t2);

                if (tmin > tmax)
                {
                    argPool.PushVec2(4);
                    return(false);
                }
            }

            // Does the ray start inside the box?
            // Does the ray intersect beyond the max fraction?
            if (tmin < 0.0f || input.MaxFraction < tmin)
            {
                argPool.PushVec2(4);
                return(false);
            }

            // Intersection.
            output.Fraction = tmin;
            output.Normal.X = normal.X;
            output.Normal.Y = normal.Y;
            argPool.PushVec2(4);
            return(true);
        }
示例#5
0
 public virtual void set_Renamed(RayCastOutput rco)
 {
     normal.set_Renamed(rco.normal);
     fraction = rco.fraction;
 }
示例#6
0
 /// <deprecated> please use {@link #raycast(RayCastOutput, RayCastInput, IWorldPool)} for better performance
 /// </deprecated>
 /// <param name="output"></param>
 /// <param name="input"></param>
 /// <returns></returns>
 public bool Raycast(RayCastOutput output, RayCastInput input)
 {
     return(Raycast(output, input, new DefaultWorldPool(4, 4)));
 }
示例#7
0
 public void Set(RayCastOutput rco)
 {
     Normal.Set(rco.Normal);
     Fraction = rco.Fraction;
 }
示例#8
0
 /// <summary>
 /// Cast a ray against this shape.
 /// </summary>
 /// <param name="output">the ray-cast results.</param>
 /// <param name="input">the ray-cast input parameters.</param>
 /// <param name="output"></param>
 /// <param name="input"></param>
 public virtual bool raycast(RayCastOutput output, RayCastInput input, int childIndex)
 {
     return m_shape.raycast(output, input, m_body.m_xf, childIndex);
 }
示例#9
0
 public void Set(RayCastOutput rco)
 {
     Normal.Set(rco.Normal);
     Fraction = rco.Fraction;
 }
示例#10
0
        /// <summary>
        /// From Real-time Collision Detection, p179.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="input"></param>
        /// <param name="argPool"></param>
        public bool Raycast(RayCastOutput output, RayCastInput input, IWorldPool argPool)
        {
            //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Float.MIN_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
            float tmin = Single.Epsilon;
            float tmax = Single.MaxValue;

            Vec2 p = argPool.PopVec2();
            Vec2 d = argPool.PopVec2();
            Vec2 absD = argPool.PopVec2();
            Vec2 normal = argPool.PopVec2();

            p.Set(input.P1);
            d.Set(input.P2).SubLocal(input.P1);
            Vec2.AbsToOut(d, absD);

            // x then y
            if (absD.X < Settings.EPSILON)
            {
                // Parallel.
                if (p.X < LowerBound.X || UpperBound.X < p.X)
                {
                    argPool.PushVec2(4);
                    return false;
                }
            }
            else
            {
                float inv_d = 1.0f / d.X;
                float t1 = (LowerBound.X - p.X) * inv_d;
                float t2 = (UpperBound.X - p.X) * inv_d;

                // Sign of the normal vector.
                float s = -1.0f;

                if (t1 > t2)
                {
                    float temp = t1;
                    t1 = t2;
                    t2 = temp;
                    s = 1.0f;
                }

                // Push the min up
                if (t1 > tmin)
                {
                    normal.SetZero();
                    normal.X = s;
                    tmin = t1;
                }

                // Pull the max down
                tmax = MathUtils.Min(tmax, t2);

                if (tmin > tmax)
                {
                    argPool.PushVec2(4);
                    return false;
                }
            }

            if (absD.Y < Settings.EPSILON)
            {
                // Parallel.
                if (p.Y < LowerBound.Y || UpperBound.Y < p.Y)
                {
                    argPool.PushVec2(4);
                    return false;
                }
            }
            else
            {
                float inv_d = 1.0f / d.Y;
                float t1 = (LowerBound.Y - p.Y) * inv_d;
                float t2 = (UpperBound.Y - p.Y) * inv_d;

                // Sign of the normal vector.
                float s = -1.0f;

                if (t1 > t2)
                {
                    float temp = t1;
                    t1 = t2;
                    t2 = temp;
                    s = 1.0f;
                }

                // Push the min up
                if (t1 > tmin)
                {
                    normal.SetZero();
                    normal.Y = s;
                    tmin = t1;
                }

                // Pull the max down
                tmax = MathUtils.Min(tmax, t2);

                if (tmin > tmax)
                {
                    argPool.PushVec2(4);
                    return false;
                }
            }

            // Does the ray start inside the box?
            // Does the ray intersect beyond the max fraction?
            if (tmin < 0.0f || input.MaxFraction < tmin)
            {
                argPool.PushVec2(4);
                return false;
            }

            // Intersection.
            output.Fraction = tmin;
            output.Normal.X = normal.X;
            output.Normal.Y = normal.Y;
            argPool.PushVec2(4);
            return true;
        }