RavEngine
Loading...
Searching...
No Matches
PxVehiclePhysXActorComponents.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
34#include "vehicle2/PxVehicleParams.h"
35#include "vehicle2/PxVehicleComponent.h"
36
37#include "vehicle2/wheel/PxVehicleWheelStates.h"
38
39#include "PxVehiclePhysXActorFunctions.h"
40#include "PxVehiclePhysXActorStates.h"
41
42#include "common/PxProfileZone.h"
43
44#if !PX_DOXYGEN
45namespace physx
46{
47namespace vehicle2
48{
49#endif
50
62{
63public:
64
67
94 const PxVehicleAxleDescription*& axleDescription,
95 const PxVehicleCommandState*& commands,
96 const PxVehicleEngineDriveTransmissionCommandState*& transmissionCommands,
97 const PxVehicleGearboxParams*& gearParams,
98 const PxVehicleGearboxState*& gearState,
99 const PxVehicleEngineParams*& engineParams,
100 PxVehiclePhysXActor*& physxActor,
101 PxVehiclePhysXSteerState*& physxSteerState,
102 PxVehiclePhysXConstraints*& physxConstraints,
103 PxVehicleRigidBodyState*& rigidBodyState,
105 PxVehicleEngineState*& engineState) = 0;
106
107 virtual bool update(const PxReal dt, const PxVehicleSimulationContext& context)
108 {
109 PX_UNUSED(dt);
110 PX_UNUSED(context);
111
112 PX_PROFILE_ZONE("PxVehiclePhysXActorBeginComponent::update", 0);
113
114 const PxVehicleAxleDescription* axleDescription;
115 const PxVehicleCommandState* commands;
116 const PxVehicleEngineDriveTransmissionCommandState* transmissionCommands;
117 const PxVehicleGearboxParams* gearParams;
118 const PxVehicleGearboxState* gearState;
119 const PxVehicleEngineParams* engineParams;
120 PxVehiclePhysXActor* physxActor;
121 PxVehiclePhysXSteerState* physxSteerState;
122 PxVehiclePhysXConstraints* physxConstraints;
123 PxVehicleRigidBodyState* rigidBodyState;
125 PxVehicleEngineState* engineState;
126
127 getDataForPhysXActorBeginComponent(axleDescription, commands, transmissionCommands,
128 gearParams, gearState, engineParams,
129 physxActor, physxSteerState, physxConstraints,
130 rigidBodyState, wheelRigidBody1dStates, engineState);
131
132 if (physxActor->rigidBody->getScene()) // Considering case where actor is not in a scene and constraints get solved via immediate mode
133 {
134 PxVehiclePhysxActorWakeup(*commands, transmissionCommands, gearParams, gearState,
135 *physxActor->rigidBody, *physxSteerState);
136
137 if (PxVehiclePhysxActorSleepCheck(*axleDescription, *physxActor->rigidBody, engineParams,
138 *rigidBodyState, *physxConstraints, wheelRigidBody1dStates, engineState))
139 {
140 return false;
141 }
142 }
143
144 PxVehicleReadRigidBodyStateFromPhysXActor(*physxActor->rigidBody, *rigidBodyState);
145
146 return true;
147 }
148};
149
158{
159public:
160
163
178 const PxVehicleAxleDescription*& axleDescription,
179 const PxVehicleRigidBodyState*& rigidBodyState,
181 PxVehicleArrayData<const PxTransform>& wheelShapeLocalPoses,
184 const PxVehicleGearboxState*& gearState,
185 PxVehiclePhysXActor*& physxActor) = 0;
186
187 virtual bool update(const PxReal dt, const PxVehicleSimulationContext& context)
188 {
189 PX_UNUSED(dt);
190
191 PX_PROFILE_ZONE("PxVehiclePhysXActorEndComponent::update", 0);
192
193 const PxVehicleAxleDescription* axleDescription;
194 const PxVehicleRigidBodyState* rigidBodyState;
196 PxVehicleArrayData<const PxTransform> wheelShapeLocalPoses;
199 const PxVehicleGearboxState* gearState;
200 PxVehiclePhysXActor* physxActor;
201
202 getDataForPhysXActorEndComponent(axleDescription, rigidBodyState,
203 wheelParams, wheelShapeLocalPoses, wheelRigidBody1dStates, wheelLocalPoses, gearState,
204 physxActor);
205
206 for (PxU32 i = 0; i < axleDescription->nbWheels; i++)
207 {
208 const PxU32 wheelId = axleDescription->wheelIdsInAxleOrder[i];
209
210 PxVehicleWriteWheelLocalPoseToPhysXWheelShape(wheelLocalPoses[wheelId].localPose, wheelShapeLocalPoses[wheelId],
211 physxActor->wheelShapes[wheelId]);
212 }
213
215 {
216 const PxVehiclePhysXSimulationContext& physxContext = static_cast<const PxVehiclePhysXSimulationContext&>(context);
217
218 PxVehicleWriteRigidBodyStateToPhysXActor(physxContext.physxActorUpdateMode, *rigidBodyState, dt, *physxActor->rigidBody);
219
220 PxVehiclePhysxActorKeepAwakeCheck(*axleDescription, wheelParams, wheelRigidBody1dStates,
221 physxContext.physxActorWakeCounterThreshold, physxContext.physxActorWakeCounterResetValue, gearState,
222 *physxActor->rigidBody);
223 }
224 else
225 {
226 PX_ALWAYS_ASSERT();
227 }
228
229 return true;
230 }
231};
232
233#if !PX_DOXYGEN
234} // namespace vehicle2
235} // namespace physx
236#endif
237
Definition base.h:1940
virtual PxScene * getScene() const =0
Retrieves the scene which this actor belongs to.
Definition PxVehicleComponent.h:45
Work items at the beginning of an update step for a PhysX actor based vehicle.
Definition PxVehiclePhysXActorComponents.h:62
virtual bool update(const PxReal dt, const PxVehicleSimulationContext &context)
Update function for a vehicle component.
Definition PxVehiclePhysXActorComponents.h:107
virtual void getDataForPhysXActorBeginComponent(const PxVehicleAxleDescription *&axleDescription, const PxVehicleCommandState *&commands, const PxVehicleEngineDriveTransmissionCommandState *&transmissionCommands, const PxVehicleGearboxParams *&gearParams, const PxVehicleGearboxState *&gearState, const PxVehicleEngineParams *&engineParams, PxVehiclePhysXActor *&physxActor, PxVehiclePhysXSteerState *&physxSteerState, PxVehiclePhysXConstraints *&physxConstraints, PxVehicleRigidBodyState *&rigidBodyState, PxVehicleArrayData< PxVehicleWheelRigidBody1dState > &wheelRigidBody1dStates, PxVehicleEngineState *&engineState)=0
Provide vehicle data items for this component.
Work items at the end of an update step for a PhysX actor based vehicle.
Definition PxVehiclePhysXActorComponents.h:158
virtual void getDataForPhysXActorEndComponent(const PxVehicleAxleDescription *&axleDescription, const PxVehicleRigidBodyState *&rigidBodyState, PxVehicleArrayData< const PxVehicleWheelParams > &wheelParams, PxVehicleArrayData< const PxTransform > &wheelShapeLocalPoses, PxVehicleArrayData< const PxVehicleWheelRigidBody1dState > &wheelRigidBody1dStates, PxVehicleArrayData< const PxVehicleWheelLocalPose > &wheelLocalPoses, const PxVehicleGearboxState *&gearState, PxVehiclePhysXActor *&physxActor)=0
Provide vehicle data items for this component.
virtual bool update(const PxReal dt, const PxVehicleSimulationContext &context)
Update function for a vehicle component.
Definition PxVehiclePhysXActorComponents.h:187
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Helper struct to pass array type data to vehice components and functions.
Definition PxVehicleParams.h:249
Definition PxVehicleParams.h:53
PxU32 wheelIdsInAxleOrder[PxVehicleLimits::eMAX_NB_WHEELS]
The list of all wheel ids on the vehicle.
Definition PxVehicleParams.h:149
PxU32 nbWheels
The number of wheels on the vehicle.
Definition PxVehicleParams.h:150
A description of the state of commands that are applied to the vehicle.
Definition PxVehicleCommandStates.h:53
A description of the state of transmission-related commands that are applied to a vehicle with engine...
Definition PxVehicleCommandStates.h:92
Definition PxVehicleDrivetrainParams.h:192
Definition PxVehicleDrivetrainStates.h:67
Definition PxVehicleDrivetrainParams.h:320
Definition PxVehicleDrivetrainStates.h:85
A description of the PhysX actor and shapes that represent the vehicle in an associated PxScene.
Definition PxVehiclePhysXActorStates.h:55
PxShape * wheelShapes[PxVehicleLimits::eMAX_NB_WHEELS]
An array of shapes with one shape pointer (or NULL) for each wheel.
Definition PxVehiclePhysXActorStates.h:65
PxRigidBody * rigidBody
The PhysX rigid body that represents the vehcle in the associated PhysX scene.
Definition PxVehiclePhysXActorStates.h:60
A mapping between constraint state data and the associated PxConstraint instances.
Definition PxVehiclePhysXConstraintStates.h:317
Definition PxVehicleParams.h:742
PxReal physxActorWakeCounterThreshold
Threshold below which to check whether the physx actor wake counter should get reset.
Definition PxVehicleParams.h:778
PxReal physxActorWakeCounterResetValue
Wake counter value to set on the physx actor if a reset is required.
Definition PxVehicleParams.h:768
A description of the previous steer command applied to the vehicle.
Definition PxVehiclePhysXActorStates.h:80
Definition PxVehicleRigidBodyStates.h:47
@ ePHYSX
The simulation context inherits from PxVehiclePhysXSimulationContext.
Definition PxVehicleParams.h:633
Definition PxVehicleParams.h:672