FarseerPhysics.Collision.Shapes.CircleShape.rayCast C# (CSharp) Method

rayCast() public method

public rayCast ( RayCastOutput &output, RayCastInput &input, Transform &transform, int childIndex ) : bool
output RayCastOutput
input RayCastInput
transform Transform
childIndex int
return bool
		public override bool rayCast( out RayCastOutput output, ref RayCastInput input, ref Transform transform, int childIndex )
		{
			// Collision Detection in Interactive 3D Environments by Gino van den Bergen
			// From Section 3.1.2
			// x = s + a * r
			// norm(x) = radius

			output = new RayCastOutput();

			var pos = transform.p + MathUtils.mul( transform.q, this.position );
			var s = input.Point1 - pos;
			var b = Vector2.Dot( s, s ) - _2radius;

			// Solve quadratic equation.
			var r = input.Point2 - input.Point1;
			var c = Vector2.Dot( s, r );
			var rr = Vector2.Dot( r, r );
			var sigma = c * c - rr * b;

			// Check for negative discriminant and short segment.
			if( sigma < 0.0f || rr < Settings.epsilon )
				return false;

			// Find the point of intersection of the line with the circle.
			float a = -( c + (float)Math.Sqrt( sigma ) );

			// Is the intersection point on the segment?
			if( 0.0f <= a && a <= input.MaxFraction * rr )
			{
				a /= rr;
				output.Fraction = a;

				//TODO: Check results here
				output.Normal = s + a * r;
				output.Normal.Normalize();
				return true;
			}

			return false;
		}