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 /APEX_1.4/module/clothing/include/ClothingCollisionImpl.h | |
| 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 'APEX_1.4/module/clothing/include/ClothingCollisionImpl.h')
| -rw-r--r-- | APEX_1.4/module/clothing/include/ClothingCollisionImpl.h | 422 |
1 files changed, 422 insertions, 0 deletions
diff --git a/APEX_1.4/module/clothing/include/ClothingCollisionImpl.h b/APEX_1.4/module/clothing/include/ClothingCollisionImpl.h new file mode 100644 index 00000000..efac0473 --- /dev/null +++ b/APEX_1.4/module/clothing/include/ClothingCollisionImpl.h @@ -0,0 +1,422 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, 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. + */ + + +#ifndef CLOTHING_COLLISION_IMPL_H +#define CLOTHING_COLLISION_IMPL_H + +#include "ApexResource.h" +#include "ApexSDKHelpers.h" +#include "ClothingCollision.h" +#include "ApexRWLockable.h" + +#include "ReadCheck.h" +#include "WriteCheck.h" + +namespace nvidia +{ +namespace clothing +{ + +class ClothingActorImpl; + + +class ClothingCollisionImpl : public ApexResource, public ApexResourceInterface, public ApexRWLockable +{ +public: + APEX_RW_LOCKABLE_BOILERPLATE + + ClothingCollisionImpl(ResourceList& list, ClothingActorImpl& owner); + + /* ApexResourceInterface */ + virtual void release(); + + uint32_t getListIndex() const + { + return m_listIndex; + } + void setListIndex(ResourceList& list, uint32_t index) + { + m_listIndex = index; + m_list = &list; + } + + void destroy(); + + void setId(int32_t id) + { + mId = id; + } + int32_t getId() const + { + return mId; + } + + virtual ClothingPlane* isPlane() { READ_ZONE(); return NULL;} + virtual ClothingConvex* isConvex() { READ_ZONE(); return NULL;} + virtual ClothingSphere* isSphere() { READ_ZONE(); return NULL;} + virtual ClothingCapsule* isCapsule() { READ_ZONE(); return NULL;} + virtual ClothingTriangleMesh* isTriangleMesh() { READ_ZONE(); return NULL;} + +protected: + + ClothingActorImpl& mOwner; + bool mInRelease; + + int32_t mId; + +private: + ClothingCollisionImpl& operator=(const ClothingCollisionImpl&); +}; + + +/************************************************************************/ +// ClothingPlaneImpl +/************************************************************************/ +class ClothingPlaneImpl : public ClothingPlane, public ClothingCollisionImpl +{ +public: + APEX_RW_LOCKABLE_BOILERPLATE + + ClothingPlaneImpl(ResourceList& list, ClothingActorImpl& owner, const PxPlane& plane) : + ClothingCollisionImpl(list, owner), + mPlane(plane), + mRefCount(0) + { + } + + virtual ClothingCollisionType::Enum getType() const + { + READ_ZONE(); + return ClothingCollisionType::Plane; + } + virtual ClothingPlane* isPlane() { return this; } + virtual ClothingConvex* isConvex() { return NULL; } + virtual ClothingSphere* isSphere() { return NULL; } + virtual ClothingCapsule* isCapsule() { return NULL; } + virtual ClothingTriangleMesh* isTriangleMesh() { return NULL; } + + virtual void release() + { + if (mRefCount > 0) + { + APEX_DEBUG_WARNING("Cannot release ClothingPlane that is referenced by a ClothingConvex. Release convex first."); + return; + } + + ClothingCollisionImpl::release(); + } + + virtual void setPlane(const PxPlane& plane); + virtual PxPlane& getPlane() + { + return mPlane; + } + + void incRefCount() + { + ++mRefCount; + } + void decRefCount() + { + PX_ASSERT(mRefCount > 0); + --mRefCount; + } + virtual uint32_t getRefCount() const + { + return (uint32_t)mRefCount; + } + +protected: + PxPlane mPlane; + + int32_t mRefCount; +}; + + + +/************************************************************************/ +// ClothingConvexImpl +/************************************************************************/ +class ClothingConvexImpl : public ClothingConvex, public ClothingCollisionImpl +{ +public: + APEX_RW_LOCKABLE_BOILERPLATE + + ClothingConvexImpl(ResourceList& list, ClothingActorImpl& owner, ClothingPlane** planes, uint32_t numPlanes) : + ClothingCollisionImpl(list, owner) + { + mPlanes.resize(numPlanes); + for (uint32_t i = 0; i < numPlanes; ++i) + { + mPlanes[i] = DYNAMIC_CAST(ClothingPlaneImpl*)(planes[i]); + mPlanes[i]->incRefCount(); + } + } + + virtual ClothingCollisionType::Enum getType() const + { + return ClothingCollisionType::Convex; + } + virtual ClothingPlane* isPlane() { return NULL; } + virtual ClothingConvex* isConvex() { return this; } + virtual ClothingSphere* isSphere() { return NULL; } + virtual ClothingCapsule* isCapsule() { return NULL; } + virtual ClothingTriangleMesh* isTriangleMesh() { return NULL; } + + virtual void release() + { + for (uint32_t i = 0; i < mPlanes.size(); ++i) + { + mPlanes[i]->decRefCount(); + } + + ClothingCollisionImpl::release(); + } + + virtual void releaseWithPlanes() + { + for (uint32_t i = 0; i < mPlanes.size(); ++i) + { + mPlanes[i]->decRefCount(); + mPlanes[i]->release(); + } + + ClothingCollisionImpl::release(); + } + + virtual uint32_t getNumPlanes() + { + return mPlanes.size(); + } + + virtual ClothingPlane** getPlanes() + { + return (ClothingPlane**)&mPlanes[0]; + } + +protected: + Array<ClothingPlaneImpl*> mPlanes; +}; + + + + +/************************************************************************/ +// ClothingSphereImpl +/************************************************************************/ +class ClothingSphereImpl : public ClothingSphere, public ClothingCollisionImpl +{ +public: + APEX_RW_LOCKABLE_BOILERPLATE + + ClothingSphereImpl(ResourceList& list, ClothingActorImpl& owner, const PxVec3& position, float radius) : + ClothingCollisionImpl(list, owner), + mPosition(position), + mRadius(radius), + mRefCount(0) + { + } + + virtual ClothingCollisionType::Enum getType() const + { + return ClothingCollisionType::Sphere; + } + virtual ClothingPlane* isPlane() { return NULL; } + virtual ClothingConvex* isConvex() { return NULL; } + virtual ClothingSphere* isSphere() { return this; } + virtual ClothingCapsule* isCapsule() { return NULL; } + virtual ClothingTriangleMesh* isTriangleMesh() { return NULL; } + + virtual void release() + { + if (mRefCount > 0) + { + APEX_DEBUG_WARNING("Cannot release ClothingSphere that is referenced by an ClothingCapsule. Release capsule first."); + return; + } + + ClothingCollisionImpl::release(); + } + + virtual void setPosition(const PxVec3& position); + virtual const PxVec3& getPosition() const + { + return mPosition; + } + + virtual void setRadius(float radius); + virtual float getRadius() const + { + return mRadius; + } + + void incRefCount() + { + ++mRefCount; + } + void decRefCount() + { + PX_ASSERT(mRefCount > 0); + --mRefCount; + } + virtual uint32_t getRefCount() const + { + return mRefCount; + } + +protected: + PxVec3 mPosition; + float mRadius; + + uint32_t mRefCount; +}; + + + + +/************************************************************************/ +// ClothingCapsuleImpl +/************************************************************************/ +class ClothingCapsuleImpl : public ClothingCapsule, public ClothingCollisionImpl +{ +public: + APEX_RW_LOCKABLE_BOILERPLATE + + ClothingCapsuleImpl(ResourceList& list, ClothingActorImpl& owner, ClothingSphere& sphere1, ClothingSphere& sphere2) : + ClothingCollisionImpl(list, owner) + { + mSpheres[0] = (DYNAMIC_CAST(ClothingSphereImpl*)(&sphere1)); + mSpheres[0]->incRefCount(); + + mSpheres[1] = (DYNAMIC_CAST(ClothingSphereImpl*)(&sphere2)); + mSpheres[1]->incRefCount(); + } + + virtual ClothingCollisionType::Enum getType() const + { + return ClothingCollisionType::Capsule; + } + virtual ClothingPlane* isPlane() { return NULL; } + virtual ClothingConvex* isConvex() { return NULL; } + virtual ClothingSphere* isSphere() { return NULL; } + virtual ClothingCapsule* isCapsule() { return this; } + virtual ClothingTriangleMesh* isTriangleMesh() { return NULL; } + + virtual void release() + { + mSpheres[0]->decRefCount(); + mSpheres[1]->decRefCount(); + + ClothingCollisionImpl::release(); + } + + virtual void releaseWithSpheres() + { + mSpheres[0]->decRefCount(); + mSpheres[1]->decRefCount(); + + mSpheres[0]->release(); + mSpheres[1]->release(); + + ClothingCollisionImpl::release(); + } + + virtual ClothingSphere** getSpheres() + { + return (ClothingSphere**)mSpheres; + } + +protected: + ClothingSphereImpl* mSpheres[2]; +}; + + + + +/************************************************************************/ +// ClothingTriangleMeshImpl +/************************************************************************/ + +struct ClothingTriangle +{ + PxVec3 v[3]; + uint32_t id; + + bool operator<(const ClothingTriangle& other) const + { + return id < other.id; + } +}; + +class ClothingTriangleMeshImpl : public ClothingTriangleMesh, public ClothingCollisionImpl +{ +public: + APEX_RW_LOCKABLE_BOILERPLATE + + ClothingTriangleMeshImpl(ResourceList& list, ClothingActorImpl& owner) : + ClothingCollisionImpl(list, owner), + mPose(PxMat44(PxIdentity)) + { + } + + virtual ClothingCollisionType::Enum getType() const + { + return ClothingCollisionType::TriangleMesh; + } + virtual ClothingPlane* isPlane() { return NULL; } + virtual ClothingConvex* isConvex() { return NULL; } + virtual ClothingSphere* isSphere() { return NULL; } + virtual ClothingCapsule* isCapsule() { return NULL; } + virtual ClothingTriangleMesh* isTriangleMesh() { return this; } + + virtual uint32_t lockTriangles(const uint32_t** ids, const PxVec3** triangles); + virtual uint32_t lockTrianglesWrite(const uint32_t** ids, PxVec3** triangles); + virtual void unlockTriangles(); + + virtual void addTriangle(uint32_t id, const PxVec3& v0, const PxVec3& v1, const PxVec3& v2); + virtual void addTriangles(const uint32_t* ids, const PxVec3* triangleVertices, uint32_t numTriangles); + + virtual void removeTriangle(uint32_t id); + virtual void removeTriangles(const uint32_t* ids, uint32_t numTriangles); + virtual void clearTriangles(); + + virtual void release() + { + ClothingCollisionImpl::release(); + } + + virtual void setPose(PxMat44 pose); + virtual const PxMat44& getPose() const + { + return mPose; + } + + void update(const PxTransform& tm, const nvidia::Array<PxVec3>& allTrianglesOld, nvidia::Array<PxVec3>& allTrianglesOldTemp, nvidia::Array<PxVec3>& allTriangles); + +protected: + void sortAddAndRemoves(); + + PxMat44 mPose; + Array<PxVec3> mTriangles; + Array<uint32_t> mIds; + + Array<uint32_t> mRemoved; + Array<ClothingTriangle> mAddedTriangles; + + Mutex mLock; +}; + + +} +} // namespace nvidia + + +#endif // CLOTHING_COLLISION_IMPL_H
\ No newline at end of file |