b3Float4.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef B3_FLOAT4_H
  2. #define B3_FLOAT4_H
  3. #include "Bullet3Common/shared/b3PlatformDefinitions.h"
  4. #ifdef __cplusplus
  5. #include "Bullet3Common/b3Vector3.h"
  6. #define b3Float4 b3Vector3
  7. #define b3Float4ConstArg const b3Vector3&
  8. #define b3Dot3F4 b3Dot
  9. #define b3Cross3 b3Cross
  10. #define b3MakeFloat4 b3MakeVector3
  11. inline b3Vector3 b3Normalized(const b3Vector3& vec)
  12. {
  13. return vec.normalized();
  14. }
  15. inline b3Float4 b3FastNormalized3(b3Float4ConstArg v)
  16. {
  17. return v.normalized();
  18. }
  19. inline b3Float4 b3MaxFloat4(const b3Float4& a, const b3Float4& b)
  20. {
  21. b3Float4 tmp = a;
  22. tmp.setMax(b);
  23. return tmp;
  24. }
  25. inline b3Float4 b3MinFloat4(const b3Float4& a, const b3Float4& b)
  26. {
  27. b3Float4 tmp = a;
  28. tmp.setMin(b);
  29. return tmp;
  30. }
  31. #else
  32. typedef float4 b3Float4;
  33. #define b3Float4ConstArg const b3Float4
  34. #define b3MakeFloat4 (float4)
  35. float b3Dot3F4(b3Float4ConstArg v0, b3Float4ConstArg v1)
  36. {
  37. float4 a1 = b3MakeFloat4(v0.xyz, 0.f);
  38. float4 b1 = b3MakeFloat4(v1.xyz, 0.f);
  39. return dot(a1, b1);
  40. }
  41. b3Float4 b3Cross3(b3Float4ConstArg v0, b3Float4ConstArg v1)
  42. {
  43. float4 a1 = b3MakeFloat4(v0.xyz, 0.f);
  44. float4 b1 = b3MakeFloat4(v1.xyz, 0.f);
  45. return cross(a1, b1);
  46. }
  47. #define b3MinFloat4 min
  48. #define b3MaxFloat4 max
  49. #define b3Normalized(a) normalize(a)
  50. #endif
  51. inline bool b3IsAlmostZero(b3Float4ConstArg v)
  52. {
  53. if (b3Fabs(v.x) > 1e-6 || b3Fabs(v.y) > 1e-6 || b3Fabs(v.z) > 1e-6)
  54. return false;
  55. return true;
  56. }
  57. inline int b3MaxDot(b3Float4ConstArg vec, __global const b3Float4* vecArray, int vecLen, float* dotOut)
  58. {
  59. float maxDot = -B3_INFINITY;
  60. int i = 0;
  61. int ptIndex = -1;
  62. for (i = 0; i < vecLen; i++)
  63. {
  64. float dot = b3Dot3F4(vecArray[i], vec);
  65. if (dot > maxDot)
  66. {
  67. maxDot = dot;
  68. ptIndex = i;
  69. }
  70. }
  71. b3Assert(ptIndex >= 0);
  72. if (ptIndex < 0)
  73. {
  74. ptIndex = 0;
  75. }
  76. *dotOut = maxDot;
  77. return ptIndex;
  78. }
  79. #endif //B3_FLOAT4_H