public void Encapsulate(OBB otherOBB) { var otherPts = BoxMath.CalcBoxCornerPoints(otherOBB.Center, otherOBB.Size, otherOBB.Rotation); Matrix4x4 transformMtx = Matrix4x4.TRS(Center, Rotation, Vector3.one); var modelPts = transformMtx.inverse.TransformPoints(otherPts); AABB modelAABB = new AABB(Vector3.zero, Size); modelAABB.Encapsulate(modelPts); Center = (Rotation * modelAABB.Center) + Center; Size = modelAABB.Size; }
private void SnapToObjectHitPoint(GameObjectRayHit objectHit, SnapToPointMode snapMode) { if (snapMode == SnapToPointMode.Exact) { float distToPlane = new Plane(Normal, Vector3.zero).GetDistanceToPoint(objectHit.HitPoint); YOffset = distToPlane; } else { var boundsQConfig = new ObjectBounds.QueryConfig(); boundsQConfig.ObjectTypes = GameObjectType.Mesh; OBB worldOBB = ObjectBounds.CalcWorldOBB(objectHit.HitObject, boundsQConfig); if (worldOBB.IsValid) { Plane slicePlane = new Plane(Normal, worldOBB.Center); Vector3 destPt = worldOBB.Center; var obbCorners = BoxMath.CalcBoxCornerPoints(worldOBB.Center, worldOBB.Size, worldOBB.Rotation); float sign = Mathf.Sign(slicePlane.GetDistanceToPoint(objectHit.HitPoint)); if (sign > 0.0f) { int furthestPtInFront = slicePlane.GetFurthestPtInFront(obbCorners); if (furthestPtInFront >= 0) { destPt = obbCorners[furthestPtInFront]; } } else { int furthestPtBehind = slicePlane.GetFurthestPtBehind(obbCorners); if (furthestPtBehind >= 0) { destPt = obbCorners[furthestPtBehind]; } } float distToPlane = new Plane(Normal, Vector3.zero).GetDistanceToPoint(destPt); YOffset = distToPlane; } } }
public List <Vector3> GetCornerPoints() { return(BoxMath.CalcBoxCornerPoints(_center, _size, Quaternion.identity)); }
public List <Vector3> GetCornerPoints() { return(BoxMath.CalcBoxCornerPoints(_center, _size, _rotation)); }