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_UTILSSETUP_H |
31 | #define PX_VEHICLE_UTILSSETUP_H |
32 | /** \addtogroup vehicle |
33 | @{ |
34 | */ |
35 | #include "foundation/PxSimpleTypes.h" |
36 | #include "vehicle/PxVehicleSDK.h" |
37 | |
38 | #if !PX_DOXYGEN |
39 | namespace physx |
40 | { |
41 | #endif |
42 | |
43 | class PxVehicleWheelsSimData; |
44 | class PxVehicleWheelsDynData; |
45 | class PxVehicleDriveSimData4W; |
46 | class PxVehicleWheels; |
47 | |
48 | |
49 | /** |
50 | \brief Reconfigure a PxVehicle4W instance as a three-wheeled car with tadpole config (2 front wheels, 1 rear wheel) |
51 | |
52 | \note The rear-left wheel is removed and the rear-right wheel is positioned at the centre of the rear axle. |
53 | The suspension of the rear-right wheel is modified to support the entire mass of the front car while preserving its natural frequency and damping ratio. |
54 | |
55 | \param[in,out] wheelsSimData is the data describing the wheels/suspensions/tires of the vehicle. |
56 | \param[in,out] wheelsDynData is the data describing the dynamic state of the wheels of the vehicle. |
57 | \param[in,out] driveSimData is the data describing the drive model of the vehicle. |
58 | */ |
59 | void PxVehicle4WEnable3WTadpoleMode(PxVehicleWheelsSimData& wheelsSimData, PxVehicleWheelsDynData& wheelsDynData, PxVehicleDriveSimData4W& driveSimData); |
60 | |
61 | /** |
62 | \brief Reconfigure a PxVehicle4W instance as a three-wheeled car with delta config (1 front wheel, 2 rear wheels) |
63 | |
64 | \note The front-left wheel is removed and the front-right wheel is positioned at the centre of the front axle. |
65 | The suspension of the front-right wheel is modified to support the entire mass of the front car while preserving its natural frequency and damping ratio. |
66 | |
67 | \param[in,out] wheelsSimData is the data describing the wheels/suspensions/tires of the vehicle. |
68 | \param[in,out] wheelsDynData is the data describing the dynamic state of the wheels of the vehicle. |
69 | \param[in,out] driveSimData is the data describing the drive model of the vehicle. |
70 | */ |
71 | void PxVehicle4WEnable3WDeltaMode(PxVehicleWheelsSimData& wheelsSimData, PxVehicleWheelsDynData& wheelsDynData, PxVehicleDriveSimData4W& driveSimData); |
72 | |
73 | /** |
74 | \brief Compute the sprung masses of the suspension springs given (i) the number of sprung masses, |
75 | (ii) coordinates of the sprung masses, (iii) the center of mass offset of the rigid body, (iv) the |
76 | total mass of the rigid body, and (v) the direction of gravity (0 for x-axis, 1 for y-axis, 2 for z-axis). |
77 | |
78 | \param[in] nbSprungMasses is the number of sprung masses of the vehicle. This value corresponds to the number of wheels on the vehicle. |
79 | \param[in] sprungMassCoordinates are the coordinates of the sprung masses relative to the actor. The array sprungMassCoordinates must be of |
80 | length nbSprungMasses or greater. |
81 | \param[in] centreOfMass is the coordinate of the center of mass of the rigid body relative to the actor. This value corresponds to |
82 | the value set by PxRigidBody::setCMassLocalPose. |
83 | \param[in] totalMass is the total mass of all the sprung masses. This value corresponds to the value set by PxRigidBody::setMass. |
84 | \param[in] gravityDirection is an integer describing the direction of gravitational acceleration. A value of 0 corresponds to (-1,0,0), |
85 | a value of 1 corresponds to (0,-1,0) and a value of 2 corresponds to (0,0,-1). |
86 | \param[out] sprungMasses are the masses to set in the associated suspension data with PxVehicleSuspensionData::mSprungMass. The sprungMasses array must be of length |
87 | nbSprungMasses or greater. Each element in the sprungMasses array corresponds to the suspension located at the same array element in sprungMassCoordinates. |
88 | The center of mass of the masses in sprungMasses with the coordinates in sprungMassCoordinates satisfy the specified centerOfMass. |
89 | */ |
90 | void PxVehicleComputeSprungMasses(const PxU32 nbSprungMasses, const PxVec3* sprungMassCoordinates, const PxVec3& centreOfMass, const PxReal totalMass, const PxU32 gravityDirection, PxReal* sprungMasses); |
91 | |
92 | |
93 | /** |
94 | \brief Reconfigure the vehicle to reflect a new center of mass local pose that has been applied to the actor. The function requires |
95 | (i) the center of mass local pose that was last used to configure the vehicle and the vehicle's actor, (ii) the new center of mass local pose that |
96 | has been applied to the vehicle's actor and will now be applied to the vehicle, and (iii) the direction of gravity (0 for x-axis, 1 for y-axis, 2 for z-axis) |
97 | |
98 | \param[in] oldCMassLocalPose is the center of mass local pose that was last used to configure the vehicle. |
99 | \param[in] newCMassLocalPose is the center of mass local pose that will be used to configure the vehicle so that it matches the vehicle's actor. |
100 | \param[in] gravityDirection is an integer describing the direction of gravitational acceleration. A value of 0 corresponds to (0,0,-1), |
101 | a value of 1 corresponds to (0,-1,0) and a value of 2 corresponds to (0,0,-1). |
102 | \param[in,out] vehicle is the vehicle to be updated with a new center of mass local pose. |
103 | |
104 | \note This function does not update the center of mass of the vehicle actor. That needs to updated separately with PxRigidBody::setCMassLocalPose |
105 | |
106 | \note The suspension sprung masses are updated so that the natural frequency and damping ratio of the springs are preserved. This involves altering the |
107 | stiffness and damping rate of the suspension springs. |
108 | */ |
109 | void PxVehicleUpdateCMassLocalPose(const PxTransform& oldCMassLocalPose, const PxTransform& newCMassLocalPose, const PxU32 gravityDirection, PxVehicleWheels* vehicle); |
110 | |
111 | /** |
112 | \brief Used by PxVehicleCopyDynamicsData |
113 | @see PxVehicleCopyDynamicsData |
114 | */ |
115 | class PxVehicleCopyDynamicsMap |
116 | { |
117 | public: |
118 | |
119 | PxVehicleCopyDynamicsMap() |
120 | { |
121 | for(PxU32 i = 0; i < PX_MAX_NB_WHEELS; i++) |
122 | { |
123 | sourceWheelIds[i] = PX_MAX_U8; |
124 | targetWheelIds[i] = PX_MAX_U8; |
125 | } |
126 | } |
127 | |
128 | PxU8 sourceWheelIds[PX_MAX_NB_WHEELS]; |
129 | PxU8 targetWheelIds[PX_MAX_NB_WHEELS]; |
130 | }; |
131 | |
132 | /** |
133 | \brief Copy dynamics data from src to trg, including wheel rotation speed, wheel rotation angle, engine rotation speed etc. |
134 | |
135 | \param[in] wheelMap - describes the mapping between the wheels in src and the wheels in trg. |
136 | |
137 | \param[in] src - according to the wheel mapping stored in wheelMap, the dynamics data in src wheels are copied to the corresponding wheels in trg. |
138 | |
139 | \param[out] trg - according to wheel mapping stored in wheelMap, the wheels in trg are given the dynamics data of the corresponding wheels in src. |
140 | |
141 | \note wheelMap must specify a unique mapping between the wheels in src and the wheels in trg. |
142 | |
143 | \note In the event that src has fewer wheels than trg, wheelMap must specify a unique mapping between each src wheel to a trg wheel. |
144 | |
145 | \note In the event that src has more wheels than trg, wheelMap must specify a unique mapping to each trg wheel from a src wheel. |
146 | |
147 | \note In the event that src has fewer wheels than trg, the trg wheels that are not mapped to a src wheel are given the average wheel rotation |
148 | speed of all enabled src wheels. |
149 | |
150 | \note src and trg must be the same vehicle type. |
151 | */ |
152 | void PxVehicleCopyDynamicsData(const PxVehicleCopyDynamicsMap& wheelMap, const PxVehicleWheels& src, PxVehicleWheels* trg); |
153 | |
154 | |
155 | #if !PX_DOXYGEN |
156 | } // namespace physx |
157 | #endif |
158 | |
159 | /** @} */ |
160 | #endif //PX_VEHICLE_UTILSSETUP_H |
161 | |