1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #ifdef MATH_ENABLE_STL_SUPPORT21 #include <string>22 #endif23 #include "[Math/MathFwd.h]"24 #include "[Math/float3.h]"25 26 #ifdef MATH_QT_INTEROP27 #include <QVector4D>28 #endif29 30 #ifdef MATH_OGRE_INTEROP31 #include <OgreVector4.h>32 #endif33 34 [MATH_BEGIN_NAMESPACE]35 36 37 38 39 40 class [float4]41 {42 public:43 enum44 {45 46 [Size] = 447 };48 49 50 51 float [x];52 53 54 float [y];55 56 57 float [z];58 59 60 float [w];61 62 63 64 65 66 [float4]() {}67 68 69 70 71 [float4](const [float4] &rhs) { [x] = rhs.[x]; [y] = rhs.[y]; [z] = rhs.[z]; [w] = rhs.[w]; }72 73 74 75 [float4](float [x], float [y], float [z], float [w]);76 77 78 79 [float4](const [float3] &[xyz], float [w]);80 81 82 83 [float4](const [float2] &xy, float [z], float [w]);84 85 86 87 explicit [float4](const float *data);88 89 90 91 92 93 94 95 96 97 98 99 100 float *[ptr]();101 const float *[ptr]() const;102 103 104 105 106 107 float &[operator []](int index) { return [At](index); }108 [CONST_WIN32] float [operator []](int index) const { return [At](index); }109 110 111 112 113 114 float &[At](int index);115 [CONST_WIN32] float [At](int index) const;116 117 118 119 120 [float4] [operator +](const [float4] &v) const;121 122 123 124 125 [float4] [operator -]() const;126 127 128 129 130 [float4] [operator -](const [float4] &v) const;131 132 133 134 135 [float4] [operator *](float scalar) const;136 137 138 139 140 [float4] [operator /](float scalar) const;141 142 143 144 [float4] &[operator +=](const [float4] &v);145 146 147 148 [float4] &[operator -=](const [float4] &v);149 150 151 152 153 [float4] &[operator *=](float scalar);154 155 156 157 [float4] &[operator /=](float scalar);158 159 #ifdef MATH_ENABLE_UNCOMMON_OPERATIONS160 [float4] [operator *](const [float4] &vector) const { return this->[Mul](vector); }161 [float4] [operator /](const [float4] &vector) const { return this->[Div](vector); }162 [float4] &[operator *=](const [float4] &vector) { *this = this->[Mul](vector); return *this; }163 [float4] &[operator /=](const [float4] &vector) { *this = this->[Div](vector); return *this; }164 #endif165 166 167 168 [float4] [Add](const [float4] &v) const { return *this + v; }169 170 171 172 173 174 [float4] [Add](float s) const;175 176 177 178 [float4] [Sub](const [float4] &v) const { return *this - v; }179 180 181 182 183 184 [float4] [Sub](float s) const;185 186 187 188 189 190 [float4] [SubLeft](float s) const;191 192 193 194 195 196 [float4] [Mul](const [float4] &v) const;197 198 199 200 201 [float4] [Mul](float s) const { return *this * s; }202 203 204 205 206 207 [float4] [Div](const [float4] &v) const;208 209 210 211 [float4] [Div](float s) const { return *this / s; }212 213 214 215 216 217 [float4] [DivLeft](float s) const;218 219 220 [float3] [xyz]() const;221 222 223 224 225 226 227 228 229 [float2] [Swizzled](int i, int j) const;230 [float3] [Swizzled](int i, int j, int k) const;231 [float4] [Swizzled](int i, int j, int k, int l) const;232 233 234 235 static [float4] [FromScalar](float scalar);236 237 238 static [float4] [FromScalar](float scalar, float [w]);239 240 241 242 void [SetFromScalar](float scalar);243 244 245 void [SetFromScalar](float scalar, float [w]);246 247 248 249 void [Set](float [x], float [y], float [z], float [w]);250 251 252 253 254 255 256 257 258 259 float [LengthSq3]() const;260 261 262 263 264 265 float [Length3]() const;266 267 268 269 270 271 272 273 274 float [LengthSq4]() const;275 276 277 278 279 float [Length4]() const;280 281 282 283 284 285 286 287 288 289 float [Normalize3]();290 291 292 293 294 295 296 297 298 float [Normalize4]();299 300 301 302 303 304 305 [float4] [Normalized3]() const;306 307 308 309 310 311 [float4] [Normalized4]() const;312 313 314 315 316 317 318 319 320 bool [NormalizeW]();321 322 323 324 325 bool [IsWZeroOrOne](float epsilon = 1[e]-3f) const;326 327 328 329 bool [IsZero3](float epsilonSq = 1[e]-6f) const;330 331 332 333 bool [IsZero4](float epsilonSq = 1[e]-6f) const;334 335 336 337 bool [IsNormalized3](float epsilonSq = 1[e]-6f) const;338 339 340 341 342 bool [IsNormalized4](float epsilonSq = 1[e]-6f) const;343 344 345 346 347 348 void [Scale3](float scalar);349 350 351 352 353 354 float [ScaleToLength3](float newLength);355 356 357 358 359 [float4] [ScaledToLength3](float newLength) const;360 361 362 bool [IsFinite]() const;363 364 365 bool [IsPerpendicular3](const [float4] &other, float epsilon = 1[e]-6f) const;366 367 #ifdef MATH_ENABLE_STL_SUPPORT368 369 std::string ToString() const;370 371 std::string SerializeToString() const;372 #endif373 374 375 static [float4] [FromString](const char *str);376 #ifdef MATH_ENABLE_STL_SUPPORT377 static [float4] [FromString](const std::string &str) { return [FromString](str.c_str()); }378 #endif379 380 381 float [SumOfElements]() const;382 383 384 float [ProductOfElements]() const;385 386 387 float [AverageOfElements]() const;388 389 390 391 float [MinElement]() const;392 393 394 395 int [MinElementIndex]() const;396 397 398 399 float [MaxElement]() const;400 401 402 403 int [MaxElementIndex]() const;404 405 406 407 408 [float4] [Abs]() const;409 410 411 412 413 [float4] [Neg3]() const;414 415 416 417 418 [float4] [Neg4]() const;419 420 421 422 423 424 [float4] [Recip3]() const;425 426 427 428 429 430 [float4] [Recip4]() const;431 432 433 434 [float4] [Min](float ceil) const;435 436 437 438 439 [float4] [Min](const [float4] &ceil) const;440 441 442 443 [float4] [Max](float floor) const;444 445 446 447 448 [float4] [Max](const [float4] &floor) const;449 450 451 [float4] [Clamp](float floor, float ceil) const;452 453 454 455 [float4] [Clamp](const [float4] &floor, const [float4] &ceil) const;456 457 458 459 [float4] [Clamp01]() const;460 461 462 463 464 465 466 [float4] [Lerp](const [float4] &b, float t) const;467 static [float4] [Lerp](const [float4] &a, const [float4] &b, float t);468 469 470 471 472 float [Distance3Sq](const [float4] &rhs) const;473 474 475 476 477 float [Distance3](const [float4] &rhs) const;478 479 480 481 482 float [Dot3](const [float3] &rhs) const;483 float [Dot3](const [float4] &rhs) const;484 485 486 487 float [Dot4](const [float4] &rhs) const;488 489 490 491 [float4] [Cross3](const [float3] &rhs) const;492 [float4] [Cross3](const [float4] &rhs) const;493 494 495 [float4x4] [OuterProduct](const [float4] &rhs) const;496 497 498 [float4] [Perpendicular3](const [float3] &hint = [float3](0,1,0), const [float3] &hint2 = [float3](0,0,1)) const;499 500 501 502 503 [float4] [AnotherPerpendicular3](const [float3] &hint = [float3](0,1,0), const [float3] &hint2 = [float3](0,0,1)) const;504 505 506 507 508 [float4] [Reflect3](const [float3] &normal) const;509 510 511 512 513 514 515 float [AngleBetween3](const [float4] &other) const;516 517 518 519 520 521 float [AngleBetweenNorm3](const [float4] &normalizedVector) const;522 523 524 525 526 float [AngleBetween4](const [float4] &other) const;527 528 529 530 531 float [AngleBetweenNorm4](const [float4] &normalizedVector) const;532 533 534 535 536 537 [float4] [ProjectTo3](const [float3] &target) const;538 539 540 541 542 543 544 [float4] [ProjectToNorm3](const [float3] &target) const;545 546 547 bool [Equals](const [float4] &other, float epsilon = 1[e]-3f) const;548 bool [Equals](float [x], float [y], float [z], float [w], float epsilon = 1[e]-3f) const;549 550 551 552 static [float4] [RandomDir]([LCG] &lcg, float length = 1.f);553 554 #ifdef MATH_ENABLE_UNCOMMON_OPERATIONS555 [float4] [operator *](const [float4] &rhs) const { return this->[Mul](rhs); }556 [float4] [operator /](const [float4] &rhs) const { return this->[Div](rhs); }557 [float4] &[operator *=](const [float4] &rhs) { *this = this->[Mul](rhs); return *this; }558 [float4] &[operator /=](const [float4] &rhs) { *this = this->[Div](rhs); return *this; }559 #endif560 561 562 563 564 static const [float4] [zero];565 566 567 568 569 static const [float4] [one];570 571 572 573 574 static const [float4] [unitX];575 576 577 578 579 static const [float4] [unitY];580 581 582 583 584 static const [float4] [unitZ];585 586 587 588 589 static const [float4] [unitW];590 591 592 593 594 595 596 597 static const [float4] [nan];598 599 600 601 602 static const [float4] [inf];603 604 #ifdef MATH_OGRE_INTEROP605 [float4](const Ogre::Vector4 &other) { [x] = other.x; [y] = other.y; [z] = other.z; [w] = other.w; }606 [float4] &operator =(const Ogre::Vector4 &other) { [x] = other.x; [y] = other.y; [z] = other.z; [w] = other.w; return *this; }607 operator Ogre::Vector4() const { return Ogre::Vector4([x], [y], [z], [w]); }608 #endif609 #ifdef MATH_QT_INTEROP610 [float4](const QVector4D &other) { [x] = other.x(); [y] = other.y(); [z] = other.z(); [w] = other.w(); }611 operator QVector4D() const { return QVector4D([x], [y], [z], [w]); }612 operator QString() const { return "float4(" + QString::number([x]) + "," + QString::number([y]) + "," + QString::number([z]) + "," + QString::number([w]) + ")"; }613 QString toString() const { return (QString)*this; }614 QVector4D ToQVector4D() const { return QVector4D([x], [y], [z], [w]); }615 static [float4] FromQVector4D(const QVector4D &v) { return ([float4])v; }616 static [float4] [FromString](const QString &str) { return [FromString](str.toStdString()); }617 #endif618 #ifdef MATH_BULLET_INTEROP619 620 [float4](const btVector3 &other) { [x] = other.x(); [y] = other.y(); [z] = other.z(); [w] = other.w(); }621 operator btVector3() const { btVector3 v([x], [y], [z]); v.setW([w]); return v; }622 #endif623 };624 625 #ifdef MATH_ENABLE_STL_SUPPORT626 627 std::ostream &operator <<(std::ostream &out, const [float4] &rhs);628 #endif629 630 631 632 [float4] [operator *](float scalar, const [float4] &rhs);633 634 #ifdef MATH_ENABLE_UNCOMMON_OPERATIONS635 inline [float4] [operator /](float scalar, const [float4] &rhs) { return [float4::FromScalar](scalar) / rhs; }636 #endif637 638 inline float [Dot3](const [float4] &a, const [float4] &b) { return a.[Dot3](b); }639 inline float [Dot4](const [float4] &a, const [float4] &b) { return a.[Dot4](b); }640 inline [float4] [Cross3](const [float4] &a, const [float4] &b) { return a.[Cross3](b); }641 inline [float4] [Abs](const [float4] &a) { return a.[Abs](); }642 inline [float4] [Min](const [float4] &a, const [float4] &b) { return a.[Min](b); }643 inline [float4] [Max](const [float4] &a, const [float4] &b) { return a.[Max](b); }644 inline [float4] [Clamp](const [float4] &a, float floor, float ceil) { return a.[Clamp](floor, ceil); }645 inline [float4] [Clamp](const [float4] &a, const [float4] &floor, const [float4] &ceil) { return a.[Clamp](floor, ceil); }646 inline [float4] [Clamp01](const [float4] &a) { return a.[Clamp01](); }647 inline [float4] [Lerp](const [float4] &a, const [float4] &b, float t) { return a.[Lerp](b, t); }648 649 [MATH_END_NAMESPACE]650 651 #ifdef MATH_QT_INTEROP652 Q_DECLARE_METATYPE([float4])653 Q_DECLARE_METATYPE([float4]*)654 #endif Go back to previous page