/// <summary> /// Construct a collision part from a plane. /// </summary> /// <param name="p">A point with which the plane intersects.</param> /// <param name="normal">The plane normal.</param> public PlanePart(Vector3 p, Vector3 normal) { this._point = p; this._normal = normal; Plane = new Plane(p, normal); }
/// <summary> /// Intersects a segment with this collision skin part and returns the intersection point that is nearest to the /// beginning of the segment. /// </summary> /// <param name="segment">The segment to intersect with.</param> /// <param name="scalar">Returns a value between 0 and 1 indicating where on the segment the first intersection occurs.</param> /// <param name="point">Returns the point of the first intersection.</param> /// <returns>Returns a value indicating whether the segment intersects with the part.</returns> public override bool Intersect(ref Segment segment, out float scalar, out Vector3 point) { scalar = float.PositiveInfinity; point = Vector3.Zero; float scalar1; Vector3 point1; for (int i = 0; i < FaceCount; i++) { var face = Face(i); Vector3 p0; World(face[0], out p0); var plane = new Plane(p0, _faceNormals[i]); if (plane.Intersect(ref segment, out scalar1, out point1) && scalar1 < scalar && IsPointOnFace(i, ref point1, true)) { scalar = scalar1; point = point1; } } return !float.IsPositiveInfinity(scalar); }