1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #include "../MathGeoLibFwd.h"21 #include "../Math/float3.h"22 23 [MATH_BEGIN_NAMESPACE]24 25 26 27 28 29 30 class [OBB]31 {32 public:33 34 35 36 vec [pos];37 38 39 40 vec [r];41 42 43 44 45 46 47 48 49 vec [axis][3];50 51 52 53 54 55 [OBB]() {}56 57 58 59 [OBB](const vec &[pos], const vec &[r], const vec &axis0, const vec &axis1, const vec &axis2);60 61 62 63 64 65 66 67 68 [OBB](const [AABB] &aabb);69 70 [FORCE_INLINE] static int [NumFaces]() { return 6; }71 [FORCE_INLINE] static int [NumEdges]() { return 12; }72 [FORCE_INLINE] static int [NumVertices]() { return 8; }73 74 75 76 77 78 void [SetNegativeInfinity]();79 80 81 82 83 84 85 86 void [SetFrom](const [AABB] &aabb);87 88 89 90 void [SetFrom](const [AABB] &aabb, const [float3x3] &transform);91 void [SetFrom](const [AABB] &aabb, const [float3x4] &transform);92 void [SetFrom](const [AABB] &aabb, const [float4x4] &transform);93 void [SetFrom](const [AABB] &aabb, const [Quat] &transform);94 95 96 97 98 99 void [SetFrom](const [Sphere] &sphere);100 101 #ifdef MATH_CONTAINERLIB_SUPPORT102 103 104 105 106 107 bool [SetFrom](const [Polyhedron] &polyhedron);108 #endif109 110 #if 0111 112 113 114 115 116 void SetFromApproximate(const vec *pointArray, int numPoints);117 #endif118 119 120 121 122 123 [Polyhedron] [ToPolyhedron]() const;124 125 126 127 128 129 [PBVolume<6>] [ToPBVolume]() const;130 131 132 133 134 135 136 [AABB] [MinimalEnclosingAABB]() const;137 138 #if 0139 140 141 142 143 [AABB] MaximalContainedAABB() const;144 #endif145 146 147 148 149 [Sphere] [MinimalEnclosingSphere]() const;150 151 152 153 154 155 [Sphere] [MaximalContainedSphere]() const;156 157 158 159 vec [Size]() const;160 161 162 163 164 vec [HalfSize]() const;165 166 167 168 169 170 vec [Diagonal]() const;171 172 173 174 vec [HalfDiagonal]() const;175 176 177 178 179 180 181 182 183 184 [float3x4] [WorldToLocal]() const;185 186 187 188 189 190 [float3x4] [LocalToWorld]() const;191 192 193 194 195 bool [IsFinite]() const;196 197 198 199 200 201 202 203 bool [IsDegenerate]() const;204 205 206 207 208 vec [CenterPoint]() const;209 210 211 212 213 vec [Centroid]() const { return [CenterPoint](); }214 215 inline vec [AnyPointFast]() const { return [pos]; }216 217 218 219 float [Volume]() const;220 221 222 223 float [SurfaceArea]() const;224 225 226 227 228 229 230 231 vec [PointInside](float x, float y, float z) const;232 233 234 235 236 237 [LineSegment] [Edge](int edgeIndex) const;238 239 240 241 242 243 244 245 vec [CornerPoint](int cornerIndex) const;246 247 248 249 250 251 252 253 254 255 vec [ExtremePoint](const vec &direction) const;256 vec [ExtremePoint](const vec &direction, float &projectionDistance) const;257 258 259 260 261 262 263 264 265 void [ProjectToAxis](const vec &direction, float &outMin, float &outMax) const;266 267 int [UniqueFaceNormals](vec *out) const;268 int [UniqueEdgeDirections](vec *out) const;269 270 271 272 273 274 vec [PointOnEdge](int edgeIndex, float u) const;275 276 277 278 279 280 vec [FaceCenterPoint](int faceIndex) const;281 282 283 284 285 286 287 288 vec [FacePoint](int faceIndex, float u, float v) const;289 290 291 292 293 294 295 [Plane] [FacePlane](int faceIndex) const;296 297 298 299 300 void [GetCornerPoints](vec *outPointArray) const;301 302 303 304 305 void [GetFacePlanes]([Plane] *outPlaneArray) const;306 307 308 309 310 311 312 313 314 315 static void [ExtremePointsAlongDirection](const vec &dir, const vec *pointArray, int numPoints, int &idxSmallest, int &idxLargest);316 317 #if 0318 319 320 321 322 323 324 static [OBB] PCAEnclosingOBB(const vec *pointArray, int numPoints);325 #endif326 327 328 static [OBB] [OptimalEnclosingOBB](const vec *pointArray, int numPoints);329 330 331 332 333 vec [RandomPointInside]([LCG] &rng) const;334 335 336 337 338 vec [RandomPointOnSurface]([LCG] &rng) const;339 340 341 342 343 vec [RandomPointOnEdge]([LCG] &rng) const;344 345 346 347 348 vec [RandomCornerPoint]([LCG] &rng) const;349 350 351 352 353 void [Translate](const vec &offset);354 355 356 357 358 359 360 361 void [Scale](const vec ¢erPoint, float scaleFactor);362 363 364 365 366 367 368 369 void [Scale](const vec ¢erPoint, const vec &scaleFactor);370 371 372 373 374 375 376 void [Transform](const [float3x3] &transform);377 void [Transform](const [float3x4] &transform);378 void [Transform](const [float4x4] &transform);379 void [Transform](const [Quat] &transform);380 381 382 383 384 385 vec [ClosestPoint](const vec &point) const;386 387 388 389 390 391 392 float [Distance](const vec &point) const;393 float [Distance](const [Sphere] &sphere) const;394 395 396 397 398 399 400 401 bool [Contains](const vec &point) const;402 bool [Contains](const [LineSegment] &lineSegment) const;403 bool [Contains](const [AABB] &aabb) const;404 bool [Contains](const [OBB] &obb) const;405 bool [Contains](const [Triangle] &triangle) const;406 bool [Contains](const [Polygon] &polygon) const;407 bool [Contains](const [Frustum] &frustum) const;408 bool [Contains](const [Polyhedron] &polyhedron) const;409 410 411 412 413 414 415 416 417 418 419 420 421 422 bool [Intersects](const [OBB] &obb, float [epsilon] = 1[e]-3f) const;423 bool [Intersects](const [AABB] &aabb) const;424 bool [Intersects](const [Plane] &plane) const;425 426 427 428 429 bool [Intersects](const [Ray] &ray, float &dNear, float &dFar) const;430 bool [Intersects](const [Ray] &ray) const;431 bool [Intersects](const [Line] &line, float &dNear, float &dFar) const;432 bool [Intersects](const [Line] &line) const;433 bool [Intersects](const [LineSegment] &lineSegment, float &dNear, float &dFar) const;434 bool [Intersects](const [LineSegment] &lineSegment) const;435 436 437 bool [Intersects](const [Sphere] &sphere, vec *closestPointOnOBB = 0) const;438 bool [Intersects](const [Capsule] &capsule) const;439 bool [Intersects](const [Triangle] &triangle) const;440 bool [Intersects](const [Polygon] &polygon) const;441 bool [Intersects](const [Frustum] &frustum) const;442 bool [Intersects](const [Polyhedron] &polyhedron) const;443 444 445 446 447 void [Enclose](const vec &point);448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 void [Triangulate](int numFacesX, int numFacesY, int numFacesZ, vec *outPos, vec *outNormal, [float2] *outUV, bool ccwIsFrontFacing) const;464 465 466 467 static int [NumVerticesInTriangulation](int numFacesX, int numFacesY, int numFacesZ)468 {469 return (numFacesX*numFacesY + numFacesX*numFacesZ + numFacesY*numFacesZ)*2*6;470 }471 472 473 474 475 void [ToEdgeList](vec *outPos) const;476 477 478 479 static int [NumVerticesInEdgeList]()480 {481 return 4*3*2;482 }483 484 #ifdef MATH_ENABLE_STL_SUPPORT485 486 487 std::string [ToString]() const;488 std::string [SerializeToString]() const;489 490 491 std::string [SerializeToCodeString]() const;492 #endif493 494 static [OBB] [FromString](const char *str, const char **outEndStr = 0);495 #ifdef MATH_ENABLE_STL_SUPPORT496 static [OBB] [FromString](const std::string &str) { return [FromString](str.c_str()); }497 #endif498 499 #ifdef MATH_QT_INTEROP500 operator QString() const { return toString(); }501 QString toString() const { return QString::fromStdString([ToString]()); }502 #endif503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 #ifdef MATH_GRAPHICSENGINE_INTEROP518 void [Triangulate](VertexBuffer &vb, int numFacesX, int numFacesY, int numFacesZ, bool ccwIsFrontFacing) const;519 void ToLineList(VertexBuffer &vb) const;520 #endif521 522 bool [Equals](const [OBB] &rhs, float [epsilon] = 1[e]-3f) const { return [pos].[Equals](rhs.[pos], [epsilon]) && [r].[Equals](rhs.[r], [epsilon]) && [axis][0].[Equals](rhs.[axis][0], [epsilon]) && [axis][1].[Equals](rhs.[axis][1], [epsilon]) && [axis][2].[Equals](rhs.[axis][2], [epsilon]); }523 524 525 526 bool [BitEquals](const [OBB] &other) const { return [pos].[BitEquals](other.[pos]) && [r].[BitEquals](other.[r]) && [axis][0].[BitEquals](other.[axis][0]) && [axis][1].[BitEquals](other.[axis][1]) && [axis][2].[BitEquals](other.[axis][2]); }527 };528 529 [OBB] [operator *](const [float3x3] &transform, const [OBB] &obb);530 [OBB] [operator *](const [float3x4] &transform, const [OBB] &obb);531 [OBB] [operator *](const [float4x4] &transform, const [OBB] &obb);532 [OBB] [operator *](const [Quat] &transform, const [OBB] &obb);533 534 #ifdef MATH_QT_INTEROP535 Q_DECLARE_METATYPE([OBB])536 Q_DECLARE_METATYPE([OBB]*)537 #endif538 539 #ifdef MATH_ENABLE_STL_SUPPORT540 std::ostream &[operator <<](std::ostream &o, const [OBB] &obb);541 #endif542 543 [MATH_END_NAMESPACE] Go back to previous page