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_VEHICLE_UPDATE_H |
31 | #define PX_VEHICLE_UPDATE_H |
32 | /** \addtogroup vehicle |
33 | @{ |
34 | */ |
35 | |
36 | #include "vehicle/PxVehicleSDK.h" |
37 | #include "vehicle/PxVehicleTireFriction.h" |
38 | #include "foundation/PxSimpleTypes.h" |
39 | #include "foundation/PxMemory.h" |
40 | #include "foundation/PxTransform.h" |
41 | #include "PxBatchQueryDesc.h" |
42 | |
43 | #if !PX_DOXYGEN |
44 | namespace physx |
45 | { |
46 | #endif |
47 | |
48 | class PxBatchQuery; |
49 | class PxContactModifyPair; |
50 | class PxVehicleWheels; |
51 | class PxVehicleDrivableSurfaceToTireFrictionPairs; |
52 | class PxVehicleTelemetryData; |
53 | |
54 | /** |
55 | \brief Structure containing data describing the non-persistent state of each suspension/wheel/tire unit. |
56 | This structure is filled out in PxVehicleUpdates and PxVehicleUpdateSingleVehicleAndStoreTelemetryData |
57 | @see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData |
58 | */ |
59 | struct PxWheelQueryResult |
60 | { |
61 | PxWheelQueryResult() |
62 | { |
63 | PxMemZero(dest: this, count: sizeof(PxWheelQueryResult)); |
64 | isInAir=true; |
65 | tireSurfaceType = PxU32(PxVehicleDrivableSurfaceType::eSURFACE_TYPE_UNKNOWN); |
66 | localPose = PxTransform(PxIdentity); |
67 | } |
68 | |
69 | /** |
70 | \brief Start point of suspension line raycast/sweep used in the raycast/sweep completed immediately before PxVehicleUpdates. |
71 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored. |
72 | @see PxVehicleSuspensionRaycasts, PxVehicleSuspensionRaycasts |
73 | */ |
74 | PxVec3 suspLineStart; |
75 | |
76 | /** |
77 | \brief Directions of suspension line raycast/sweep used in the raycast/sweep completed immediately before PxVehicleUpdates. |
78 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored. |
79 | @see PxVehicleSuspensionRaycasts, PxVehicleSuspensionRaycasts |
80 | */ |
81 | PxVec3 suspLineDir; |
82 | |
83 | /** |
84 | \brief Lengths of suspension line raycast/sweep used in raycast/sweep completed immediately before PxVehicleUpdates. |
85 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then 0 is stored. |
86 | @see PxVehicleSuspensionRaycasts, PxVehicleSuspensionRaycasts |
87 | */ |
88 | PxReal suspLineLength; |
89 | |
90 | /** |
91 | \brief If suspension travel limits forbid the wheel from touching the drivable surface then isInAir is true. |
92 | \note If the wheel can be placed on the contact plane of the most recent suspension line raycast/sweep then isInAir is false. |
93 | \note If #PxVehicleWheelsSimFlag::eLIMIT_SUSPENSION_EXPANSION_VELOCITY is set, then isInAir will also be true if the suspension |
94 | force is not large enough to expand to the target length in the given simulation time step. |
95 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then isInAir |
96 | is computed using the contact plane that was hit by the most recent suspension line raycast/sweep. |
97 | */ |
98 | bool isInAir; |
99 | |
100 | /** |
101 | \brief PxActor instance of the driving surface under the corresponding vehicle wheel. |
102 | \note If suspension travel limits forbid the wheel from touching the drivable surface then tireContactActor is NULL. |
103 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then NULL is stored. |
104 | */ |
105 | PxActor* tireContactActor; |
106 | |
107 | /** |
108 | \brief PxShape instance of the driving surface under the corresponding vehicle wheel. |
109 | \note If suspension travel limits forbid the wheel from touching the drivable surface then tireContactShape is NULL. |
110 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then NULL is stored. |
111 | */ |
112 | PxShape* tireContactShape; |
113 | |
114 | /** |
115 | \brief PxMaterial instance of the driving surface under the corresponding vehicle wheel. |
116 | \note If suspension travel limits forbid the wheel from touching the drivable surface then tireSurfaceMaterial is NULL. |
117 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then NULL is stored. |
118 | */ |
119 | const PxMaterial* tireSurfaceMaterial; |
120 | |
121 | /** |
122 | \brief Surface type integer that corresponds to the mapping between tireSurfaceMaterial and integer as |
123 | described in PxVehicleDrivableSurfaceToTireFrictionPairs. |
124 | \note If suspension travel limits forbid the wheel from touching the drivable surface then tireSurfaceType is |
125 | PxVehicleDrivableSurfaceType::eSURFACE_TYPE_UNKNOWN. |
126 | \note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then |
127 | PxVehicleDrivableSurfaceType::eSURFACE_TYPE_UNKNOWN is stored. |
128 | @see PxVehicleDrivableSurfaceToTireFrictionPairs |
129 | */ |
130 | PxU32 tireSurfaceType; |
131 | |
132 | /** |
133 | \brief Point on the drivable surface hit by the most recent suspension raycast or sweep. |
134 | \note If suspension travel limits forbid the wheel from touching the drivable surface then the contact point is (0,0,0). |
135 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored. |
136 | */ |
137 | PxVec3 tireContactPoint; |
138 | |
139 | /** |
140 | \brief Normal on the drivable surface at the hit point of the most recent suspension raycast or sweep. |
141 | \note If suspension travel limits forbid the wheel from touching the drivable surface then the contact normal is (0,0,0). |
142 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored. |
143 | */ |
144 | PxVec3 tireContactNormal; |
145 | |
146 | /** |
147 | \brief Friction experienced by the tire for the combination of tire type and surface type after accounting |
148 | for the friction vs slip graph. |
149 | \note If suspension travel limits forbid the wheel from touching the drivable surface then the tire friction is 0. |
150 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the |
151 | stored tire friction is the value computed in PxVehicleUpdates that immediately followed the last raycast or sweep. |
152 | @see PxVehicleDrivableSurfaceToTireFrictionPairs, PxVehicleTireData |
153 | */ |
154 | PxReal tireFriction; |
155 | |
156 | /** |
157 | \brief Compression of the suspension spring. |
158 | \note If suspension travel limits forbid the wheel from touching the drivable surface then the jounce is -PxVehicleSuspensionData.mMaxDroop |
159 | The jounce can never exceed PxVehicleSuspensionData.mMaxCompression. Positive values result when the suspension is compressed from |
160 | the rest position, while negative values mean the suspension is elongated from the rest position. |
161 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the |
162 | suspension compression is computed using the contact plane that was hit by the most recent suspension line raycast or sweep. |
163 | */ |
164 | PxReal suspJounce; |
165 | |
166 | /** |
167 | \brief Magnitude of force applied by the suspension spring along the direction of suspension travel. |
168 | \note If suspension travel limits forbid the wheel from touching the drivable surface then the force is 0 |
169 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the |
170 | suspension spring force is computed using the contact plane that was hit by the most recent suspension line raycast or sweep. |
171 | @see PxVehicleWheelsSimData::getSuspTravelDirection |
172 | */ |
173 | PxReal suspSpringForce; |
174 | |
175 | /** |
176 | \brief Forward direction of the wheel/tire accounting for steer/toe/camber angle projected on to the contact plane of the drivable surface. |
177 | \note If suspension travel limits forbid the wheel from touching the drivable surface then tireLongitudinalDir is (0,0,0) |
178 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the |
179 | tire longitudinal direction is computed using the contact plane that was hit by the most recent suspension line raycast or sweep. |
180 | */ |
181 | PxVec3 tireLongitudinalDir; |
182 | |
183 | /** |
184 | \brief Lateral direction of the wheel/tire accounting for steer/toe/camber angle projected on to the contact plan of the drivable surface. |
185 | \note If suspension travel limits forbid the wheel from touching the drivable surface then tireLateralDir is (0,0,0) |
186 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the |
187 | tire lateral direction is computed using the contact plane that was hit by the most recent suspension line raycast or sweep. |
188 | */ |
189 | PxVec3 tireLateralDir; |
190 | |
191 | /** |
192 | \brief Longitudinal slip of the tire. |
193 | \note If suspension travel limits forbid the wheel from touching the drivable surface then longitudinalSlip is 0.0 |
194 | \note The longitudinal slip is approximately (w*r - vz) / PxAbs(vz) where w is the angular speed of the wheel, r is the radius of the wheel, and |
195 | vz component of rigid body velocity computed at the wheel base along the longitudinal direction of the tire. |
196 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the |
197 | tire longitudinal slip is computed using the contact plane that was hit by the most recent suspension line raycast or sweep. |
198 | */ |
199 | PxReal longitudinalSlip; |
200 | |
201 | /** |
202 | \brief Lateral slip of the tire. |
203 | \note If suspension travel limits forbid the wheel from touching the drivable surface then lateralSlip is 0.0 |
204 | \note The lateral slip angle is approximately PxAtan(vx / PxAbs(vz)) where vx and vz are the components of rigid body velocity at the wheel base |
205 | along the wheel's lateral and longitudinal directions, respectively. |
206 | \note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the |
207 | tire lateral slip is computed using the contact plane that was hit by the most recent suspension line raycast or sweep. |
208 | */ |
209 | PxReal lateralSlip; |
210 | |
211 | /** |
212 | \brief Steer angle of the wheel about the "up" vector accounting for input steer and toe and, if applicable, Ackermann steer correction. |
213 | @see PxVehicleWheelData::mToeAngle |
214 | */ |
215 | PxReal steerAngle; |
216 | |
217 | /** |
218 | \brief Local pose of the wheel. |
219 | */ |
220 | PxTransform localPose; |
221 | }; |
222 | |
223 | struct PxVehicleWheelQueryResult |
224 | { |
225 | /** |
226 | \brief Pointer to an PxWheelQueryResult buffer of length nbWheelQueryResults |
227 | The wheelQueryResults buffer must persist until the end of PxVehicleUpdates |
228 | A NULL pointer is permitted. |
229 | The wheelQueryResults buffer is left unmodified in PxVehicleUpdates for vehicles with sleeping rigid bodies |
230 | whose control inputs indicate they should remain inert. |
231 | @see PxVehicleUpdates |
232 | */ |
233 | PxWheelQueryResult* wheelQueryResults; |
234 | |
235 | /** |
236 | \brief The length of the wheelQueryResults buffer. This value corresponds to the |
237 | number of wheels in the associated vehicle in PxVehicleUpdates. |
238 | */ |
239 | PxU32 nbWheelQueryResults; |
240 | }; |
241 | |
242 | /** |
243 | \brief Structure containing data that is computed for a wheel during concurrent calls to PxVehicleUpdates or |
244 | PxVehicleUpdateSingleVehicleAndStoreTelemetryData but which cannot be safely concurrently applied. |
245 | |
246 | @see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData, PxVehiclePostUpdates, PxVehicleConcurrentUpdate |
247 | */ |
248 | struct PxVehicleWheelConcurrentUpdateData |
249 | { |
250 | friend class PxVehicleUpdate; |
251 | |
252 | PxVehicleWheelConcurrentUpdateData() |
253 | : localPose(PxTransform(PxIdentity)), |
254 | hitActor(NULL), |
255 | hitActorForce(PxVec3(0,0,0)), |
256 | hitActorForcePosition(PxVec3(0,0,0)) |
257 | { |
258 | } |
259 | |
260 | private: |
261 | |
262 | PxTransform localPose; |
263 | PxRigidDynamic* hitActor; |
264 | PxVec3 hitActorForce; |
265 | PxVec3 hitActorForcePosition; |
266 | }; |
267 | |
268 | /** |
269 | \brief Structure containing data that is computed for a vehicle and its wheels during concurrent calls to PxVehicleUpdates or |
270 | PxVehicleUpdateSingleVehicleAndStoreTelemetryData but which cannot be safely concurrently applied. |
271 | |
272 | @see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData, PxVehiclePostUpdates, PxVehicleWheelConcurrentUpdateData |
273 | */ |
274 | |
275 | struct PxVehicleConcurrentUpdateData |
276 | { |
277 | friend class PxVehicleUpdate; |
278 | |
279 | PxVehicleConcurrentUpdateData() |
280 | : concurrentWheelUpdates(NULL), |
281 | nbConcurrentWheelUpdates(0), |
282 | linearMomentumChange(PxVec3(0,0,0)), |
283 | angularMomentumChange(PxVec3(0,0,0)), |
284 | staySleeping(false), |
285 | wakeup(false) |
286 | { |
287 | } |
288 | |
289 | /** |
290 | \brief Pointer to an PxVehicleWheelConcurrentUpdate buffer of length nbConcurrentWheelUpdates |
291 | The concurrentWheelUpdates buffer must persist until the end of PxVehiclePostUpdates |
292 | A NULL pointer is not permitted. |
293 | @see PxVehicleUpdates, PxVehiclePostUpdates |
294 | */ |
295 | PxVehicleWheelConcurrentUpdateData* concurrentWheelUpdates; |
296 | |
297 | /** |
298 | \brief The length of the concurrentWheelUpdates buffer. This value corresponds to the |
299 | number of wheels in the associated vehicle passed to PxVehicleUpdates. |
300 | */ |
301 | PxU32 nbConcurrentWheelUpdates; |
302 | |
303 | private: |
304 | |
305 | PxVec3 linearMomentumChange; |
306 | PxVec3 angularMomentumChange; |
307 | bool staySleeping; |
308 | bool wakeup; |
309 | }; |
310 | |
311 | /** |
312 | \brief Perform raycasts for all suspension lines for all vehicles. |
313 | |
314 | \param[in] batchQuery is a PxBatchQuery instance used to specify shader data and functions for the raycast scene queries. |
315 | |
316 | \param[in] nbVehicles is the number of vehicles in the vehicles array. |
317 | |
318 | \param[in] vehicles is an array of all vehicles that are to have a raycast issued from each wheel. |
319 | |
320 | \param[in] nbSceneQueryResults must be greater than or equal to the total number of wheels of all the vehicles in the vehicles array; that is, |
321 | sceneQueryResults must have dimensions large enough for one raycast hit result per wheel for all the vehicles in the vehicles array. |
322 | |
323 | \param[in] sceneQueryResults must persist without being overwritten until the end of the next PxVehicleUpdates call. |
324 | |
325 | \param[in] vehiclesToRaycast is an array of bools of length nbVehicles that is used to decide if raycasts will be performed for the corresponding vehicle |
326 | in the vehicles array. If vehiclesToRaycast[i] is true then suspension line raycasts will be performed for vehicles[i]. If vehiclesToRaycast[i] is |
327 | false then suspension line raycasts will not be performed for vehicles[i]. |
328 | |
329 | \note If vehiclesToRaycast is NULL then raycasts are performed for all vehicles in the vehicles array. |
330 | |
331 | \note If vehiclesToRaycast[i] is false then the vehicle stored in vehicles[i] will automatically use the raycast or sweep hit planes recorded by the most recent |
332 | suspension sweeps or raycasts for that vehicle. For vehicles far from the camera or not visible on the screen it can be |
333 | optimal to only perform suspension line raycasts every Nth update rather than every single update. The accuracy of the cached contact plane |
334 | naturally diminishes as N increase, meaning that wheels might start to hover or intersect the ground for large values of N or even with values close to 1 in |
335 | conjunction with large vehicle speeds and/or geometry that has low spatial coherence. |
336 | |
337 | \note Calling setToRestState invalidates any cached hit planes. Prior to calling PxVehicleUpdates each vehicle needs to perform suspension line raycasts |
338 | or sweeps at least once after instantiation and at least once after calling setToRestState. |
339 | |
340 | \note Each raycast casts along the suspension travel direction from the position of the top of the wheel at maximum suspension compression |
341 | to the position of the base of the wheel at maximum droop. Raycasts that start inside a PxShape are subsequently ignored by the |
342 | corresponding vehicle. |
343 | |
344 | \note Only blocking hits are supported (PxQueryHitType::eBLOCK). |
345 | |
346 | @see PxVehicleDrive4W::setToRestState, PxVehicleDriveNW::setToRestState, PxVehicleDriveTank::setToRestState, PxVehicleNoDrive::setToRestState |
347 | */ |
348 | void PxVehicleSuspensionRaycasts |
349 | (PxBatchQuery* batchQuery, |
350 | const PxU32 nbVehicles, PxVehicleWheels** vehicles, |
351 | const PxU32 nbSceneQueryResults, PxRaycastQueryResult* sceneQueryResults, |
352 | const bool* vehiclesToRaycast = NULL); |
353 | |
354 | |
355 | /** |
356 | \brief Perform sweeps for all suspension lines for all vehicles. |
357 | |
358 | \param[in] batchQuery is a PxBatchQuery instance used to specify shader data and functions for the sweep scene queries. |
359 | |
360 | \param[in] nbVehicles is the number of vehicles in the vehicles array. |
361 | |
362 | \param[in] vehicles is an array of all vehicles that are to have a sweep issued from each wheel. |
363 | |
364 | \param[in] nbSceneQueryResults must be greater than or equal to the total number of wheels of all the vehicles in the vehicles array; that is, |
365 | sceneQueryResults must have dimensions large enough for one sweep hit result per wheel for all the vehicles in the vehicles array. |
366 | |
367 | \param[in] sceneQueryResults must persist without being overwritten until the end of the next PxVehicleUpdates call. |
368 | |
369 | \param[in] nbHitsPerQuery is the maximum numbers of hits that will be returned for each query. |
370 | |
371 | \param[in] vehiclesToSweep is an array of bools of length nbVehicles that is used to decide if sweeps will be performed for the corresponding vehicle |
372 | in the vehicles array. If vehiclesToSweep[i] is true then suspension sweeps will be performed for vehicles[i]. If vehiclesToSweep[i] is |
373 | false then suspension sweeps will not be performed for vehicles[i]. |
374 | |
375 | \param[in] sweepWidthScale scales the geometry of the wheel used in the sweep. Values < 1 result in a thinner swept wheel, while values > 1 result in a fatter swept wheel. |
376 | |
377 | \param[in] sweepRadiusScale scales the geometry of the wheel used in the sweep. Values < 1 result in a larger swept wheel, while values > 1 result in a smaller swept wheel. |
378 | |
379 | \param[in] sweepInflation Inflation parameter for sweeps. This is the inflation parameter from PxScene::sweep(). It inflates the shape and makes it rounder, |
380 | which gives smoother and more reliable normals. |
381 | |
382 | \note If vehiclesToSweep is NULL then sweeps are performed for all vehicles in the vehicles array. |
383 | |
384 | \note If vehiclesToSweep[i] is false then the vehicle stored in vehicles[i] will automatically use the most recent sweep or raycast hit planes |
385 | recorded by the most recent suspension sweeps or raycasts for that vehicle. For vehicles far from the camera or not visible on the screen it can be |
386 | optimal to only perform suspension queries every Nth update rather than every single update. The accuracy of the cached contact plane |
387 | naturally diminishes as N increase, meaning that wheels might start to hover or intersect the ground for large values of N or even with values close to 1 in |
388 | conjunction with large vehicle speeds and/or geometry that has low spatial coherence. |
389 | |
390 | \note Calling setToRestState invalidates any cached hit planes. Prior to calling PxVehicleUpdates each vehicle needs to perform suspension raycasts |
391 | or sweeps at least once after instantiation and at least once after calling setToRestState. |
392 | |
393 | \note Each sweep casts the wheel's shape along the suspension travel direction from the position of the top of the wheel at maximum suspension compression |
394 | to the position of the base of the wheel at maximum droop. Sweeps that start inside a PxShape are subsequently ignored by the |
395 | corresponding vehicle. |
396 | |
397 | \note A scale can be applied to the shape so that a modified shape is swept through the scene. The parameters sweepWidthScale and sweepRadiusScale scale the |
398 | swept wheel shape in the width and radial directions. It is sometimes a good idea to sweep a thinner wheel to allow contact with other dynamic actors to be resolved |
399 | first before attempting to drive on them. |
400 | |
401 | \note Blocking hits (PxQueryHitType::eBLOCK) and non-blocking hits (PxQueryHitType::TOUCH) are supported. If the pre-and post-filter functions of the PxBatchQuery |
402 | instance are set up to return blocking hits it is recommended to set nbHitsPerQuery = 1. If the filter functions returns touch hits then it is recommended to |
403 | set nbHitsPerQuery > 1. The exact value depends on the expected complexity of the geometry that lies under the wheel. For complex geometry, especially with dynamic |
404 | objects, it is recommended to use non-blocking hits. The vehicle update function will analyze all returned hits and choose the most appropriate using the thresholds |
405 | set in PxVehicleSetSweepHitRejectionAngles. |
406 | |
407 | @see PxVehicleDrive4W::setToRestState, PxVehicleDriveNW::setToRestState, PxVehicleDriveTank::setToRestState, PxVehicleNoDrive::setToRestState |
408 | |
409 | @see PxBatchQuery::sweep PxScene::sweep() |
410 | |
411 | @see PxVehicleSetSweepHitRejectionAngles |
412 | */ |
413 | void PxVehicleSuspensionSweeps |
414 | (PxBatchQuery* batchQuery, |
415 | const PxU32 nbVehicles, PxVehicleWheels** vehicles, |
416 | const PxU32 nbSceneQueryResults, PxSweepQueryResult* sceneQueryResults, const PxU16 nbHitsPerQuery, |
417 | const bool* vehiclesToSweep = NULL, |
418 | const PxF32 sweepWidthScale = 1.0f, const PxF32 sweepRadiusScale = 1.0f, const PxF32 sweepInflation = 0.0f); |
419 | |
420 | /** |
421 | \brief A function called from PxContactModifyCallback::onContactModify. The function determines if rigid body contact points |
422 | recorded for the wheel's PxShape are likely to be duplicated and resolved by the wheel's suspension raycast. Contact points that will be |
423 | resolved by the suspension are ignored. Contact points that are accepted (rather than ignored) are modified to account for the effect of the |
424 | suspension geometry and the angular speed of the wheel. |
425 | |
426 | \param[in] vehicle is a reference to the PxVehicleWheels instance that owns the wheel |
427 | |
428 | \param[in] wheelId is the id of the wheel |
429 | |
430 | \param[in] wheelTangentVelocityMultiplier determines the amount of wheel angular velocity that is used to modify the target relative velocity of the contact. |
431 | The target relative velocity is modified by adding a vector equal to the tangent velocity of the rotating wheel at the contact point and scaled by |
432 | wheelTangentVelocityMultiplier. The value of wheelTangentVelocityMultiplier is limited to the range (0,1). Higher values mimic higher values of friction |
433 | and tire load, while lower values mimic lower values of friction and tire load. |
434 | |
435 | \param[in] maxImpulse determines the maximum impulse strength that the contacts can apply when a wheel is in contact with a PxRigidDynamic. This value is ignored for |
436 | contacts with PxRigidStatic instances. |
437 | |
438 | \param[in,out] contactModifyPair describes the set of contacts involving the PxShape of the specified wheel and one other shape. The contacts in the contact set are |
439 | ignored or modified as required. |
440 | |
441 | \note[in] Contact points are accepted or rejected using the threshold angles specified in the function PxVehicleSetSweepHitRejectionAngles. |
442 | |
443 | \note If a contact point is not rejected it is modified to account for the wheel rotation speed. |
444 | |
445 | \note Set maxImpulse to PX_MAX_F32 to allow any impulse value to be applied. |
446 | |
447 | \note Reduce maxImpulse if the wheels are frequently colliding with light objects with mass much less than the vehicle's mass. |
448 | Reducing this value encourages numerical stability. |
449 | |
450 | @see PxContactModifyCallback::onContactModify, PxVehicleSetSweepHitRejectionAngles |
451 | */ |
452 | PxU32 PxVehicleModifyWheelContacts |
453 | (const PxVehicleWheels& vehicle, const PxU32 wheelId, |
454 | const PxF32 wheelTangentVelocityMultiplier, const PxReal maxImpulse, |
455 | PxContactModifyPair& contactModifyPair); |
456 | |
457 | |
458 | /** |
459 | \brief Update an array of vehicles by either applying an acceleration to the rigid body actor associated with |
460 | each vehicle or by an immediate update of the velocity of the actor. |
461 | |
462 | \note The update mode (acceleration or velocity change) can be selected with PxVehicleSetUpdateMode. |
463 | |
464 | \param[in] timestep is the timestep of the update |
465 | |
466 | \param[in] gravity is the value of gravitational acceleration |
467 | |
468 | \param[in] vehicleDrivableSurfaceToTireFrictionPairs describes the mapping between each PxMaterial ptr and an integer representing a |
469 | surface type. It also stores the friction value for each combination of surface and tire type. |
470 | |
471 | \param[in] nbVehicles is the number of vehicles pointers in the vehicles array |
472 | |
473 | \param[in,out] vehicles is an array of length nbVehicles containing all vehicles to be updated by the specified timestep |
474 | |
475 | \param[out] vehicleWheelQueryResults is an array of length nbVehicles storing the wheel query results of each corresponding vehicle and wheel in the |
476 | vehicles array. A NULL pointer is permitted. |
477 | |
478 | \param[out] vehicleConcurrentUpdates is an array of length nbVehicles. It is only necessary to specify vehicleConcurrentUpdates if PxVehicleUpdates is |
479 | called concurrently (also concurrently with PxVehicleUpdateSingleVehicleAndStoreTelemetryData). The element vehicleConcurrentUpdates[i] of the array |
480 | stores data that is computed for vehicle[i] during PxVehicleUpdates but which cannot be safely written when concurrently called. The data computed and |
481 | stored in vehicleConcurrentUpdates must be passed to PxVehiclePostUpdates, where it is applied to all relevant actors in sequence. A NULL pointer is permitted. |
482 | |
483 | \note The vehicleWheelQueryResults buffer must persist until the end of PxVehicleUpdates. |
484 | |
485 | \note The vehicleWheelQueryResults buffer is left unmodified for vehicles with sleeping rigid bodies whose control inputs indicate they should remain inert. |
486 | |
487 | \note If PxVehicleUpdates is called concurrently then vehicleConcurrentUpdates must be specified. Do not specify vehicleConcurrentUpdates if PxVehicleUpdates |
488 | is not called concurrently. |
489 | |
490 | \note The vehicleConcurrentUpdates buffer must persist until the end of PxVehiclePostUpdate. |
491 | |
492 | \note If any vehicle has one or more disabled wheels (PxVehicleWheelsSimData::disableWheel) then the disabled wheels must not be associated |
493 | with a PxShape (PxVehicleWheelsSimData::setWheelShapeMapping); the differential of the vehicle must be configured so that no drive torque |
494 | is delivered to a disabled wheel; and the wheel must have zero rotation speed (PxVehicleWheelsDynData::setWheelRotationSpeed) |
495 | |
496 | \note Concurrent calls to PxVehicleUpdates and PxVehicleUpdateSingleVehicleAndStoreTelemetryData are permitted if the parameter |
497 | vehicleConcurrentUpdates is used. |
498 | |
499 | @see PxVehicleSetUpdateMode, PxVehicleWheelsSimData::disableWheel, PxVehicleWheelsSimData::setWheelShapeMapping, PxVehicleWheelsDynData::setWheelRotationSpeed, |
500 | PxVehiclePostUpdates |
501 | */ |
502 | void PxVehicleUpdates( |
503 | const PxReal timestep, const PxVec3& gravity, |
504 | const PxVehicleDrivableSurfaceToTireFrictionPairs& vehicleDrivableSurfaceToTireFrictionPairs, |
505 | const PxU32 nbVehicles, PxVehicleWheels** vehicles, PxVehicleWheelQueryResult* vehicleWheelQueryResults, PxVehicleConcurrentUpdateData* vehicleConcurrentUpdates = NULL); |
506 | |
507 | |
508 | /** |
509 | \brief Apply actor changes that were computed in concurrent calls to PxVehicleUpdates or PxVehicleUpdateSingleVehicleAndStoreTelemetryData but |
510 | which could not be safely applied due to the concurrency. |
511 | |
512 | \param[in] vehicleConcurrentUpdates is an array of length nbVehicles where vehicleConcurrentUpdates[i] contains data describing actor changes that |
513 | were computed for vehicles[i] during concurrent calls to PxVehicleUpdates or PxVehicleUpdateSingleVehicleAndStoreTelemetryData. |
514 | |
515 | \param[in] nbVehicles is the number of vehicles pointers in the vehicles array |
516 | |
517 | \param[in,out] vehicles is an array of length nbVehicles containing all vehicles that were partially updated in concurrent calls to PxVehicleUpdates or |
518 | PxVehicleUpdateSingleVehicleAndStoreTelemetryData. |
519 | |
520 | @see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData |
521 | */ |
522 | void PxVehiclePostUpdates( |
523 | const PxVehicleConcurrentUpdateData* vehicleConcurrentUpdates, const PxU32 nbVehicles, PxVehicleWheels** vehicles); |
524 | |
525 | |
526 | /** |
527 | \brief Shift the origin of vehicles by the specified vector. |
528 | |
529 | Call this method to adjust the internal data structures of vehicles to reflect the shifted origin location |
530 | (the shift vector will get subtracted from all world space spatial data). |
531 | |
532 | \note It is the user's responsibility to keep track of the summed total origin shift and adjust all input/output to/from PhysXVehicle accordingly. |
533 | |
534 | \note This call will not automatically shift the PhysX scene and its objects. You need to call PxScene::shiftOrigin() seperately to keep the systems in sync. |
535 | |
536 | \param[in] shift is the translation vector to shift the origin by. |
537 | |
538 | \param[in] nbVehicles is the number of vehicles in the vehicles array. |
539 | |
540 | \param[in,out] vehicles is an array of all vehicles that should be updated to map to the new scene origin. |
541 | */ |
542 | void PxVehicleShiftOrigin(const PxVec3& shift, const PxU32 nbVehicles, PxVehicleWheels** vehicles); |
543 | |
544 | #if PX_DEBUG_VEHICLE_ON |
545 | /** |
546 | \brief Update an single vehicle by either applying an acceleration to the rigid body actor associated with |
547 | each vehicle or by an immediate update of the velocity of the actor. Also record telemetry data from the |
548 | vehicle so that it may be visualized or queried. |
549 | |
550 | \note The update mode (acceleration or velocity change) can be selected with PxVehicleSetUpdateMode. |
551 | |
552 | \param[in] timestep is the timestep of the update |
553 | |
554 | \param[in] gravity is the value of gravitational acceleration |
555 | |
556 | \param[in] vehicleDrivableSurfaceToTireFrictionPairs describes the mapping between each PxMaterial ptr and an integer representing a |
557 | surface type. It also stores the friction value for each combination of surface and tire type. |
558 | |
559 | \param[in,out] focusVehicle is the vehicle to be updated and have its telemetry data recorded |
560 | |
561 | \param[out] vehicleWheelQueryResults is an array of length 1 storing the wheel query results of each wheel of the vehicle/ |
562 | A NULL pointer is permitted. |
563 | |
564 | \param[out] telemetryData is the data structure used to record telemetry data during the update for later query or visualization |
565 | |
566 | \param[out] vehicleConcurrentUpdates is an array of length 1. It is only necessary to specify vehicleConcurrentUpdates if |
567 | PxVehicleUpdateSingleVehicleAndStoreTelemetryData is called concurrently (also concurrently with PxVehicleUpdates). The |
568 | PxVehicleConcurrentUpdateData struct stores data that cannot be safely written when concurrently called. The data computed and |
569 | stored in vehicleConcurrentUpdates must be passed to PxVehiclePostUpdates, where it is applied to the vehicle actor. A NULL |
570 | pointer is permitted. |
571 | |
572 | \note The vehicleWheelQueryResults buffer must persist until the end of PxVehicleUpdateSingleVehicleAndStoreTelemetryData |
573 | |
574 | \note The vehicleWheelQueryResults buffer is left unmodified for vehicles with sleeping rigid bodies whose control inputs indicate they should remain inert. |
575 | |
576 | \note Concurrent calls to PxVehicleUpdateSingleVehicleAndStoreTelemetryData and PxVehicleUpdates are permitted if the parameter |
577 | vehicleConcurrentUpdates is used. |
578 | |
579 | @see PxVehiclePostUpdates, PxVehicleSetUpdateMode, PxVehicleTelemetryData |
580 | */ |
581 | void PxVehicleUpdateSingleVehicleAndStoreTelemetryData |
582 | (const PxReal timestep, const PxVec3& gravity, |
583 | const PxVehicleDrivableSurfaceToTireFrictionPairs& vehicleDrivableSurfaceToTireFrictionPairs, |
584 | PxVehicleWheels* focusVehicle, PxVehicleWheelQueryResult* vehicleWheelQueryResults, |
585 | PxVehicleTelemetryData& telemetryData, |
586 | PxVehicleConcurrentUpdateData* vehicleConcurrentUpdates = NULL); |
587 | #endif |
588 | |
589 | #if !PX_DOXYGEN |
590 | } // namespace physx |
591 | #endif |
592 | |
593 | /** @} */ |
594 | #endif //PX_VEHICLE_UPDATE_H |
595 | |