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 | |
31 | #ifndef PX_PHYSICS_CCT_BOX_CONTROLLER |
32 | #define PX_PHYSICS_CCT_BOX_CONTROLLER |
33 | /** \addtogroup character |
34 | @{ |
35 | */ |
36 | |
37 | #include "characterkinematic/PxController.h" |
38 | |
39 | #if !PX_DOXYGEN |
40 | namespace physx |
41 | { |
42 | #endif |
43 | |
44 | /** |
45 | \brief Descriptor for a box character controller. |
46 | |
47 | @see PxBoxController PxControllerDesc |
48 | */ |
49 | class PxBoxControllerDesc : public PxControllerDesc |
50 | { |
51 | public: |
52 | /** |
53 | \brief constructor sets to default. |
54 | */ |
55 | PX_INLINE PxBoxControllerDesc(); |
56 | PX_INLINE virtual ~PxBoxControllerDesc() {} |
57 | |
58 | /** |
59 | \brief copy constructor. |
60 | */ |
61 | PX_INLINE PxBoxControllerDesc(const PxBoxControllerDesc&); |
62 | |
63 | /** |
64 | \brief assignment operator. |
65 | */ |
66 | PX_INLINE PxBoxControllerDesc& operator=(const PxBoxControllerDesc&); |
67 | |
68 | /** |
69 | \brief (re)sets the structure to the default. |
70 | */ |
71 | PX_INLINE virtual void setToDefault(); |
72 | |
73 | /** |
74 | \brief returns true if the current settings are valid |
75 | |
76 | \return True if the descriptor is valid. |
77 | */ |
78 | PX_INLINE virtual bool isValid() const; |
79 | |
80 | /** |
81 | \brief Half height |
82 | |
83 | <b>Default:</b> 1.0 |
84 | */ |
85 | PxF32 halfHeight; // Half-height in the "up" direction |
86 | |
87 | /** |
88 | \brief Half side extent |
89 | |
90 | <b>Default:</b> 0.5 |
91 | */ |
92 | PxF32 halfSideExtent; // Half-extent in the "side" direction |
93 | |
94 | /** |
95 | \brief Half forward extent |
96 | |
97 | <b>Default:</b> 0.5 |
98 | */ |
99 | PxF32 halfForwardExtent; // Half-extent in the "forward" direction |
100 | |
101 | protected: |
102 | PX_INLINE void copy(const PxBoxControllerDesc&); |
103 | }; |
104 | |
105 | PX_INLINE PxBoxControllerDesc::PxBoxControllerDesc() : |
106 | PxControllerDesc (PxControllerShapeType::eBOX), |
107 | halfHeight (1.0f), |
108 | halfSideExtent (0.5f), |
109 | halfForwardExtent (0.5f) |
110 | { |
111 | } |
112 | |
113 | PX_INLINE PxBoxControllerDesc::PxBoxControllerDesc(const PxBoxControllerDesc& other) : PxControllerDesc(other) |
114 | { |
115 | copy(other); |
116 | } |
117 | |
118 | PX_INLINE PxBoxControllerDesc& PxBoxControllerDesc::operator=(const PxBoxControllerDesc& other) |
119 | { |
120 | PxControllerDesc::operator=(other); |
121 | copy(other); |
122 | return *this; |
123 | } |
124 | |
125 | PX_INLINE void PxBoxControllerDesc::copy(const PxBoxControllerDesc& other) |
126 | { |
127 | halfHeight = other.halfHeight; |
128 | halfSideExtent = other.halfSideExtent; |
129 | halfForwardExtent = other.halfForwardExtent; |
130 | } |
131 | |
132 | PX_INLINE void PxBoxControllerDesc::setToDefault() |
133 | { |
134 | *this = PxBoxControllerDesc(); |
135 | } |
136 | |
137 | PX_INLINE bool PxBoxControllerDesc::isValid() const |
138 | { |
139 | if(!PxControllerDesc::isValid()) return false; |
140 | if(halfHeight<=0.0f) return false; |
141 | if(halfSideExtent<=0.0f) return false; |
142 | if(halfForwardExtent<=0.0f) return false; |
143 | if(stepOffset>2.0f*halfHeight) return false; // Prevents obvious mistakes |
144 | return true; |
145 | } |
146 | |
147 | /** |
148 | \brief Box character controller. |
149 | |
150 | @see PxBoxControllerDesc PxController |
151 | */ |
152 | class PxBoxController : public PxController |
153 | { |
154 | public: |
155 | |
156 | /** |
157 | \brief Gets controller's half height. |
158 | |
159 | \return The half height of the controller. |
160 | |
161 | @see PxBoxControllerDesc.halfHeight setHalfHeight() |
162 | */ |
163 | virtual PxF32 getHalfHeight() const = 0; |
164 | |
165 | /** |
166 | \brief Gets controller's half side extent. |
167 | |
168 | \return The half side extent of the controller. |
169 | |
170 | @see PxBoxControllerDesc.halfSideExtent setHalfSideExtent() |
171 | */ |
172 | virtual PxF32 getHalfSideExtent() const = 0; |
173 | |
174 | /** |
175 | \brief Gets controller's half forward extent. |
176 | |
177 | \return The half forward extent of the controller. |
178 | |
179 | @see PxBoxControllerDesc.halfForwardExtent setHalfForwardExtent() |
180 | */ |
181 | virtual PxF32 getHalfForwardExtent() const = 0; |
182 | |
183 | /** |
184 | \brief Sets controller's half height. |
185 | |
186 | \warning this doesn't check for collisions. |
187 | |
188 | \param[in] halfHeight The new half height for the controller. |
189 | \return Currently always true. |
190 | |
191 | @see PxBoxControllerDesc.halfHeight getHalfHeight() |
192 | */ |
193 | virtual bool setHalfHeight(PxF32 halfHeight) = 0; |
194 | |
195 | /** |
196 | \brief Sets controller's half side extent. |
197 | |
198 | \warning this doesn't check for collisions. |
199 | |
200 | \param[in] halfSideExtent The new half side extent for the controller. |
201 | \return Currently always true. |
202 | |
203 | @see PxBoxControllerDesc.halfSideExtent getHalfSideExtent() |
204 | */ |
205 | virtual bool setHalfSideExtent(PxF32 halfSideExtent) = 0; |
206 | |
207 | /** |
208 | \brief Sets controller's half forward extent. |
209 | |
210 | \warning this doesn't check for collisions. |
211 | |
212 | \param[in] halfForwardExtent The new half forward extent for the controller. |
213 | \return Currently always true. |
214 | |
215 | @see PxBoxControllerDesc.halfForwardExtent getHalfForwardExtent() |
216 | */ |
217 | virtual bool setHalfForwardExtent(PxF32 halfForwardExtent) = 0; |
218 | |
219 | protected: |
220 | PX_INLINE PxBoxController() {} |
221 | virtual ~PxBoxController() {} |
222 | }; |
223 | |
224 | #if !PX_DOXYGEN |
225 | } // namespace physx |
226 | #endif |
227 | |
228 | /** @} */ |
229 | #endif |
230 | |