RavEngine
Loading...
Searching...
No Matches
PxVehicleSuspLimitConstraintShader.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_VEHICLE_SUSP_LIMIT_CONSTRAINT_SHADER_H
30#define PX_VEHICLE_SUSP_LIMIT_CONSTRAINT_SHADER_H
35#include "foundation/PxTransform.h"
36#include "extensions/PxConstraintExt.h"
37#include "PxConstraintDesc.h"
38#include "PxConstraint.h"
39#include "vehicle/PxVehicleWheels.h"
40
41#if !PX_DOXYGEN
42namespace physx
43{
44#endif
45
47{
48//= ATTENTION! =====================================================================================
49// Changing the data layout of this class breaks the binary serialization format. See comments for
50// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
51// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
52// accordingly.
53//==================================================================================================
54public:
55
56 friend class PxVehicleWheels;
57
58 PxVehicleConstraintShader(PxVehicleWheels* vehicle, PxConstraint* constraint = NULL)
59 : mConstraint(constraint),
60 mVehicle(vehicle)
61 {
62 }
65 {
66 }
67
68 static void getBinaryMetaData(PxOutputStream& stream);
69
70 void release()
71 {
72 if(mConstraint)
73 {
74 mConstraint->release();
75 }
76 }
77
78 virtual void onComShift(PxU32 actor) { PX_UNUSED(actor); }
79
80 virtual void onOriginShift(const PxVec3& shift) { PX_UNUSED(shift); }
81
82 virtual void* prepareData()
83 {
84 return &mData;
85 }
86
87 virtual bool updatePvdProperties(pvdsdk::PvdDataStream& pvdConnection,
88 const PxConstraint* c,
89 PxPvdUpdateType::Enum updateType) const { PX_UNUSED(c); PX_UNUSED(updateType); PX_UNUSED(&pvdConnection); return true;}
90
91 virtual void updateOmniPvdProperties() const { }
92
93 virtual void onConstraintRelease()
94 {
95 mVehicle->onConstraintRelease();
96 }
97
98 virtual void* getExternalReference(PxU32& typeID) { typeID = PxConstraintExtIDs::eVEHICLE_SUSP_LIMIT_DEPRECATED; return this; }
99 virtual PxBase* getSerializable() { return NULL; }
100
101 //TAG:solverprepshader
102 static PxU32 vehicleSuspLimitConstraintSolverPrep(
103 Px1DConstraint* constraints,
104 PxVec3p& body0WorldOffset,
105 PxU32 maxConstraints,
107 const void* constantBlock,
108 const PxTransform& bodyAToWorld,
109 const PxTransform& bodyBToWorld,
110 bool,
111 PxVec3p& cA2w, PxVec3p& cB2w
112 )
113 {
114 PX_UNUSED(maxConstraints);
115 PX_UNUSED(body0WorldOffset);
116 PX_UNUSED(bodyBToWorld);
117 PX_ASSERT(bodyAToWorld.isValid()); PX_ASSERT(bodyBToWorld.isValid());
118
119 const VehicleConstraintData* data = static_cast<const VehicleConstraintData*>(constantBlock);
120 PxU32 numActive=0;
121 const PxQuat bodyRotation = bodyAToWorld.q * data->mCMassRotation.getConjugate();
122
123 //KS - the TGS solver will use raXn to try to add to the angular part of the linear constraints.
124 //We overcome this by setting the ra and rb offsets to be 0.
125 cA2w = bodyAToWorld.p;
126 cB2w = bodyBToWorld.p;
127
128 //Susp limit constraints.
129 for(PxU32 i=0;i<4;i++)
130 {
131 if(data->mSuspLimitData.mActiveFlags[i])
132 {
133 Px1DConstraint& p=constraints[numActive];
134 p.linear0 = bodyRotation.rotate(data->mSuspLimitData.mDirs[i]);
135 p.angular0 = bodyRotation.rotate(data->mSuspLimitData.mCMOffsets[i].cross(data->mSuspLimitData.mDirs[i]));
136 p.geometricError=data->mSuspLimitData.mErrors[i];
137 p.linear1=PxVec3(0);
138 p.angular1=PxVec3(0);
139 p.minImpulse=-FLT_MAX;
140 p.maxImpulse=0;
141 p.velocityTarget=0;
143 numActive++;
144 }
145 }
146
147 //Sticky tire friction constraints.
148 for(PxU32 i=0;i<4;i++)
149 {
150 if(data->mStickyTireForwardData.mActiveFlags[i])
151 {
152 Px1DConstraint& p=constraints[numActive];
153 p.linear0=data->mStickyTireForwardData.mDirs[i];
154 p.angular0=data->mStickyTireForwardData.mCMOffsets[i].cross(data->mStickyTireForwardData.mDirs[i]);
155 p.geometricError=0.0f;
156 p.linear1=PxVec3(0);
157 p.angular1=PxVec3(0);
158 p.minImpulse=-FLT_MAX;
159 p.maxImpulse=FLT_MAX;
160 p.velocityTarget=data->mStickyTireForwardData.mTargetSpeeds[i];
161 p.mods.spring.damping = 1000.0f;
164 numActive++;
165 }
166 }
167
168 //Sticky tire friction constraints.
169 for(PxU32 i=0;i<4;i++)
170 {
171 if(data->mStickyTireSideData.mActiveFlags[i])
172 {
173 Px1DConstraint& p=constraints[numActive];
174 p.linear0=data->mStickyTireSideData.mDirs[i];
175 p.angular0=data->mStickyTireSideData.mCMOffsets[i].cross(data->mStickyTireSideData.mDirs[i]);
176 p.geometricError=0.0f;
177 p.linear1=PxVec3(0);
178 p.angular1=PxVec3(0);
179 p.minImpulse=-FLT_MAX;
180 p.maxImpulse=FLT_MAX;
181 p.velocityTarget=data->mStickyTireSideData.mTargetSpeeds[i];
182 p.mods.spring.damping = 1000.0f;
185 numActive++;
186 }
187 }
188
189
190 return numActive;
191 }
192
193 static void visualiseConstraint(PxConstraintVisualizer &viz,
194 const void* constantBlock,
195 const PxTransform& body0Transform,
196 const PxTransform& body1Transform,
197 PxU32 flags){ PX_UNUSED(&viz); PX_UNUSED(constantBlock); PX_UNUSED(body0Transform);
198 PX_UNUSED(body1Transform); PX_UNUSED(flags);
199 PX_ASSERT(body0Transform.isValid()); PX_ASSERT(body1Transform.isValid()); }
200
201public:
202
204 {
205 PxVec3 mCMOffsets[4];
206 PxVec3 mDirs[4];
207 PxReal mErrors[4];
208 bool mActiveFlags[4];
209 };
211 {
212 PxVec3 mCMOffsets[4];
213 PxVec3 mDirs[4];
214 PxReal mTargetSpeeds[4];
215 bool mActiveFlags[4];
216 };
217
219 {
220 SuspLimitConstraintData mSuspLimitData;
221 StickyTireConstraintData mStickyTireForwardData;
222 StickyTireConstraintData mStickyTireSideData;
223 PxQuat mCMassRotation;
224 };
226
227 PxConstraint* mConstraint;
228
229 PX_INLINE void setPxConstraint(PxConstraint* pxConstraint)
230 {
231 mConstraint = pxConstraint;
232 }
233
234 PX_INLINE PxConstraint* getPxConstraint()
235 {
236 return mConstraint;
237 }
238
239 PxConstraintConnector* getConnector()
240 {
241 return this;
242 }
243
244 virtual PxConstraintSolverPrep getPrep() const { return vehicleSuspLimitConstraintSolverPrep; }
245 virtual const void* getConstantBlock() const { return &mData; }
246
247private:
248
249 PxVehicleWheels* mVehicle;
250
251#if !PX_P64_FAMILY
252 PxU32 mPad[2];
253#else
254 PxU32 mPad[1];
255#endif
256};
257PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleConstraintShader)& 0x0f));
258
259
265 (const void* shaderData,
266 const PxF32 tireFriction,
267 const PxF32 longSlip, const PxF32 latSlip, const PxF32 camber,
268 const PxF32 wheelOmega, const PxF32 wheelRadius, const PxF32 recipWheelRadius,
269 const PxF32 restTireLoad, const PxF32 normalisedTireLoad, const PxF32 tireLoad,
270 const PxF32 gravity, const PxF32 recipGravity,
271 PxF32& wheelTorque, PxF32& tireLongForceMag, PxF32& tireLatForceMag, PxF32& tireAlignMoment);
272
273
278{
279public:
280
283 {
284 }
285
291 const void** mShaderData;
292
299
300#if !PX_P64_FAMILY
301 PxU32 mPad[2];
302#endif
303};
304
306
307
308#if !PX_DOXYGEN
309} // namespace physx
310#endif
311
312
314#endif
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
This class connects a custom constraint to the SDK.
Definition PxConstraintDesc.h:354
A plugin class for implementing constraints.
Definition PxConstraint.h:100
virtual void release()=0
Releases a PxConstraint instance.
Output stream class for I/O.
Definition PxIO.h:114
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition PxQuat.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 rotate(const PxVec3 &v) const
Definition PxQuat.h:287
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
PX_CUDA_CALLABLE bool isValid() const
returns true if finite and q is a unit quaternion
Definition PxTransform.h:148
A padded version of PxVec3, to safely load its data using SIMD.
Definition PxVec3.h:392
3 Element vector class.
Definition PxVec3.h:50
Definition PxVehicleSuspLimitConstraintShader.h:47
virtual void * getExternalReference(PxU32 &typeID)
Fetches external data for a constraint.
Definition PxVehicleSuspLimitConstraintShader.h:98
virtual bool updatePvdProperties(pvdsdk::PvdDataStream &pvdConnection, const PxConstraint *c, PxPvdUpdateType::Enum updateType) const
this function is called by the SDK to update PVD's view of it
Definition PxVehicleSuspLimitConstraintShader.h:87
virtual PxBase * getSerializable()
Obtain a reference to a PxBase interface if the constraint has one.
Definition PxVehicleSuspLimitConstraintShader.h:99
virtual PxConstraintSolverPrep getPrep() const
Obtain the shader function pointer used to prep rows for this constraint.
Definition PxVehicleSuspLimitConstraintShader.h:244
virtual const void * getConstantBlock() const
Obtain the pointer to the constraint's constant data.
Definition PxVehicleSuspLimitConstraintShader.h:245
virtual void updateOmniPvdProperties() const
this function is called by the SDK to update OmniPVD's view of it
Definition PxVehicleSuspLimitConstraintShader.h:91
virtual void onOriginShift(const PxVec3 &shift)
Origin shift callback.
Definition PxVehicleSuspLimitConstraintShader.h:80
virtual void onConstraintRelease()
Constraint release callback.
Definition PxVehicleSuspLimitConstraintShader.h:93
virtual void onComShift(PxU32 actor)
Center-of-mass shift callback.
Definition PxVehicleSuspLimitConstraintShader.h:78
virtual void * prepareData()
Pre-simulation data preparation when the constraint is marked dirty, this function is called at the s...
Definition PxVehicleSuspLimitConstraintShader.h:82
Structure containing shader data for each tire of a vehicle and a shader function that computes indiv...
Definition PxVehicleSuspLimitConstraintShader.h:278
const void ** mShaderData
Array of shader data - one data entry per tire. Default values are pointers to PxVehicleTireData (sto...
Definition PxVehicleSuspLimitConstraintShader.h:291
PxVehicleComputeTireForce mShader
Shader function. Default value is PxVehicleComputeTireForceDefault and is set in PxVehicleDriveTank::...
Definition PxVehicleSuspLimitConstraintShader.h:298
Data structure with instanced dynamics data and configuration data of a vehicle with just wheels.
Definition PxVehicleWheels.h:827
Definition PxPvdDataStream.h:241
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU32(* PxConstraintSolverPrep)(Px1DConstraint *constraints, PxVec3p &bodyAWorldOffset, PxU32 maxConstraints, PxConstraintInvMassScale &invMassScale, const void *constantBlock, const PxTransform &bodyAToWorld, const PxTransform &bodyBToWorld, bool useExtendedLimits, PxVec3p &cAtW, PxVec3p &cBtW)
Solver constraint generation shader.
Definition PxConstraintDesc.h:223
void PxVehicleComputeTireForceDefault(const void *shaderData, const PxF32 tireFriction, const PxF32 longSlip, const PxF32 latSlip, const PxF32 camber, const PxF32 wheelOmega, const PxF32 wheelRadius, const PxF32 recipWheelRadius, const PxF32 restTireLoad, const PxF32 normalisedTireLoad, const PxF32 tireLoad, const PxF32 gravity, const PxF32 recipGravity, PxF32 &wheelTorque, PxF32 &tireLongForceMag, PxF32 &tireLatForceMag, PxF32 &tireAlignMoment)
Default implementation of PxVehicleComputeTireForce.
Definition PxVehicleUpdate.cpp:1984
PX_DEPRECATED typedef void(* PxVehicleComputeTireForce)(const void *shaderData, const PxF32 tireFriction, const PxF32 longSlip, const PxF32 latSlip, const PxF32 camber, const PxF32 wheelOmega, const PxF32 wheelRadius, const PxF32 recipWheelRadius, const PxF32 restTireLoad, const PxF32 normalisedTireLoad, const PxF32 tireLoad, const PxF32 gravity, const PxF32 recipGravity, PxF32 &wheelTorque, PxF32 &tireLongForceMag, PxF32 &tireLatForceMag, PxF32 &tireAlignMoment)
Prototype of shader function that is used to compute wheel torque and tire forces.
Definition PxVehicleShaders.h:61
@ eANGULAR_CONSTRAINT
whether this is an angular or linear constraint
Definition PxConstraintDesc.h:71
@ eACCELERATION_SPRING
whether the constraint is a force or acceleration spring. Only valid if eSPRING is set.
Definition PxConstraintDesc.h:66
@ eSPRING
whether the constraint is a spring. Mutually exclusive with eRESTITUTION. If set, eKEEPBIAS is ignore...
Definition PxConstraintDesc.h:65
A one-dimensional constraint.
Definition PxConstraintDesc.h:134
Struct for specifying mass scaling for a pair of rigids.
Definition PxConstraintDesc.h:184
Enum
Definition PxConstraintDesc.h:337
Definition PxVehicleSuspLimitConstraintShader.h:211
Definition PxVehicleSuspLimitConstraintShader.h:204
Definition PxVehicleSuspLimitConstraintShader.h:219