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/float2.h"22 #include "../Math/float3.h"23 #include "../Math/float3x4.h"24 #include "../Math/float4x4.h"25 #include "[Ray.h]"26 27 #ifdef MATH_TINYXML_INTEROP28 #include "Config/tinyxml/tinyxml.h"29 #endif30 31 [MATH_BEGIN_NAMESPACE]32 33 34 enum [FrustumType]35 {36 [InvalidFrustum] = 0,37 38 39 40 41 42 [OrthographicFrustum],43 44 45 46 47 48 49 [PerspectiveFrustum]50 };51 52 53 54 55 enum [FrustumProjectiveSpace]56 {57 [FrustumSpaceInvalid] = 0,58 59 60 61 62 63 64 65 [FrustumSpaceGL],66 67 68 69 70 71 72 [FrustumSpaceD3D]73 };74 75 76 77 78 79 80 81 82 83 enum [FrustumHandedness]84 {85 [FrustumHandednessInvalid] = 0,86 87 88 89 90 [FrustumLeftHanded],91 92 93 94 [FrustumRightHanded]95 };96 97 98 class [Frustum]99 {100 private:101 102 103 [FrustumType] type;104 105 [FrustumProjectiveSpace] projectiveSpace;106 107 [FrustumHandedness] handedness;108 109 110 vec pos;111 112 113 114 vec front;115 116 117 118 119 120 121 122 123 vec up;124 125 126 127 128 129 130 131 float nearPlaneDistance;132 133 134 135 136 137 float farPlaneDistance;138 union139 {140 141 142 float [horizontalFov];143 144 145 float [orthographicWidth];146 };147 union148 {149 150 151 float [verticalFov];152 153 154 float [orthographicHeight];155 };156 157 void WorldMatrixChanged();158 void ProjectionMatrixChanged();159 160 161 162 [float3x4] worldMatrix;163 [float4x4] projectionMatrix;164 [float4x4] viewProjMatrix;165 166 public:167 168 169 170 171 172 173 174 175 176 [Frustum]();177 178 179 180 181 void [SetKind]([FrustumProjectiveSpace] projectiveSpace, [FrustumHandedness] handedness);182 183 184 185 186 187 188 void [SetViewPlaneDistances](float nearPlaneDistance, float farPlaneDistance);189 190 191 192 193 194 195 void [SetFrame](const vec &pos, const vec &front, const vec &up);196 197 198 199 200 void [SetPos](const vec &pos);201 202 203 204 205 void [SetFront](const vec &front);206 207 208 209 210 void [SetUp](const vec &up);211 212 213 214 215 216 217 void [SetPerspective](float [horizontalFov], float [verticalFov]);218 219 220 221 222 223 void [SetOrthographic](float [orthographicWidth], float [orthographicHeight]);224 225 226 227 [FrustumHandedness] [Handedness]() const { return handedness; }228 229 230 231 [FrustumType] [Type]() const { return type; }232 233 234 235 [FrustumProjectiveSpace] [ProjectiveSpace]() const { return projectiveSpace; }236 237 238 239 const vec &[Pos]() const { return pos; }240 241 242 243 const vec &[Front]() const { return front; }244 245 246 247 const vec &[Up]() const { return up; }248 249 250 251 float [NearPlaneDistance]() const { return nearPlaneDistance; }252 253 254 255 float [FarPlaneDistance]() const { return farPlaneDistance; }256 257 258 259 260 float [HorizontalFov]() const { return [horizontalFov]; }261 262 263 264 265 float [VerticalFov]() const { return [verticalFov]; }266 267 268 269 270 float [OrthographicWidth]() const { return [orthographicWidth]; }271 272 273 274 275 float [OrthographicHeight]() const { return [orthographicHeight]; }276 277 278 279 int [NumEdges]() const { return 12; }280 281 282 283 284 285 286 float [AspectRatio]() const;287 288 289 290 291 292 293 void [SetHorizontalFovAndAspectRatio](float [horizontalFov], float aspectRatio);294 295 296 297 298 299 300 void [SetVerticalFovAndAspectRatio](float [verticalFov], float aspectRatio);301 302 303 304 305 vec [WorldRight]() const;306 307 308 309 310 311 [Plane] [NearPlane]() const;312 313 314 315 float [NearPlaneWidth]() const;316 317 318 319 float [NearPlaneHeight]() const;320 321 322 323 324 325 [Plane] [FarPlane]() const;326 327 328 329 330 331 332 [Plane] [LeftPlane]() const;333 [Plane] [RightPlane]() const; 334 [Plane] [TopPlane]() const; 335 [Plane] [BottomPlane]() const; 336 337 338 339 340 341 342 [Plane] [GetPlane](int faceIndex) const;343 344 345 346 347 348 349 void [GetPlanes]([Plane] *outArray) const;350 351 vec [CenterPoint]() const;352 353 354 355 356 357 [LineSegment] [Edge](int edgeIndex) const;358 359 360 361 362 363 vec [CornerPoint](int cornerIndex) const;364 365 366 367 368 void [GetCornerPoints](vec *outPointArray) const;369 370 371 inline vec [AnyPointFast]() const { return [CornerPoint](0); }372 373 374 375 376 377 378 379 380 381 vec [ExtremePoint](const vec &direction) const { float projectionDistance; return [ExtremePoint](direction, projectionDistance); }382 vec [ExtremePoint](const vec &direction, float &projectionDistance) const;383 384 385 386 387 388 389 390 391 void [ProjectToAxis](const vec &direction, float &outMin, float &outMax) const;392 393 int [UniqueFaceNormals](vec *out) const;394 int [UniqueEdgeDirections](vec *out) const;395 396 397 398 399 400 401 void [SetWorldMatrix](const [float3x4] &worldTransform);402 403 404 405 406 407 408 409 [float3x4] [WorldMatrix]() const { return worldMatrix; }410 [float3x4] [ComputeWorldMatrix]() const;411 412 413 414 415 416 417 418 [float3x4] [ViewMatrix]() const { [float3x4] m = worldMatrix; m.[InverseOrthonormal](); return m; }419 [float3x4] [ComputeViewMatrix]() const;420 421 422 423 424 425 426 [float4x4] [ProjectionMatrix]() const { return projectionMatrix; }427 [float4x4] [ComputeProjectionMatrix]() const;428 429 430 431 432 433 434 435 436 437 [float4x4] [ViewProjMatrix]() const { return viewProjMatrix; }438 [float4x4] [ComputeViewProjMatrix]() const;439 440 441 442 443 444 445 [Ray] [UnProject](float x, float y) const;446 [Ray] [UnProject](const [float2] &xy) const { return [UnProject](xy.[x], xy.[y]); }447 448 449 450 451 452 [Ray] [UnProjectFromNearPlane](float x, float y) const;453 454 455 456 457 [LineSegment] [UnProjectLineSegment](float x, float y) const;458 459 460 461 462 463 464 465 vec [PointInside](float x, float y, float z) const;466 vec [PointInside](const vec &xyz) const { return [PointInside](xyz.x, xyz.y, xyz.z); }467 468 469 470 471 472 473 474 475 476 477 478 vec [Project](const vec &point) const;479 480 481 482 483 484 485 486 487 vec [NearPlanePos](float x, float y) const;488 vec [NearPlanePos](const [float2] &point) const;489 490 491 492 493 494 495 496 497 vec [FarPlanePos](float x, float y) const;498 vec [FarPlanePos](const [float2] &point) const;499 500 501 502 503 504 505 static [float2] [ViewportToScreenSpace](float x, float y, int screenWidth, int screenHeight);506 static [float2] [ViewportToScreenSpace](const [float2] &point, int screenWidth, int screenHeight);507 508 509 510 511 static [float2] [ScreenToViewportSpace](float x, float y, int screenWidth, int screenHeight);512 static [float2] [ScreenToViewportSpace](const [float2] &point, int screenWidth, int screenHeight);513 514 515 516 517 518 519 520 bool [IsFinite]() const;521 522 523 float [Volume]() const;524 525 526 527 528 vec [FastRandomPointInside]([LCG] &rng) const;529 530 531 532 533 vec [UniformRandomPointInside]([LCG] &rng) const;534 535 536 537 538 539 void [Translate](const vec &offset);540 541 542 543 544 545 546 void [Transform](const [float3x3] &transform);547 void [Transform](const [float3x4] &transform);548 void [Transform](const [float4x4] &transform);549 void [Transform](const [Quat] &transform);550 551 552 553 554 555 556 [AABB] [MinimalEnclosingAABB]() const;557 558 559 560 561 562 563 564 [OBB] [MinimalEnclosingOBB](float expandGuardband = 1[e]-5f) const;565 566 567 568 569 570 [Polyhedron] [ToPolyhedron]() const;571 572 573 574 575 576 [PBVolume<6>] [ToPBVolume]() const;577 578 579 580 581 582 583 584 bool [Contains](const vec &point) const;585 bool [Contains](const [LineSegment] &lineSegment) const;586 bool [Contains](const [Triangle] &triangle) const;587 bool [Contains](const [Polygon] &polygon) const;588 bool [Contains](const [AABB] &aabb) const;589 bool [Contains](const [OBB] &obb) const;590 bool [Contains](const [Frustum] &frustum) const;591 bool [Contains](const [Polyhedron] &polyhedron) const;592 593 594 595 596 597 vec [ClosestPoint](const vec &point) const;598 599 600 601 602 603 604 float [Distance](const vec &point) const;605 606 607 608 609 610 611 612 613 bool [Intersects](const [Ray] &ray) const;614 bool [Intersects](const [Line] &line) const;615 bool [Intersects](const [LineSegment] &lineSegment) const;616 bool [Intersects](const [AABB] &aabb) const;617 bool [Intersects](const [OBB] &obb) const;618 bool [Intersects](const [Plane] &plane) const;619 bool [Intersects](const [Triangle] &triangle) const;620 bool [Intersects](const [Polygon] &polygon) const;621 bool [Intersects](const [Sphere] &sphere) const;622 bool [Intersects](const [Capsule] &capsule) const;623 bool [Intersects](const [Frustum] &frustum) const;624 bool [Intersects](const [Polyhedron] &polyhedron) const;625 626 #if defined(MATH_TINYXML_INTEROP) && defined(MATH_CONTAINERLIB_SUPPORT)627 void DeserializeFromXml(TiXmlElement *[e]);628 #endif629 630 #ifdef MATH_ENABLE_STL_SUPPORT631 632 std::string [ToString]() const;633 634 std::string [SerializeToString]() const { return [ToString](); }635 #endif636 #ifdef MATH_QT_INTEROP637 operator QString() const { return toString(); }638 QString toString() const { return QString::fromStdString([ToString]()); }639 #endif640 };641 642 [Frustum] [operator *](const [float3x3] &transform, const [Frustum] &frustum);643 [Frustum] [operator *](const [float3x4] &transform, const [Frustum] &frustum);644 [Frustum] [operator *](const [float4x4] &transform, const [Frustum] &frustum);645 [Frustum] [operator *](const [Quat] &transform, const [Frustum] &frustum);646 647 #ifdef MATH_QT_INTEROP648 Q_DECLARE_METATYPE([Frustum])649 Q_DECLARE_METATYPE([Frustum]*)650 #endif651 652 #ifdef MATH_ENABLE_STL_SUPPORT653 std::ostream &[operator <<](std::ostream &o, const [Frustum] &frustum);654 #endif655 656 [MATH_END_NAMESPACE] Go back to previous page