Nez.Vector2Ext.getRayIntersection C# (CSharp) Méthode

getRayIntersection() private méthode

private getRayIntersection ( Vector2 a, Vector2 b, Vector2 c, Vector2 d, Vector2 &intersection ) : bool
a Microsoft.Xna.Framework.Vector2
b Microsoft.Xna.Framework.Vector2
c Microsoft.Xna.Framework.Vector2
d Microsoft.Xna.Framework.Vector2
intersection Microsoft.Xna.Framework.Vector2
Résultat bool
		public static bool getRayIntersection( Vector2 a, Vector2 b, Vector2 c, Vector2 d, out Vector2 intersection )
		{
			var dy1 = b.Y - a.Y;
			var dx1 = b.X - a.X;
			var dy2 = d.Y - c.Y;
			var dx2 = d.X - c.X;

			if( dy1 * dx2 == dy2 * dx1 )
			{
				intersection = new Vector2( float.NaN, float.NaN );
				return false;
			}

			var x = ( ( c.Y - a.Y ) * dx1 * dx2 + dy1 * dx2 * a.X - dy2 * dx1 * c.X ) / ( dy1 * dx2 - dy2 * dx1 );
			var y = a.Y + ( dy1 / dx1 ) * ( x - a.X );

			intersection = new Vector2( x, y );
			return true;
		}

Usage Example

Exemple #1
0
        void patchJaggedJoint(ref Segment segment, ref int vertIndex)
        {
            Vector2 intersection;

            if (segment.shouldFuseBottom)
            {
                if (Vector2Ext.getRayIntersection(
                        segment.tl,
                        segment.tr,
                        _lastSegment.tl,
                        _lastSegment.tr,
                        out intersection))
                {
                    addVert(vertIndex++, intersection, new Vector2(1, 1), segment.point.color);

                    _indices.add((short)vertIndex);
                    _indices.add((short)(vertIndex + 4));
                    _indices.add((short)(vertIndex - 1));

                    _indices.add((short)(vertIndex - 1));
                    _indices.add((short)(vertIndex + 4));
                    _indices.add((short)(vertIndex - 5));
                }
            }
            else
            {
                if (Vector2Ext.getRayIntersection(
                        segment.bl,
                        segment.br,
                        _lastSegment.bl,
                        _lastSegment.br,
                        out intersection))
                {
                    var firstSegmentOffset = vertIndex == 5 ? 1 : 0;
                    addVert(vertIndex++, intersection, new Vector2(1, 0), segment.point.color);

                    _indices.add((short)(vertIndex + 4));
                    _indices.add((short)(vertIndex + 3));
                    _indices.add((short)(vertIndex - 1));

                    _indices.add((short)(vertIndex - 3 + firstSegmentOffset));
                    _indices.add((short)(vertIndex + 4));
                    _indices.add((short)(vertIndex - 1));
                }
            }
        }