aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/GeomUtils/src/intersection/GuIntersectionEdgeEdge.cpp
diff options
context:
space:
mode:
authorgit perforce import user <a@b>2016-10-25 12:29:14 -0600
committerSheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees>2016-10-25 18:56:37 -0500
commit3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch)
treefa6485c169e50d7415a651bf838f5bcd0fd3bfbd /PhysX_3.4/Source/GeomUtils/src/intersection/GuIntersectionEdgeEdge.cpp
downloadphysx-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/intersection/GuIntersectionEdgeEdge.cpp')
-rw-r--r--PhysX_3.4/Source/GeomUtils/src/intersection/GuIntersectionEdgeEdge.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/PhysX_3.4/Source/GeomUtils/src/intersection/GuIntersectionEdgeEdge.cpp b/PhysX_3.4/Source/GeomUtils/src/intersection/GuIntersectionEdgeEdge.cpp
new file mode 100644
index 00000000..3f828ba5
--- /dev/null
+++ b/PhysX_3.4/Source/GeomUtils/src/intersection/GuIntersectionEdgeEdge.cpp
@@ -0,0 +1,84 @@
+// 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 "GuIntersectionEdgeEdge.h"
+#include "PsMathUtils.h"
+#include "CmPhysXCommon.h"
+
+using namespace physx;
+
+bool Gu::intersectEdgeEdge(const PxVec3& p1, const PxVec3& p2, const PxVec3& dir, const PxVec3& p3, const PxVec3& p4, PxReal& dist, PxVec3& ip)
+{
+ const PxVec3 v1 = p2 - p1;
+
+ // Build plane P based on edge (p1, p2) and direction (dir)
+ PxPlane plane;
+ plane.n = v1.cross(dir);
+ plane.d = -(plane.n.dot(p1));
+
+ // if colliding edge (p3,p4) does not cross plane return no collision
+ // same as if p3 and p4 on same side of plane return 0
+ //
+ // Derivation:
+ // d3 = d(p3, P) = (p3 | plane.n) - plane.d; Reversed sign compared to Plane::Distance() because plane.d is negated.
+ // d4 = d(p4, P) = (p4 | plane.n) - plane.d; Reversed sign compared to Plane::Distance() because plane.d is negated.
+ // if d3 and d4 have the same sign, they're on the same side of the plane => no collision
+ // We test both sides at the same time by only testing Sign(d3 * d4).
+ // ### put that in the Plane class
+ // ### also check that code in the triangle class that might be similar
+ const PxReal d3 = plane.distance(p3);
+ PxReal temp = d3 * plane.distance(p4);
+ if(temp>0.0f) return false;
+
+ // if colliding edge (p3,p4) and plane are parallel return no collision
+ PxVec3 v2 = p4 - p3;
+
+ temp = plane.n.dot(v2);
+ if(temp==0.0f) return false; // ### epsilon would be better
+
+ // compute intersection point of plane and colliding edge (p3,p4)
+ ip = p3-v2*(d3/temp);
+
+ // find largest 2D plane projection
+ PxU32 i,j;
+ Ps::closestAxis(plane.n, i, j);
+
+ // compute distance of intersection from line (ip, -dir) to line (p1,p2)
+ dist = (v1[i]*(ip[j]-p1[j])-v1[j]*(ip[i]-p1[i]))/(v1[i]*dir[j]-v1[j]*dir[i]);
+ if(dist<0.0f) return false;
+
+ // compute intersection point on edge (p1,p2) line
+ ip -= dist*dir;
+
+ // check if intersection point (ip) is between edge (p1,p2) vertices
+ temp = (p1.x-ip.x)*(p2.x-ip.x)+(p1.y-ip.y)*(p2.y-ip.y)+(p1.z-ip.z)*(p2.z-ip.z);
+ if(temp<1e-3f) return true; // collision found
+
+ return false; // no collision
+}