RavEngine
Loading...
Searching...
No Matches
PxVehicleWheelHelpers.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#pragma once
30
35#include "vehicle2/PxVehicleFunctions.h"
36
37#include "vehicle2/suspension/PxVehicleSuspensionParams.h"
38#include "vehicle2/suspension/PxVehicleSuspensionStates.h"
39
40#include "PxVehicleWheelParams.h"
41#include "PxVehicleWheelStates.h"
42
43#if !PX_DOXYGEN
44namespace physx
45{
46namespace vehicle2
47{
48#endif
49
61PX_FORCE_INLINE PxQuat PxVehicleComputeWheelLocalOrientation
62(const PxVehicleFrame& frame,
63 const PxVehicleSuspensionParams& suspensionParams,
64 const PxReal camberAngle, const PxReal toeAngle, const PxReal steerAngle,
65 const PxReal rotationAngle)
66{
67 const PxQuat wheelLocalOrientation =
68 (suspensionParams.suspensionAttachment.q * PxVehicleComputeRotation(frame, camberAngle, 0.0f, steerAngle + toeAngle))*
69 (suspensionParams.wheelAttachment.q * PxVehicleComputeRotation(frame, 0.0f, rotationAngle, 0.0f));
70 return wheelLocalOrientation;
71}
72
85PX_FORCE_INLINE PxQuat PxVehicleComputeWheelOrientation
86(const PxVehicleFrame& frame,
87 const PxVehicleSuspensionParams& suspensionParams,
88 const PxReal camberAngle, const PxReal toeAngle, const PxReal steerAngle,
89 const PxQuat& rigidBodyOrientation, const PxReal rotationAngle)
90{
91 const PxQuat wheelOrientation = rigidBodyOrientation * PxVehicleComputeWheelLocalOrientation(frame, suspensionParams,
92 camberAngle, toeAngle, steerAngle, rotationAngle);
93 return wheelOrientation;
94}
95
107PX_FORCE_INLINE PxTransform PxVehicleComputeWheelLocalPose
108(const PxVehicleFrame& frame,
109 const PxVehicleSuspensionParams& suspensionParams,
110 const PxVehicleSuspensionState& suspensionState,
111 const PxReal camberAngle, const PxReal toeAngle, const PxReal steerAngle,
112 const PxReal rotationAngle)
113{
114 //Full equation:
115 //PxTransform(suspAttachment.p + suspParams.suspensionTravelDir*suspDist, suspAttachment.q) *
116 //PxTransform(PxVec3(0), PxQuat(camber, 0, steer+toe)) *
117 //wheelAttachment *
118 //PxTransform(PxVec3(0), PxQuat(0, rotation, 0))
119 //Reduces to:
120 //PxTransform(suspAttachment.p + suspParams.suspensionTravelDir*suspDist, suspAttachment.q * PxQuat(camber, 0, steer+toe)) *
121 //PxTranfsorm(wheelAttachment.p, wheelAttachment.q * PxQuat(0, rotation, 0))
122 const PxF32 suspDist = (suspensionState.jounce != PX_VEHICLE_UNSPECIFIED_JOUNCE) ? (suspensionParams.suspensionTravelDist - suspensionState.jounce) : 0.0f;
123 const PxTransform wheelLocalPose =
124 PxTransform(
125 suspensionParams.suspensionAttachment.p + suspensionParams.suspensionTravelDir*suspDist,
126 suspensionParams.suspensionAttachment.q*PxVehicleComputeRotation(frame, camberAngle, 0.0f, steerAngle + toeAngle))*
127 PxTransform(
128 suspensionParams.wheelAttachment.p,
129 suspensionParams.wheelAttachment.q*PxVehicleComputeRotation(frame, 0.0f, rotationAngle, 0.0f));
130 return wheelLocalPose;
131}
132
133
144PX_FORCE_INLINE PxTransform PxVehicleComputeWheelLocalPose
145(const PxVehicleFrame& frame,
146 const PxVehicleSuspensionParams& suspensionParams,
147 const PxVehicleSuspensionState& suspensionState, const PxVehicleSuspensionComplianceState& suspensionComplianceState,
148 const PxReal steerAngle,
149 const PxVehicleWheelRigidBody1dState& wheelState)
150{
151 return PxVehicleComputeWheelLocalPose(frame, suspensionParams, suspensionState,
152 suspensionComplianceState.camber, suspensionComplianceState.toe, steerAngle,
153 wheelState.rotationAngle);
154}
155
168PX_FORCE_INLINE PxTransform PxVehicleComputeWheelPose
169(const PxVehicleFrame& frame,
170 const PxVehicleSuspensionParams& suspensionParams,
171 const PxVehicleSuspensionState& suspensionState,
172 const PxReal camberAngle, const PxReal toeAngle, const PxReal steerAngle,
173 const PxTransform& rigidBodyPose, const PxReal rotationAngle)
174{
175 const PxTransform wheelPose = rigidBodyPose * PxVehicleComputeWheelLocalPose(frame, suspensionParams, suspensionState,
176 camberAngle, toeAngle, steerAngle, rotationAngle);
177 return wheelPose;
178}
179
192PX_FORCE_INLINE PxTransform PxVehicleComputeWheelPose
193(const PxVehicleFrame& frame,
194 const PxVehicleSuspensionParams& suspensionParams,
195 const PxVehicleSuspensionState& suspensionState, const PxVehicleSuspensionComplianceState& suspensionComplianceState, const PxReal steerAngle,
196 const PxTransform& rigidBodyPose, const PxVehicleWheelRigidBody1dState& wheelState)
197{
198 return PxVehicleComputeWheelPose(frame, suspensionParams, suspensionState,
199 suspensionComplianceState.camber, suspensionComplianceState.toe, steerAngle,
200 rigidBodyPose, wheelState.rotationAngle);
201}
202
211PX_FORCE_INLINE bool PxVehicleIsWheelOnGround(const PxVehicleSuspensionState& suspState)
212{
213 return (suspState.separation <= 0.0f);
214}
215
216#if !PX_DOXYGEN
217} // namespace vehicle2
218} // namespace physx
219#endif
220
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39