[1378] | 1 | #ifndef NX_INTERSECTION_POINT_TRIANGLE
|
---|
| 2 | #define NX_INTERSECTION_POINT_TRIANGLE
|
---|
| 3 | /** \addtogroup physics
|
---|
| 4 | @{
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | #include "Nxp.h"
|
---|
| 8 |
|
---|
| 9 | //namespace NxCollision {
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | \brief Point-in-triangle test.
|
---|
| 13 |
|
---|
| 14 | We use the edges as parameters in case the user has access to edges directly
|
---|
| 15 | This is actually a "point-in-prism" test since it returns true as long as the point is bound by the edge planes.
|
---|
| 16 |
|
---|
| 17 | \warning #NxCreatePhysicsSDK() must be called before using this function.
|
---|
| 18 |
|
---|
| 19 | \param[in] p Point to test. <b>Range:</b> position vector
|
---|
| 20 | \param[in] p0 Triangle vertex. <b>Range:</b> position vector
|
---|
| 21 | \param[in] edge10 Triangle edge. <b>Range:</b> direction vector
|
---|
| 22 | \param[in] edge20 Second triangle edge. <b>Range:</b> direction vector
|
---|
| 23 |
|
---|
| 24 | \return True on intersection
|
---|
| 25 |
|
---|
| 26 | <b>Platform:</b>
|
---|
| 27 | \li PC SW: Yes
|
---|
| 28 | \li PPU : Yes
|
---|
| 29 | \li PS3 : Yes
|
---|
| 30 | \li XB360: Yes
|
---|
| 31 |
|
---|
| 32 | @see NxPointTriangleIntersect2D
|
---|
| 33 | */
|
---|
| 34 | NX_INLINE NX_BOOL NxPointTriangleIntersect(const NxVec3& p, const NxVec3& p0, const NxVec3& edge10, const NxVec3& edge20)
|
---|
| 35 | {
|
---|
| 36 | NxReal a = edge10|edge10;
|
---|
| 37 | NxReal b = edge10|edge20;
|
---|
| 38 | NxReal c = edge20|edge20;
|
---|
| 39 | NxReal ac_bb = (a*c)-(b*b);
|
---|
| 40 |
|
---|
| 41 | NxVec3 vp = p - p0;
|
---|
| 42 |
|
---|
| 43 | NxReal d = vp|edge10;
|
---|
| 44 | NxReal e = vp|edge20;
|
---|
| 45 |
|
---|
| 46 | NxReal x = (d*c) - (e*b);
|
---|
| 47 | NxReal y = (e*a) - (d*b);
|
---|
| 48 | NxReal z = x + y - ac_bb;
|
---|
| 49 |
|
---|
| 50 | // Same as: if(x>0.0f && y>0.0f && z<0.0f) return TRUE;
|
---|
| 51 | // else return FALSE;
|
---|
| 52 | return (( NX_IR(z) & ~(NX_IR(x)|NX_IR(y)) ) & NX_SIGN_BITMASK);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | \brief Dedicated 2D version of previous test
|
---|
| 57 |
|
---|
| 58 | \warning #NxCreatePhysicsSDK() must be called before using this function.
|
---|
| 59 |
|
---|
| 60 | \param[in] px Point to test, X
|
---|
| 61 | \param[in] pz Point to test, Z
|
---|
| 62 | \param[in] p0x Vertex of triangle to test, X
|
---|
| 63 | \param[in] p0z Vertex of triangle to test, Z
|
---|
| 64 | \param[in] e10x Edge of triangle to test, X
|
---|
| 65 | \param[in] e10z Edge of triangle to test, Y
|
---|
| 66 | \param[in] e20x Second edge of triangle to test, X
|
---|
| 67 | \param[in] e20z Second edge of triangle to test, Y
|
---|
| 68 |
|
---|
| 69 | \return True on intersection
|
---|
| 70 |
|
---|
| 71 | <b>Platform:</b>
|
---|
| 72 | \li PC SW: Yes
|
---|
| 73 | \li PPU : Yes
|
---|
| 74 | \li PS3 : Yes
|
---|
| 75 | \li XB360: Yes
|
---|
| 76 |
|
---|
| 77 | @see NxPointTriangleIntersect
|
---|
| 78 | */
|
---|
| 79 | NX_INLINE NX_BOOL NxPointTriangleIntersect2D(
|
---|
| 80 | NxReal px, NxReal pz,
|
---|
| 81 | NxReal p0x, NxReal p0z,
|
---|
| 82 | NxReal e10x, NxReal e10z,
|
---|
| 83 | NxReal e20x, NxReal e20z)
|
---|
| 84 | {
|
---|
| 85 | NxReal a = e10x*e10x + e10z*e10z;
|
---|
| 86 | NxReal b = e10x*e20x + e10z*e20z;
|
---|
| 87 | NxReal c = e20x*e20x + e20z*e20z;
|
---|
| 88 | NxReal ac_bb = (a*c)-(b*b);
|
---|
| 89 |
|
---|
| 90 | NxReal vpx = px - p0x;
|
---|
| 91 | NxReal vpz = pz - p0z;
|
---|
| 92 |
|
---|
| 93 | NxReal d = vpx*e10x + vpz*e10z;
|
---|
| 94 | NxReal e = vpx*e20x + vpz*e20z;
|
---|
| 95 |
|
---|
| 96 | NxReal x = (d*c) - (e*b);
|
---|
| 97 | NxReal y = (e*a) - (d*b);
|
---|
| 98 | NxReal z = x + y - ac_bb;
|
---|
| 99 |
|
---|
| 100 | // Same as: if(x>0.0f && y>0.0f && z<0.0f) return TRUE;
|
---|
| 101 | // else return FALSE;
|
---|
| 102 | return (( NX_IR(z) & ~(NX_IR(x)|NX_IR(y)) ) & NX_SIGN_BITMASK);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | //}
|
---|
| 106 |
|
---|
| 107 | /** @} */
|
---|
| 108 | #endif
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | //AGCOPYRIGHTBEGIN
|
---|
| 112 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 113 | // Copyright © 2005 AGEIA Technologies.
|
---|
| 114 | // All rights reserved. www.ageia.com
|
---|
| 115 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 116 | //AGCOPYRIGHTEND
|
---|
| 117 |
|
---|