aboutsummaryrefslogtreecommitdiff
path: root/NvCloth/samples/SampleBase/utils/Utils.h
diff options
context:
space:
mode:
authorMarijn Tamis <[email protected]>2017-04-28 14:19:07 +0200
committerMarijn Tamis <[email protected]>2017-04-28 14:19:07 +0200
commitb350eb5f4d44e8448115796144375d79438d74ae (patch)
tree8e102e8c28f45a1b87bd335ceee4f33c3d4ee7c2 /NvCloth/samples/SampleBase/utils/Utils.h
parentAdd visual samples. (diff)
downloadnvcloth-b350eb5f4d44e8448115796144375d79438d74ae.tar.xz
nvcloth-b350eb5f4d44e8448115796144375d79438d74ae.zip
NvCloth 1.1.0 Release. (22041545)
Diffstat (limited to 'NvCloth/samples/SampleBase/utils/Utils.h')
-rw-r--r--NvCloth/samples/SampleBase/utils/Utils.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/NvCloth/samples/SampleBase/utils/Utils.h b/NvCloth/samples/SampleBase/utils/Utils.h
index 5e84e8e..1a5d5ee 100644
--- a/NvCloth/samples/SampleBase/utils/Utils.h
+++ b/NvCloth/samples/SampleBase/utils/Utils.h
@@ -3,6 +3,8 @@
#include <DeviceManager.h>
#include <assert.h>
+#include <foundation/PxVec3.h>
+#include <foundation/PxVec4.h>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -80,8 +82,32 @@ static const char* strext(const char* str)
return ext;
}
+//Math utilities
static inline float lerp(float a, float b, float t) { return a + (b - a) * t; }
+/** returns a PxVec4 containing [x,y,z,d] for plane equation ax + by + cz + d = 0.
+* Where plane contains p and has normal n.
+*/
+inline physx::PxVec4 constructPlaneFromPointNormal(physx::PxVec3 p, physx::PxVec3 n)
+{
+ n.normalize();
+ return physx::PxVec4(n, -p.dot(n));
+}
+
+/** returns two vectors in b and c so that [a b c] form a basis.
+* a needs to be a unit vector.
+*/
+inline void computeBasis(const physx::PxVec3& a, physx::PxVec3* b, physx::PxVec3* c)
+{
+ if(fabsf(a.x) >= 0.57735f)
+ *b = physx::PxVec3(a.y, -a.x, 0.0f);
+ else
+ *b = physx::PxVec3(0.0f, a.z, -a.y);
+
+ *b = b->getNormalized();
+ *c = a.cross(*b);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////