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_NO_DRIVE_H
31#define PX_VEHICLE_NO_DRIVE_H
32/** \addtogroup vehicle
33 @{
34*/
35
36#include "vehicle/PxVehicleWheels.h"
37#include "vehicle/PxVehicleComponents.h"
38
39
40#if !PX_DOXYGEN
41namespace physx
42{
43#endif
44
45struct PxFilterData;
46class PxGeometry;
47class PxPhysics;
48class PxVehicleDrivableSurfaceToTireFrictionPairs;
49class PxShape;
50class PxMaterial;
51class PxRigidDynamic;
52
53/**
54\brief Data structure with instanced dynamics data and configuration data of a vehicle with no drive model.
55*/
56class PxVehicleNoDrive : public PxVehicleWheels
57{
58//= ATTENTION! =====================================================================================
59// Changing the data layout of this class breaks the binary serialization format. See comments for
60// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
61// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
62// accordingly.
63//==================================================================================================
64public:
65
66 friend class PxVehicleUpdate;
67
68 /**
69 \brief Allocate a PxVehicleNoDrive instance for a vehicle without drive model and with nbWheels
70
71 \param[in] nbWheels is the number of wheels on the vehicle.
72
73 \return The instantiated vehicle.
74
75 @see free, setup
76 */
77 static PxVehicleNoDrive* allocate(const PxU32 nbWheels);
78
79 /**
80 \brief Deallocate a PxVehicleNoDrive instance.
81 @see allocate
82 */
83 void free();
84
85 /**
86 \brief Set up a vehicle using simulation data for the wheels.
87 \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
88 \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
89 \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
90 \note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheels::setWheelShapeMapping.
91 @see allocate, free, setToRestState, PxVehicleWheels::setWheelShapeMapping
92 */
93 void setup
94 (PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData);
95
96 /**
97 \brief Allocate and set up a vehicle using simulation data for the wheels.
98 \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
99 \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
100 \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
101 \note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheels::setWheelShapeMapping.
102 \return The instantiated vehicle.
103 @see allocate, free, setToRestState, PxVehicleWheels::setWheelShapeMapping
104 */
105 static PxVehicleNoDrive* create
106 (PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData);
107
108 /**
109 \brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body
110 to the state they were in immediately after setup or create.
111 \note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line
112 raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates.
113 @see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates
114 */
115 void setToRestState();
116
117 /**
118 \brief Set the brake torque to be applied to a specific wheel
119
120 \note The applied brakeTorque persists until the next call to setBrakeTorque
121
122 \note The brake torque is specified in Newton metres.
123
124 \param[in] id is the wheel being given the brake torque
125 \param[in] brakeTorque is the value of the brake torque
126 */
127 void setBrakeTorque(const PxU32 id, const PxReal brakeTorque);
128
129 /**
130 \brief Set the drive torque to be applied to a specific wheel
131
132 \note The applied driveTorque persists until the next call to setDriveTorque
133
134 \note The brake torque is specified in Newton metres.
135
136 \param[in] id is the wheel being given the brake torque
137 \param[in] driveTorque is the value of the brake torque
138 */
139 void setDriveTorque(const PxU32 id, const PxReal driveTorque);
140
141 /**
142 \brief Set the steer angle to be applied to a specific wheel
143
144 \note The applied steerAngle persists until the next call to setSteerAngle
145
146 \note The steer angle is specified in radians.
147
148 \param[in] id is the wheel being given the steer angle
149 \param[in] steerAngle is the value of the steer angle in radians.
150 */
151 void setSteerAngle(const PxU32 id, const PxReal steerAngle);
152
153 /**
154 \brief Get the brake torque that has been applied to a specific wheel
155 \param[in] id is the wheel being queried for its brake torque
156 \return The brake torque applied to the queried wheel.
157 */
158 PxReal getBrakeTorque(const PxU32 id) const;
159
160 /**
161 \brief Get the drive torque that has been applied to a specific wheel
162 \param[in] id is the wheel being queried for its drive torque
163 \return The drive torque applied to the queried wheel.
164 */
165 PxReal getDriveTorque(const PxU32 id) const;
166
167 /**
168 \brief Get the steer angle that has been applied to a specific wheel
169 \param[in] id is the wheel being queried for its steer angle
170 \return The steer angle (in radians) applied to the queried wheel.
171 */
172 PxReal getSteerAngle(const PxU32 id) const;
173
174private:
175
176 PxReal* mSteerAngles;
177 PxReal* mDriveTorques;
178 PxReal* mBrakeTorques;
179
180#if PX_P64_FAMILY
181 PxU32 mPad[2];
182#else
183 PxU32 mPad[1];
184#endif
185
186 /**
187 \brief Test if the instanced dynamics and configuration data has legal values.
188 */
189 bool isValid() const;
190
191
192//serialization
193public:
194 PxVehicleNoDrive(PxBaseFlags baseFlags) : PxVehicleWheels(baseFlags) {}
195 virtual void exportExtraData(PxSerializationContext&);
196 void importExtraData(PxDeserializationContext&);
197 static PxVehicleNoDrive* createObject(PxU8*& address, PxDeserializationContext& context);
198 static void getBinaryMetaData(PxOutputStream& stream);
199 virtual const char* getConcreteTypeName() const { return "PxVehicleNoDrive"; }
200 virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxVehicleNoDrive", s2: name) || PxBase::isKindOf(superClass: name); }
201 PxU32 getNbSteerAngle() const { return mWheelsSimData.getNbWheels(); }
202 PxU32 getNbDriveTorque() const { return mWheelsSimData.getNbWheels(); }
203 PxU32 getNbBrakeTorque() const { return mWheelsSimData.getNbWheels(); }
204protected:
205 PxVehicleNoDrive();
206 ~PxVehicleNoDrive() {}
207//~serialization
208};
209PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleNoDrive) & 15));
210
211#if !PX_DOXYGEN
212} // namespace physx
213#endif
214
215/** @} */
216#endif //PX_VEHICLE_NO_DRIVE_H
217

source code of qtquick3dphysics/src/3rdparty/PhysX/include/vehicle/PxVehicleNoDrive.h