public bool TryGetIntersection(Vector2D point, out IntersectionInfo result) { ContainmentType contains; rect.Contains(ref point, out contains); if (contains == ContainmentType.Contains) { int x = (int)Math.Floor((point.X - rect.Min.X) * gridSpacingInv); int y = (int)Math.Floor((point.Y - rect.Min.Y) * gridSpacingInv); Scalar bottomLeft = nodes[x][y]; Scalar bottomRight = nodes[x + 1][y]; Scalar topLeft = nodes[x][y + 1]; Scalar topRight = nodes[x + 1][y + 1]; if (bottomLeft <= 0 || bottomRight <= 0 || topLeft <= 0 || topRight <= 0) { Scalar xPercent = (point.X - (gridSpacing * x + rect.Min.X)) * gridSpacingInv; Scalar yPercent = (point.Y - (gridSpacing * y + rect.Min.Y)) * gridSpacingInv; Scalar top, bottom, distance; MathHelper.Lerp(ref topLeft, ref topRight, ref xPercent, out top); MathHelper.Lerp(ref bottomLeft, ref bottomRight, ref xPercent, out bottom); MathHelper.Lerp(ref bottom, ref top, ref yPercent, out distance); if (distance <= 0) { Scalar right, left; MathHelper.Lerp(ref bottomRight, ref topRight, ref yPercent, out right); MathHelper.Lerp(ref bottomLeft, ref topLeft, ref yPercent, out left); Vector2D normal; normal.X = right - left; normal.Y = top - bottom; //Vector2D.Normalize(ref normal, out result.Normal); result.rawNormal = normal; result.normalized = false; result.Position = point; result.Distance = distance; return(true); } } } result = IntersectionInfo.Zero; return(false); }
public bool TryGetIntersection(Vector2D point, out IntersectionInfo result) { ContainmentType contains; rect.Contains(ref point,out contains); if (contains == ContainmentType.Contains) { int x = (int)Math.Floor((point.X - rect.Min.X) * gridSpacingInv); int y = (int)Math.Floor((point.Y - rect.Min.Y) * gridSpacingInv); Scalar bottomLeft = nodes[x][y]; Scalar bottomRight = nodes[x + 1][y]; Scalar topLeft = nodes[x][y + 1]; Scalar topRight = nodes[x + 1][y + 1]; if (bottomLeft <= 0 || bottomRight <= 0 || topLeft <= 0 || topRight <= 0) { Scalar xPercent = (point.X - (gridSpacing * x + rect.Min.X)) * gridSpacingInv; Scalar yPercent = (point.Y - (gridSpacing * y + rect.Min.Y)) * gridSpacingInv; Scalar top, bottom, distance; MathHelper.Lerp(ref topLeft, ref topRight, ref xPercent, out top); MathHelper.Lerp(ref bottomLeft, ref bottomRight, ref xPercent, out bottom); MathHelper.Lerp(ref bottom, ref top, ref yPercent, out distance); if (distance <= 0) { Scalar right, left; MathHelper.Lerp(ref bottomRight, ref topRight, ref yPercent, out right); MathHelper.Lerp(ref bottomLeft, ref topLeft, ref yPercent, out left); Vector2D normal; normal.X = right - left; normal.Y = top - bottom; Vector2D.Normalize(ref normal, out result.Normal); result.Position = point; result.Distance = distance; return true; } } } result = IntersectionInfo.Zero; return false; }
public override bool TryGetIntersection(Vector2D vector, out IntersectionInfo info) { if (grid == null) { throw new NotSupportedException(); } Vector2D local; Vector2D.Transform(ref matrix2DInv.VertexMatrix, ref vector, out local); if (grid.TryGetIntersection(local, out info)) { Vector2D.Transform(ref matrix2D.NormalMatrix, ref info.normal, out info.normal); info.location = vector; return true; } return false; }
public bool TryGetIntersection(Vector2D vector, out IntersectionInfo result) { if (BoundingBox2D.TestIntersection(ref box, ref vector)) { int x = (int)Math.Floor((vector.X - box.Lower.X) * gridSpacingInv); int y = (int)Math.Floor((vector.Y - box.Lower.Y) * gridSpacingInv); Scalar bottomLeft = nodes[x, y]; Scalar bottomRight = nodes[x + 1, y]; Scalar topLeft = nodes[x, y + 1]; Scalar topRight = nodes[x + 1, y + 1]; if (bottomLeft <= 0 || bottomRight <= 0 || topLeft <= 0 || topRight <= 0) { Scalar xPercent = (vector.X - (gridSpacing * x + box.Lower.X)) * gridSpacingInv; Scalar yPercent = (vector.Y - (gridSpacing * y + box.Lower.Y)) * gridSpacingInv; Scalar top, bottom, distance; MathHelper.Lerp(ref topLeft, ref topRight, ref xPercent, out top); MathHelper.Lerp(ref bottomLeft, ref bottomRight, ref xPercent, out bottom); MathHelper.Lerp(ref bottom, ref top, ref yPercent, out distance); if (distance <= 0) { Scalar right, left; MathHelper.Lerp(ref bottomRight, ref topRight, ref yPercent, out right); MathHelper.Lerp(ref bottomLeft, ref topLeft, ref yPercent, out left); Vector2D normal; normal.X = right - left; normal.Y = top - bottom; Vector2D.Normalize(ref normal, out normal); result = new IntersectionInfo(vector, normal, distance); return true; } } } result = null; return false; }
public override bool TryGetIntersection(Vector2D vector, out IntersectionInfo info) { Scalar result; Vector2D normal; Vector2D.Subtract(ref vector, ref position, out normal); Vector2D.Normalize(ref normal, out result, out normal); result -= radius; if (result <= 0) { info = new IntersectionInfo(vector, normal, result); return true; } info = null; return false; }
public override bool TryGetIntersection(Vector2D vector, out IntersectionInfo info) { throw new NotSupportedException(); }