diff options
| author | git perforce import user <a@b> | 2016-10-25 12:29:14 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees> | 2016-10-25 18:56:37 -0500 |
| commit | 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch) | |
| tree | fa6485c169e50d7415a651bf838f5bcd0fd3bfbd /PhysX_3.4/Source/GeomUtils/src/common | |
| download | physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip | |
Initial commit:
PhysX 3.4.0 Update @ 21294896
APEX 1.4.0 Update @ 21275617
[CL 21300167]
Diffstat (limited to 'PhysX_3.4/Source/GeomUtils/src/common')
7 files changed, 694 insertions, 0 deletions
diff --git a/PhysX_3.4/Source/GeomUtils/src/common/GuBarycentricCoordinates.cpp b/PhysX_3.4/Source/GeomUtils/src/common/GuBarycentricCoordinates.cpp new file mode 100644 index 00000000..c7972a98 --- /dev/null +++ b/PhysX_3.4/Source/GeomUtils/src/common/GuBarycentricCoordinates.cpp @@ -0,0 +1,87 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + + +#include "GuBarycentricCoordinates.h" + +using namespace physx; +using namespace Ps::aos; + +void Gu::barycentricCoordinates(const Vec3VArg p, const Vec3VArg a, const Vec3VArg b, FloatV& v) +{ + const Vec3V v0 = V3Sub(a, p); + const Vec3V v1 = V3Sub(b, p); + const Vec3V d = V3Sub(v1, v0); + const FloatV denominator = V3Dot(d, d); + const FloatV numerator = V3Dot(V3Neg(v0), d); + v = FDiv(numerator, denominator); +} + +void Gu::barycentricCoordinates(const Ps::aos::Vec3VArg p, const Ps::aos::Vec3VArg a, const Ps::aos::Vec3VArg b, const Ps::aos::Vec3VArg c, Ps::aos::FloatV& v, Ps::aos::FloatV& w) +{ + const Vec3V ab = V3Sub(b, a); + const Vec3V ac = V3Sub(c, a); + + const Vec3V n = V3Cross(ab, ac); + + const VecCrossV crossA = V3PrepareCross(V3Sub(a, p)); + const VecCrossV crossB = V3PrepareCross(V3Sub(b, p)); + const VecCrossV crossC = V3PrepareCross(V3Sub(c, p)); + const Vec3V bCrossC = V3Cross(crossB, crossC); + const Vec3V cCrossA = V3Cross(crossC, crossA); + const Vec3V aCrossB = V3Cross(crossA, crossB); + + const FloatV va = V3Dot(n, bCrossC);//edge region of BC, signed area rbc, u = S(rbc)/S(abc) for a + const FloatV vb = V3Dot(n, cCrossA);//edge region of AC, signed area rac, v = S(rca)/S(abc) for b + const FloatV vc = V3Dot(n, aCrossB);//edge region of AB, signed area rab, w = S(rab)/S(abc) for c + const FloatV totalArea =FAdd(va, FAdd(vb, vc)); + const FloatV zero = FZero(); + const FloatV denom = FSel(FIsEq(totalArea, zero), zero, FRecip(totalArea)); + v = FMul(vb, denom); + w = FMul(vc, denom); + +} + +/* + v0 = b - a; + v1 = c - a; + v2 = p - a; +*/ +void Gu::barycentricCoordinates(const Vec3VArg v0, const Vec3VArg v1, const Vec3VArg v2, FloatV& v, FloatV& w) +{ + const FloatV d00 = V3Dot(v0, v0); + const FloatV d01 = V3Dot(v0, v1); + const FloatV d11 = V3Dot(v1, v1); + const FloatV d20 = V3Dot(v2, v0); + const FloatV d21 = V3Dot(v2, v1); + const FloatV denom = FRecip(FSub(FMul(d00,d11), FMul(d01, d01))); + v = FMul(FSub(FMul(d11, d20), FMul(d01, d21)), denom); + w = FMul(FSub(FMul(d00, d21), FMul(d01, d20)), denom); +} + diff --git a/PhysX_3.4/Source/GeomUtils/src/common/GuBarycentricCoordinates.h b/PhysX_3.4/Source/GeomUtils/src/common/GuBarycentricCoordinates.h new file mode 100644 index 00000000..fb4178af --- /dev/null +++ b/PhysX_3.4/Source/GeomUtils/src/common/GuBarycentricCoordinates.h @@ -0,0 +1,93 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#ifndef GU_BARYCENTRIC_COORDINATES_H +#define GU_BARYCENTRIC_COORDINATES_H + +#include "PxPhysXCommonConfig.h" +#include "CmPhysXCommon.h" +#include "PsVecMath.h" + +namespace physx +{ +namespace Gu +{ + //calculate the barycentric coorinates for a point in a segment + void barycentricCoordinates(const Ps::aos::Vec3VArg p, + const Ps::aos::Vec3VArg a, + const Ps::aos::Vec3VArg b, + Ps::aos::FloatV& v); + + //calculate the barycentric coorinates for a point in a triangle + void barycentricCoordinates(const Ps::aos::Vec3VArg p, + const Ps::aos::Vec3VArg a, + const Ps::aos::Vec3VArg b, + const Ps::aos::Vec3VArg c, + Ps::aos::FloatV& v, + Ps::aos::FloatV& w); + + void barycentricCoordinates(const Ps::aos::Vec3VArg v0, + const Ps::aos::Vec3VArg v1, + const Ps::aos::Vec3VArg v2, + Ps::aos::FloatV& v, + Ps::aos::FloatV& w); + + PX_INLINE Ps::aos::BoolV isValidTriangleBarycentricCoord(const Ps::aos::FloatVArg v, const Ps::aos::FloatVArg w) + { + using namespace Ps::aos; + const FloatV zero = FNeg(FEps()); + const FloatV one = FAdd(FOne(), FEps()); + + const BoolV con0 = BAnd(FIsGrtrOrEq(v, zero), FIsGrtrOrEq(one, v)); + const BoolV con1 = BAnd(FIsGrtrOrEq(w, zero), FIsGrtrOrEq(one, w)); + const BoolV con2 = FIsGrtr(one, FAdd(v, w)); + return BAnd(con0, BAnd(con1, con2)); + } + + PX_INLINE Ps::aos::BoolV isValidTriangleBarycentricCoord2(const Ps::aos::Vec4VArg vwvw) + { + using namespace Ps::aos; + const Vec4V eps = V4Splat(FEps()); + const Vec4V zero =V4Neg(eps); + const Vec4V one = V4Add(V4One(), eps); + + const Vec4V v0v1v0v1 = V4PermXZXZ(vwvw); + const Vec4V w0w1w0w1 = V4PermYWYW(vwvw); + + const BoolV con0 = BAnd(V4IsGrtrOrEq(v0v1v0v1, zero), V4IsGrtrOrEq(one, v0v1v0v1)); + const BoolV con1 = BAnd(V4IsGrtrOrEq(w0w1w0w1, zero), V4IsGrtrOrEq(one, w0w1w0w1)); + const BoolV con2 = V4IsGrtr(one, V4Add(v0v1v0v1, w0w1w0w1)); + return BAnd(con0, BAnd(con1, con2)); + } + +} // namespace Gu + +} + +#endif diff --git a/PhysX_3.4/Source/GeomUtils/src/common/GuBoxConversion.h b/PhysX_3.4/Source/GeomUtils/src/common/GuBoxConversion.h new file mode 100644 index 00000000..e125e682 --- /dev/null +++ b/PhysX_3.4/Source/GeomUtils/src/common/GuBoxConversion.h @@ -0,0 +1,121 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#ifndef GU_BOX_CONVERSION_H +#define GU_BOX_CONVERSION_H + +#include "GuBox.h" +#include "PsMathUtils.h" +#include "CmMatrix34.h" +#include "PsVecMath.h" + +namespace physx +{ + // PT: builds rot from quat. WARNING: writes 4 bytes after 'dst.rot'. + PX_FORCE_INLINE void buildFrom(Gu::Box& dst, const PxQuat& q) + { + using namespace Ps::aos; + const QuatV qV = V4LoadU(&q.x); + Vec3V column0, column1, column2; + QuatGetMat33V(qV, column0, column1, column2); + // PT: TODO: investigate if these overlapping stores are a problem + V4StoreU(Vec4V_From_Vec3V(column0), &dst.rot.column0.x); + V4StoreU(Vec4V_From_Vec3V(column1), &dst.rot.column1.x); + V4StoreU(Vec4V_From_Vec3V(column2), &dst.rot.column2.x); + } + + PX_FORCE_INLINE void buildFrom(Gu::Box& dst, const PxVec3& center, const PxVec3& extents, const PxQuat& q) + { + using namespace Ps::aos; + // PT: writes 4 bytes after 'rot' but it's safe since we then write 'center' just afterwards + buildFrom(dst, q); + dst.center = center; + dst.extents = extents; + } + + PX_FORCE_INLINE void buildMatrixFromBox(Cm::Matrix34& mat34, const Gu::Box& box) + { + mat34.m = box.rot; + mat34.p = box.center; + } + + // SD: function is now the same as FastVertex2ShapeScaling::transformQueryBounds + // PT: lots of LHS in that one. TODO: revisit... + PX_INLINE Gu::Box transform(const Cm::Matrix34& transfo, const Gu::Box& box) + { + Gu::Box ret; + PxMat33& obbBasis = ret.rot; + + obbBasis.column0 = transfo.rotate(box.rot.column0 * box.extents.x); + obbBasis.column1 = transfo.rotate(box.rot.column1 * box.extents.y); + obbBasis.column2 = transfo.rotate(box.rot.column2 * box.extents.z); + + ret.center = transfo.transform(box.center); + ret.extents = Ps::optimizeBoundingBox(obbBasis); + return ret; + } + + PX_INLINE Gu::Box transformBoxOrthonormal(const Gu::Box& box, const PxTransform& t) + { + Gu::Box ret; + PxMat33& obbBasis = ret.rot; + obbBasis.column0 = t.rotate(box.rot.column0); + obbBasis.column1 = t.rotate(box.rot.column1); + obbBasis.column2 = t.rotate(box.rot.column2); + ret.center = t.transform(box.center); + ret.extents = box.extents; + return ret; + } + + /** + \brief recomputes the OBB after an arbitrary transform by a 4x4 matrix. + \param mtx [in] the transform matrix + \param obb [out] the transformed OBB + */ + PX_INLINE void rotate(const Gu::Box& src, const Cm::Matrix34& mtx, Gu::Box& obb) + { + // The extents remain constant + obb.extents = src.extents; + // The center gets x-formed + obb.center = mtx.transform(src.center); + // Combine rotations + obb.rot = mtx.m * src.rot; + } + +// PT: TODO: move this to a better place + PX_FORCE_INLINE void getInverse(PxMat33& dstRot, PxVec3& dstTrans, const PxMat33& srcRot, const PxVec3& srcTrans) + { + const PxMat33 invRot = srcRot.getInverse(); + dstTrans = invRot.transform(-srcTrans); + dstRot = invRot; + } + +} + +#endif diff --git a/PhysX_3.4/Source/GeomUtils/src/common/GuEdgeCache.h b/PhysX_3.4/Source/GeomUtils/src/common/GuEdgeCache.h new file mode 100644 index 00000000..8efad75a --- /dev/null +++ b/PhysX_3.4/Source/GeomUtils/src/common/GuEdgeCache.h @@ -0,0 +1,85 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#ifndef GU_EDGECACHE_H +#define GU_EDGECACHE_H + +#include "foundation/PxMemory.h" +#include "CmPhysXCommon.h" +#include "PsHash.h" + +namespace physx +{ +namespace Gu +{ + class EdgeCache + { +#define NUM_EDGES_IN_CACHE 64 //must be power of 2. 32 lines result in 10% extra work (due to cache misses), 64 lines in 6% extra work, 128 lines in 4%. + public: + EdgeCache() + { + PxMemZero(cacheLines, NUM_EDGES_IN_CACHE*sizeof(CacheLine)); + } + + PxU32 hash(PxU32 key) const + { + return (NUM_EDGES_IN_CACHE - 1) & Ps::hash(key); //Only a 16 bit hash would be needed here. + } + + bool isInCache(PxU8 vertex0, PxU8 vertex1) + { + PX_ASSERT(vertex1 >= vertex0); + PxU16 key = PxU16((vertex0 << 8) | vertex1); + PxU32 h = hash(key); + CacheLine& cl = cacheLines[h]; + if (cl.fullKey == key) + { + return true; + } + else //cache the line now as it's about to be processed + { + cl.fullKey = key; + return false; + } + } + + private: + struct CacheLine + { + PxU16 fullKey; + }; + CacheLine cacheLines[NUM_EDGES_IN_CACHE]; +#undef NUM_EDGES_IN_CACHE + }; +} + +} + +#endif + diff --git a/PhysX_3.4/Source/GeomUtils/src/common/GuEdgeListData.h b/PhysX_3.4/Source/GeomUtils/src/common/GuEdgeListData.h new file mode 100644 index 00000000..dea26f16 --- /dev/null +++ b/PhysX_3.4/Source/GeomUtils/src/common/GuEdgeListData.h @@ -0,0 +1,153 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#ifndef GU_EDGE_LIST_DATA_H +#define GU_EDGE_LIST_DATA_H + +#include "foundation/PxSimpleTypes.h" +#include "CmPhysXCommon.h" + +namespace physx +{ +namespace Gu +{ + +/*! +NOTICE! + +This is a data-code separated version of PxPhysics::EdgeList. + +It is to be shared between high and low level code, so make sure both are recompiled +if any change is done here. +*/ + +// Flags +enum EdgeType +{ + PX_EDGE_UNDEFINED, + + PX_EDGE_BOUNDARY, //!< Edge belongs to a single triangle + PX_EDGE_INTERNAL, //!< Edge belongs to exactly two triangles + PX_EDGE_SINGULAR, //!< Edge belongs to three or more triangles + + PX_EDGE_FORCE_DWORD = 0x7fffffff +}; + +enum EdgeFlag +{ + PX_EDGE_ACTIVE = (1<<0) +}; + + +// Data + + +//! Basic edge-data +struct EdgeData +{ + PxU32 Ref0; //!< First vertex reference + PxU32 Ref1; //!< Second vertex reference +}; +PX_COMPILE_TIME_ASSERT(sizeof(Gu::EdgeData) == 8); + + +//! Basic edge-data using 8-bit references +struct Edge8Data +{ + PxU8 Ref0; //!< First vertex reference + PxU8 Ref1; //!< Second vertex reference +}; +PX_COMPILE_TIME_ASSERT(sizeof(Gu::Edge8Data) == 2); + + +//! A count/offset pair = an edge descriptor +struct EdgeDescData +{ + PxU16 Flags; + PxU16 Count; + PxU32 Offset; +}; +PX_COMPILE_TIME_ASSERT(sizeof(Gu::EdgeDescData) == 8); + + +//! Edge<->triangle mapping +struct EdgeTriangleData +{ + PxU32 mLink[3]; +}; +PX_COMPILE_TIME_ASSERT(sizeof(Gu::EdgeTriangleData) == 12); + + +struct EdgeListData +{ + // The edge list + PxU32 mNbEdges; //!< Number of edges in the list + Gu::EdgeData* mEdges; //!< List of edges + // Faces to edges + PxU32 mNbFaces; //!< Number of faces for which we have data + Gu::EdgeTriangleData* mEdgeFaces; //!< Array of edge-triangles referencing mEdges + // Edges to faces + Gu::EdgeDescData* mEdgeToTriangles; //!< An EdgeDesc structure for each edge + PxU32* mFacesByEdges; //!< A pool of face indices +}; +#if PX_P64_FAMILY +PX_COMPILE_TIME_ASSERT(sizeof(Gu::EdgeListData) == 48); +#else +PX_COMPILE_TIME_ASSERT(sizeof(Gu::EdgeListData) == 24); +#endif + + +// Accessors + +enum +{ + MSH_EDGE_LINK_MASK = 0x0fffffff, + MSH_ACTIVE_EDGE_MASK = 0x80000000, + MSH_ACTIVE_VERTEX_MASK = 0x40000000 +}; + +class EdgeTriangleAC +{ +public: + PX_INLINE static PxU32 GetEdge01(const Gu::EdgeTriangleData& data) { return data.mLink[0] & MSH_EDGE_LINK_MASK; } + PX_INLINE static PxU32 GetEdge12(const Gu::EdgeTriangleData& data) { return data.mLink[1] & MSH_EDGE_LINK_MASK; } + PX_INLINE static PxU32 GetEdge20(const Gu::EdgeTriangleData& data) { return data.mLink[2] & MSH_EDGE_LINK_MASK; } + PX_INLINE static PxU32 GetEdge(const Gu::EdgeTriangleData& data, PxU32 i) { return data.mLink[i] & MSH_EDGE_LINK_MASK; } + + PX_INLINE static Ps::IntBool HasActiveEdge01(const Gu::EdgeTriangleData& data) { return Ps::IntBool(data.mLink[0] & MSH_ACTIVE_EDGE_MASK); } + PX_INLINE static Ps::IntBool HasActiveEdge12(const Gu::EdgeTriangleData& data) { return Ps::IntBool(data.mLink[1] & MSH_ACTIVE_EDGE_MASK); } + PX_INLINE static Ps::IntBool HasActiveEdge20(const Gu::EdgeTriangleData& data) { return Ps::IntBool(data.mLink[2] & MSH_ACTIVE_EDGE_MASK); } + PX_INLINE static Ps::IntBool HasActiveEdge(const Gu::EdgeTriangleData& data, PxU32 i) { return Ps::IntBool(data.mLink[i] & MSH_ACTIVE_EDGE_MASK); } +}; + +} // namespace Gu + +} + +#endif diff --git a/PhysX_3.4/Source/GeomUtils/src/common/GuSeparatingAxes.cpp b/PhysX_3.4/Source/GeomUtils/src/common/GuSeparatingAxes.cpp new file mode 100644 index 00000000..79d2de3c --- /dev/null +++ b/PhysX_3.4/Source/GeomUtils/src/common/GuSeparatingAxes.cpp @@ -0,0 +1,64 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#include "GuSeparatingAxes.h" + +using namespace physx; + +union FloatInt +{ + float f; + PxU32 i; +}; + +bool Gu::SeparatingAxes::addAxis(const PxVec3& axis) +{ + PxU32 numAxes = getNumAxes(); + const PxVec3* PX_RESTRICT axes = getAxes(); + const PxVec3* PX_RESTRICT axes_end = axes + numAxes; + while(axes<axes_end) + { + if(PxAbs(axis.dot(*axes))>0.9999f) + return false; + axes++; + } + +#ifdef SEP_AXIS_FIXED_MEMORY + if(mNbAxes<SEP_AXIS_FIXED_MEMORY) + { + mAxes[mNbAxes++] = axis; + return true; + } + + return false; +#else + mAxes.pushBack(axis); + return true; +#endif +} diff --git a/PhysX_3.4/Source/GeomUtils/src/common/GuSeparatingAxes.h b/PhysX_3.4/Source/GeomUtils/src/common/GuSeparatingAxes.h new file mode 100644 index 00000000..208a9e1a --- /dev/null +++ b/PhysX_3.4/Source/GeomUtils/src/common/GuSeparatingAxes.h @@ -0,0 +1,91 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#ifndef GU_SEPARATINGAXES_H +#define GU_SEPARATINGAXES_H + +#include "foundation/PxVec3.h" +#include "PxPhysXCommonConfig.h" + +namespace physx +{ +namespace Gu +{ + // PT: this is a number of axes. Multiply by sizeof(PxVec3) for size in bytes. + #define SEP_AXIS_FIXED_MEMORY 256 + + // This class holds a list of potential separating axes. + // - the orientation is irrelevant so V and -V should be the same vector + // - the scale is irrelevant so V and n*V should be the same vector + // - a given separating axis should appear only once in the class +#if PX_VC + #pragma warning(push) + #pragma warning( disable : 4251 ) // class needs to have dll-interface to be used by clients of class +#endif + class PX_PHYSX_COMMON_API SeparatingAxes + { + public: + PX_INLINE SeparatingAxes() : mNbAxes(0) {} + + bool addAxis(const PxVec3& axis); + + PX_FORCE_INLINE const PxVec3* getAxes() const + { + return mAxes; + } + + PX_FORCE_INLINE PxU32 getNumAxes() const + { + return mNbAxes; + } + + PX_FORCE_INLINE void reset() + { + mNbAxes = 0; + } + + private: + PxU32 mNbAxes; + PxVec3 mAxes[SEP_AXIS_FIXED_MEMORY]; + }; +#if PX_VC + #pragma warning(pop) +#endif + + enum PxcSepAxisType + { + SA_NORMAL0, // Normal of object 0 + SA_NORMAL1, // Normal of object 1 + SA_EE // Cross product of edges + }; + +} +} + +#endif |