| 46 | namespace |
| 47 | { |
| 48 | OrientedBoundingBox GetWriteBox(const Vector3& min, const Vector3& max, const float margin) |
| 49 | { |
| 50 | OrientedBoundingBox box; |
| 51 | const Vector3 vec = max - min; |
| 52 | const Vector3 dir = Vector3::Normalize(vec); |
| 53 | Quaternion orientation; |
| 54 | if (Vector3::Dot(dir, Vector3::Up) >= 0.999f) |
| 55 | Quaternion::RotationAxis(Vector3::Left, PI_HALF, orientation); |
| 56 | else |
| 57 | Quaternion::LookRotation(dir, Vector3::Cross(Vector3::Cross(dir, Vector3::Up), dir), orientation); |
| 58 | const Vector3 up = orientation * Vector3::Up; |
| 59 | Matrix world; |
| 60 | Matrix::CreateWorld(min + vec * 0.5f, dir, up, world); |
| 61 | world.Decompose(box.Transformation); |
| 62 | Matrix invWorld; |
| 63 | Matrix::Invert(world, invWorld); |
| 64 | Vector3 vecLocal; |
| 65 | Vector3::TransformNormal(vec * 0.5f, invWorld, vecLocal); |
| 66 | box.Extents.X = margin; |
| 67 | box.Extents.Y = margin; |
| 68 | box.Extents.Z = vecLocal.Z; |
| 69 | return box; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void BoxVolume::OnDebugDrawSelected() |
no test coverage detected