| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 12 | |
| 13 | |
| 14 | #ifndef PX_PHYSICS_GEOMUTILS_PX_TRIANGLE |
| 15 | #define PX_PHYSICS_GEOMUTILS_PX_TRIANGLE |
| 16 | /** \addtogroup geomutils |
| 17 | @{ |
| 18 | */ |
| 19 | |
| 20 | #include "common/PxPhysXCommonConfig.h" |
| 21 | #include "foundation/PxVec3.h" |
| 22 | |
| 23 | #ifndef PX_DOXYGEN |
| 24 | namespace physx |
| 25 | { |
| 26 | #endif |
| 27 | |
| 28 | /** |
| 29 | \brief Triangle class. |
| 30 | */ |
| 31 | class PxTriangle |
| 32 | { |
| 33 | public: |
| 34 | /** |
| 35 | \brief Constructor |
| 36 | */ |
| 37 | PX_FORCE_INLINE PxTriangle() {} |
| 38 | |
| 39 | /** |
| 40 | \brief Constructor |
| 41 | |
| 42 | \param[in] p0 Point 0 |
| 43 | \param[in] p1 Point 1 |
| 44 | \param[in] p2 Point 2 |
| 45 | */ |
| 46 | PX_FORCE_INLINE PxTriangle(const PxVec3& p0, const PxVec3& p1, const PxVec3& p2) |
| 47 | { |
| 48 | verts[0] = p0; |
| 49 | verts[1] = p1; |
| 50 | verts[2] = p2; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | \brief Copy constructor |
| 55 | |
| 56 | \param[in] triangle Tri to copy |
| 57 | */ |
| 58 | PX_FORCE_INLINE PxTriangle(const PxTriangle& triangle) |
| 59 | { |
| 60 | verts[0] = triangle.verts[0]; |
| 61 | verts[1] = triangle.verts[1]; |
| 62 | verts[2] = triangle.verts[2]; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | \brief Destructor |
| 67 | */ |
| 68 | PX_FORCE_INLINE ~PxTriangle() {} |
| 69 | |
| 70 | /** |
| 71 | \brief Array of Vertices. |
| 72 | */ |
| 73 | PxVec3 verts[3]; |
| 74 | |
| 75 | /** |
| 76 | \brief Compute the normal of the Triangle. |
| 77 | |
| 78 | \param[out] _normal Triangle normal. |
| 79 | */ |
| 80 | PX_FORCE_INLINE void normal(PxVec3& _normal) const |
| 81 | { |
| 82 | _normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]); |
| 83 | _normal.normalize(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | \brief Compute the unnormalized normal of the triangle. |
| 88 | |
| 89 | \param[out] _normal Triangle normal (not normalized). |
| 90 | */ |
| 91 | #ifdef __SPU__ |
| 92 | void denormalizedNormal(PxVec3& _normal) const |
| 93 | #else |
| 94 | PX_FORCE_INLINE void denormalizedNormal(PxVec3& _normal) const |
| 95 | #endif |
| 96 | { |
| 97 | _normal = (verts[1]-verts[0]).cross(verts[2]-verts[0]); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | \brief Compute the area of the triangle. |
| 102 | |
| 103 | \return Area of the triangle. |
| 104 | */ |
| 105 | PX_FORCE_INLINE PxReal area() const |
| 106 | { |
| 107 | const PxVec3& p0 = verts[0]; |
| 108 | const PxVec3& p1 = verts[1]; |
| 109 | const PxVec3& p2 = verts[2]; |
| 110 | return ((p0 - p1).cross(p0 - p2)).magnitude() * 0.5f; |
| 111 | } |
| 112 | |
| 113 | }; |
| 114 | |
| 115 | |
| 116 | #ifndef PX_DOXYGEN |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | /** @} */ |
| 121 | #endif |
| 122 | |