Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
예제 #1
0
 public void Set(RayCastInput rci)
 {
     P1.Set(rci.P1);
     P2.Set(rci.P2);
     MaxFraction = rci.MaxFraction;
 }
예제 #2
0
파일: World.cs 프로젝트: thdtjsdn/box2dnet
        public virtual float raycastCallback(RayCastInput input, int nodeId)
        {
            Object userData = broadPhase.getUserData(nodeId);
            FixtureProxy proxy = (FixtureProxy)userData;
            Fixture fixture = proxy.fixture;
            int index = proxy.childIndex;
            bool hit = fixture.raycast(output, input, index);

            if (hit)
            {
                float fraction = output.fraction;
                // Vec2 point = (1.0f - fraction) * input.p1 + fraction * input.p2;
                temp.set_Renamed(input.p2).mulLocal(fraction);
                point.set_Renamed(input.p1).mulLocal(1 - fraction).addLocal(temp);
                return callback.reportFixture(fixture, point, output.normal, fraction);
            }

            return input.maxFraction;
        }
예제 #3
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);
 }
예제 #4
0
        public float RaycastCallback(RayCastInput input, int nodeId)
        {
            Object userData = BroadPhase.GetUserData(nodeId);
            FixtureProxy proxy = (FixtureProxy)userData;
            Fixture fixture = proxy.Fixture;
            int index = proxy.ChildIndex;
            bool hit = fixture.Raycast(output, input, index);

            if (hit)
            {
                float fraction = output.Fraction;
                // Vec2 point = (1.0f - fraction) * input.p1 + fraction * input.p2;
                temp.Set(input.P2).MulLocal(fraction);
                point.Set(input.P1).MulLocal(1 - fraction).AddLocal(temp);
                return Callback.ReportFixture(fixture, point, output.Normal, fraction);
            }

            return input.MaxFraction;
        }
예제 #5
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;
        }
예제 #6
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));
 }
예제 #7
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);
 }
예제 #8
0
 public virtual void set_Renamed(RayCastInput rci)
 {
     p1.set_Renamed(rci.p1);
     p2.set_Renamed(rci.p2);
     maxFraction = rci.maxFraction;
 }
예제 #9
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;
        }