public BoxFace GetBoxFaceWhichFacesNormal(Vector3 normal) { List <Plane> facePlanes = GetBoxFacePlanes(); int planeIndex; PlaneExtensions.GetPlaneWhichFacesNormal(facePlanes, normal, out planeIndex); return((BoxFace)planeIndex); }
public BoxFace GetBoxFaceMostAlignedWithNormal(Vector3 normal) { List <Plane> facePlanes = GetBoxFacePlanes(); int planeIndex; PlaneExtensions.GetPlaneMostAlignedWithNormal(facePlanes, normal, out planeIndex); return((BoxFace)planeIndex); }
private void CalculateIndexOfStrokeAlignmentSegmentPlane() { int indexOfPointClosestToStrokeSurfacePickPoint = _pivotPointsOfLastPlacedHierarchy.GetIndexOfPointClosestToPoint(_strokeSurface.MouseCursorPickPoint); if (indexOfPointClosestToStrokeSurfacePickPoint != ProjectedBoxFacePivotPoints.IndexOfPointInCenter) { Vector3 pivotPointClosestToStrokeSurfacePickPoint = _pivotPointsOfLastPlacedHierarchy.GetPointByIndex(indexOfPointClosestToStrokeSurfacePickPoint); // Now identify the segment whose center point is closest to the calculated pivot point List <Segment3D> segments = _pivotPointsOfLastPlacedHierarchy.GetAllBoundarySegments(); int indexOfBestSegment = -1; float minDistance = float.MaxValue; for (int segmentIndex = 0; segmentIndex < segments.Count; ++segmentIndex) { Segment3D segment = segments[segmentIndex]; Vector3 segmentMidPoint = segment.GetPoint(0.5f); float distanceFromPivotPoint = (segmentMidPoint - pivotPointClosestToStrokeSurfacePickPoint).magnitude; if (distanceFromPivotPoint < minDistance) { minDistance = distanceFromPivotPoint; indexOfBestSegment = segmentIndex; } } _indexOfStrokeAlignmentSegmentPlane = indexOfBestSegment; } else { Vector3 fromCenterToStrokeSurfacePickPoint = _strokeSurface.MouseCursorPickPoint - _pivotPointsOfLastPlacedHierarchy.CenterPoint; List <Plane> pivotPointBoundarySegmentPlanes = _pivotPointsOfLastPlacedHierarchy.GetAllBoundarySegmentPlanes(); _indexOfStrokeAlignmentSegmentPlane = PlaneExtensions.GetIndexOfPlaneWhoseNormalIsMostAlignedWithDir(pivotPointBoundarySegmentPlanes, fromCenterToStrokeSurfacePickPoint); } /* Left here for reference. This is the way in which it was initially done. * if(indexOfPointClosestToStrokeSurfacePickPoint != ProjectedBoxFacePivotPoints.IndexOfPointInCenter) * { * Vector3 pivotPointClosestToStrokeSurfacePickPoint = _pivotPointsOfLastPlacedHierarchy.GetPointByIndex(indexOfPointClosestToStrokeSurfacePickPoint); * Vector3 fromCenterPivotToCalculatedClosestPoint = pivotPointClosestToStrokeSurfacePickPoint - _pivotPointsOfLastPlacedHierarchy.CenterPoint; * * pivotPointBoundarySegmentPlanes = _pivotPointsOfLastPlacedHierarchy.GetAllBoundarySegmentPlanes(); * _indexOfStrokeAlignmentSegmentPlane = PlaneExtensions.GetIndexOfPlaneWhoseNormalIsMostAlignedWithDir(pivotPointBoundarySegmentPlanes, fromCenterPivotToCalculatedClosestPoint); * } * else * { * fromClosestPointToStrokeSurfacePickPoint = _strokeSurface.MouseCursorPickPoint - _pivotPointsOfLastPlacedHierarchy.CenterPoint; * pivotPointBoundarySegmentPlanes = _pivotPointsOfLastPlacedHierarchy.GetAllBoundarySegmentPlanes(); * _indexOfStrokeAlignmentSegmentPlane = PlaneExtensions.GetIndexOfPlaneWhoseNormalIsMostAlignedWithDir(pivotPointBoundarySegmentPlanes, fromCenterPivotToStrokeSurfacePickPoint); * } */ }
public bool AreAllBoxPointsOnOrInFrontOfAnyFacePlane(OrientedBox otherBox) { List <Vector3> otherBoxPoints = otherBox.GetCenterAndCornerPoints(); List <Plane> allFacePlanes = GetBoxFacePlanes(); foreach (Plane plane in allFacePlanes) { if (PlaneExtensions.AreAllPointsInFrontOrOnPlane(plane, otherBoxPoints)) { return(true); } } return(false); }