1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | #ifndef PX_PHYSICS_CCT_OBSTACLES |
31 | #define PX_PHYSICS_CCT_OBSTACLES |
32 | /** \addtogroup character |
33 | @{ |
34 | */ |
35 | |
36 | #include "characterkinematic/PxExtended.h" |
37 | #include "geometry/PxGeometry.h" |
38 | |
39 | #if !PX_DOXYGEN |
40 | namespace physx |
41 | { |
42 | #endif |
43 | |
44 | class PxControllerManager; |
45 | |
46 | #define INVALID_OBSTACLE_HANDLE 0xffffffff |
47 | |
48 | /** |
49 | \brief Base class for obstacles. |
50 | |
51 | @see PxBoxObstacle PxCapsuleObstacle PxObstacleContext |
52 | */ |
53 | class PxObstacle |
54 | { |
55 | protected: |
56 | PxObstacle() : |
57 | mType (PxGeometryType::eINVALID), |
58 | mUserData (NULL), |
59 | mPos (0.0, 0.0, 0.0), |
60 | mRot (PxQuat(PxIdentity)) |
61 | {} |
62 | |
63 | PxGeometryType::Enum mType; |
64 | public: |
65 | |
66 | PX_FORCE_INLINE PxGeometryType::Enum getType() const { return mType; } |
67 | |
68 | void* mUserData; |
69 | PxExtendedVec3 mPos; |
70 | PxQuat mRot; |
71 | }; |
72 | |
73 | /** |
74 | \brief A box obstacle. |
75 | |
76 | @see PxObstacle PxCapsuleObstacle PxObstacleContext |
77 | */ |
78 | class PxBoxObstacle : public PxObstacle |
79 | { |
80 | public: |
81 | PxBoxObstacle() : |
82 | mHalfExtents(0.0f) |
83 | { mType = PxGeometryType::eBOX; } |
84 | |
85 | PxVec3 mHalfExtents; |
86 | }; |
87 | |
88 | /** |
89 | \brief A capsule obstacle. |
90 | |
91 | @see PxBoxObstacle PxObstacle PxObstacleContext |
92 | */ |
93 | class PxCapsuleObstacle : public PxObstacle |
94 | { |
95 | public: |
96 | PxCapsuleObstacle() : |
97 | mHalfHeight (0.0f), |
98 | mRadius (0.0f) |
99 | { mType = PxGeometryType::eCAPSULE; } |
100 | |
101 | PxReal mHalfHeight; |
102 | PxReal mRadius; |
103 | }; |
104 | |
105 | typedef PxU32 ObstacleHandle; |
106 | |
107 | /** |
108 | \brief Context class for obstacles. |
109 | |
110 | An obstacle context class contains and manages a set of user-defined obstacles. |
111 | |
112 | @see PxBoxObstacle PxCapsuleObstacle PxObstacle |
113 | */ |
114 | class PxObstacleContext |
115 | { |
116 | public: |
117 | PxObstacleContext() {} |
118 | virtual ~PxObstacleContext() {} |
119 | |
120 | /** |
121 | \brief Releases the context. |
122 | */ |
123 | virtual void release() = 0; |
124 | |
125 | /** |
126 | \brief Retrieves the controller manager associated with this context. |
127 | |
128 | \return The associated controller manager |
129 | */ |
130 | virtual PxControllerManager& getControllerManager() const = 0; |
131 | |
132 | /** |
133 | \brief Adds an obstacle to the context. |
134 | |
135 | \param [in] obstacle Obstacle data for the new obstacle. The data gets copied. |
136 | |
137 | \return Handle for newly-added obstacle |
138 | */ |
139 | virtual ObstacleHandle addObstacle(const PxObstacle& obstacle) = 0; |
140 | |
141 | /** |
142 | \brief Removes an obstacle from the context. |
143 | |
144 | \param [in] handle Handle for the obstacle object that needs to be removed. |
145 | |
146 | \return True if success |
147 | */ |
148 | virtual bool removeObstacle(ObstacleHandle handle) = 0; |
149 | |
150 | /** |
151 | \brief Updates data for an existing obstacle. |
152 | |
153 | \param [in] handle Handle for the obstacle object that needs to be updated. |
154 | \param [in] obstacle New obstacle data |
155 | |
156 | \return True if success |
157 | */ |
158 | virtual bool updateObstacle(ObstacleHandle handle, const PxObstacle& obstacle) = 0; |
159 | |
160 | /** |
161 | \brief Retrieves number of obstacles in the context. |
162 | |
163 | \return Number of obstacles in the context |
164 | */ |
165 | virtual PxU32 getNbObstacles() const = 0; |
166 | |
167 | /** |
168 | \brief Retrieves desired obstacle. |
169 | |
170 | \param [in] i Obstacle index |
171 | |
172 | \return Desired obstacle |
173 | */ |
174 | virtual const PxObstacle* getObstacle(PxU32 i) const = 0; |
175 | |
176 | /** |
177 | \brief Retrieves desired obstacle by given handle. |
178 | |
179 | \param [in] handle Obstacle handle |
180 | |
181 | \return Desired obstacle |
182 | */ |
183 | virtual const PxObstacle* getObstacleByHandle(ObstacleHandle handle) const = 0; |
184 | }; |
185 | |
186 | #if !PX_DOXYGEN |
187 | } |
188 | #endif |
189 | |
190 | /** @} */ |
191 | #endif |
192 | |