PxPlane.h
Go to the documentation of this file.
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_FOUNDATION_PX_PLANE_H
15 #define PX_FOUNDATION_PX_PLANE_H
16 
21 #include "foundation/PxMath.h"
22 #include "foundation/PxVec3.h"
23 
24 #ifndef PX_DOXYGEN
25 namespace physx
26 {
27 #endif
28 
34 class PxPlane
35 {
36 public:
41  {
42  }
43 
48  : n(nx, ny, nz)
49  , d(distance)
50  {
51  }
52 
57  : n(normal)
58  , d(distance)
59  {
60  }
61 
62 
66  PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3& point, const PxVec3& normal)
67  : n(normal)
68  , d(-point.dot(n)) // p satisfies normal.dot(p) + d = 0
69  {
70  }
71 
75  PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3& p0, const PxVec3& p1, const PxVec3& p2)
76  {
77  n = (p1 - p0).cross(p2 - p0).getNormalized();
78  d = -p0.dot(n);
79  }
80 
84  PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxPlane& p) const { return n == p.n && d == p.d; }
85 
86  PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal distance(const PxVec3& p) const
87  {
88  return p.dot(n) + d;
89  }
90 
91  PX_CUDA_CALLABLE PX_FORCE_INLINE bool contains(const PxVec3& p) const
92  {
93  return PxAbs(distance(p)) < (1.0e-7f);
94  }
95 
99  PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 project(const PxVec3 & p) const
100  {
101  return p - n * distance(p);
102  }
103 
108  {
109  return -n*d;
110  }
111 
117  {
118  PxReal denom = 1.0f / n.magnitude();
119  n *= denom;
120  d *= denom;
121  }
122 
123 
126 };
127 
128 #ifndef PX_DOXYGEN
129 } // namespace physx
130 #endif
131 
133 #endif
134 


Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com