feat(physics): wire physx sdk into build

This commit is contained in:
2026-04-15 12:22:15 +08:00
parent 5bf258df6d
commit 31f40e2cbb
2044 changed files with 752623 additions and 1 deletions

View File

@@ -0,0 +1,239 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#pragma once
#include "vehicle2/PxVehicleParams.h"
#include "vehicle2/PxVehicleComponent.h"
#include "vehicle2/wheel/PxVehicleWheelStates.h"
#include "PxVehiclePhysXActorFunctions.h"
#include "PxVehiclePhysXActorStates.h"
#include "common/PxProfileZone.h"
#if !PX_DOXYGEN
namespace physx
{
namespace vehicle2
{
#endif
/**
\brief Work items at the beginning of an update step for a PhysX actor based vehicle.
Includes:
- Waking the actor up if it is sleeping and a throttle or steer command is issued.
- Clearing certain states if the actor is sleeping.
- Reading the state from the PhysX actor and copy to the vehicle internal state.
\see PxVehiclePhysxActorWakeup PxVehiclePhysxActorSleepCheck PxVehicleReadRigidBodyStateFromPhysXActor
*/
class PxVehiclePhysXActorBeginComponent : public PxVehicleComponent
{
public:
PxVehiclePhysXActorBeginComponent() : PxVehicleComponent() {}
virtual ~PxVehiclePhysXActorBeginComponent() {}
/**
\brief Provide vehicle data items for this component.
\param[out] axleDescription identifies the wheels on each axle.
\param[out] commands are the brake, throttle and steer values that will drive the vehicle.
\param[out] transmissionCommands are the target gear and clutch values that will control
the transmission. Can be set to NULL if the vehicle does not have a gearbox. If
specified, then gearParams and gearState has to be specifed too.
\param[out] gearParams The gearbox parameters. Can be set to NULL if the vehicle does
not have a gearbox and transmissionCommands is NULL.
\param[out] gearState The state of the gearbox. Can be set to NULL if the vehicle does
not have a gearbox and transmissionCommands is NULL.
\param[out] engineParams The engine parameters. Can be set to NULL if the vehicle does
not have an engine. Must be specified, if engineState is specified.
\param[out] physxActor is the PxRigidBody instance associated with the vehicle.
\param[out] physxSteerState is the previous state of the steer and is used to determine if the
steering wheel has changed by comparing with PxVehicleCommandState::steer.
\param[out] physxConstraints The state of the suspension limit and low speed tire constraints.
If the vehicle actor is sleeping and constraints are active, they will be
deactivated and marked as dirty.
\param[out] rigidBodyState is the state of the rigid body used by the Vehicle SDK.
\param[out] wheelRigidBody1dStates describes the angular speed of each wheel.
\param[out] engineState The engine state. Can be set to NULL if the vehicle does
not have an engine. If specified, then engineParams has to be specifed too.
*/
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;
virtual bool update(const PxReal dt, const PxVehicleSimulationContext& context)
{
PX_UNUSED(dt);
PX_UNUSED(context);
PX_PROFILE_ZONE("PxVehiclePhysXActorBeginComponent::update", 0);
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;
getDataForPhysXActorBeginComponent(axleDescription, commands, transmissionCommands,
gearParams, gearState, engineParams,
physxActor, physxSteerState, physxConstraints,
rigidBodyState, wheelRigidBody1dStates, engineState);
if (physxActor->rigidBody->getScene()) // Considering case where actor is not in a scene and constraints get solved via immediate mode
{
PxVehiclePhysxActorWakeup(*commands, transmissionCommands, gearParams, gearState,
*physxActor->rigidBody, *physxSteerState);
if (PxVehiclePhysxActorSleepCheck(*axleDescription, *physxActor->rigidBody, engineParams,
*rigidBodyState, *physxConstraints, wheelRigidBody1dStates, engineState))
{
return false;
}
}
PxVehicleReadRigidBodyStateFromPhysXActor(*physxActor->rigidBody, *rigidBodyState);
return true;
}
};
/**
\brief Work items at the end of an update step for a PhysX actor based vehicle.
Includes:
- Writing vehicle internal state to the PhysX actor.
- Keeping the vehicle awake if certain criteria are met.
*/
class PxVehiclePhysXActorEndComponent : public PxVehicleComponent
{
public:
PxVehiclePhysXActorEndComponent() : PxVehicleComponent() {}
virtual ~PxVehiclePhysXActorEndComponent() {}
/**
\brief Provide vehicle data items for this component.
\param[out] axleDescription identifies the wheels on each axle.
\param[out] rigidBodyState is the state of the rigid body used by the Vehicle SDK.
\param[out] wheelParams describes the radius, mass etc. of the wheels.
\param[out] wheelShapeLocalPoses are the local poses in the wheel's frame to apply to the PxShape instances that represent the wheel
\param[out] wheelRigidBody1dStates describes the angular speed of the wheels.
\param[out] wheelLocalPoses describes the local poses of the wheels in the rigid body frame.
\param[out] gearState The gear state. Can be set to NULL if the vehicle does
not have gears.
\param[out] throttle The throttle command state (see #PxVehicleCommandState).
Can be set to NULL if the vehicle is not controlled through
PxVehicleCommandState.
\param[out] physxActor is the PxRigidBody instance associated with the vehicle.
*/
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,
const PxReal*& throttle,
PxVehiclePhysXActor*& physxActor) = 0;
virtual bool update(const PxReal dt, const PxVehicleSimulationContext& context)
{
PX_UNUSED(dt);
PX_PROFILE_ZONE("PxVehiclePhysXActorEndComponent::update", 0);
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;
const PxReal* throttle;
PxVehiclePhysXActor* physxActor;
getDataForPhysXActorEndComponent(axleDescription, rigidBodyState,
wheelParams, wheelShapeLocalPoses, wheelRigidBody1dStates, wheelLocalPoses, gearState, throttle,
physxActor);
for (PxU32 i = 0; i < axleDescription->nbWheels; i++)
{
const PxU32 wheelId = axleDescription->wheelIdsInAxleOrder[i];
PxVehicleWriteWheelLocalPoseToPhysXWheelShape(wheelLocalPoses[wheelId].localPose, wheelShapeLocalPoses[wheelId],
physxActor->wheelShapes[wheelId]);
}
if (context.getType() == PxVehicleSimulationContextType::ePHYSX)
{
const PxVehiclePhysXSimulationContext& physxContext = static_cast<const PxVehiclePhysXSimulationContext&>(context);
PxVehicleWriteRigidBodyStateToPhysXActor(physxContext.physxActorUpdateMode, *rigidBodyState, dt, *physxActor->rigidBody);
PxVehiclePhysxActorKeepAwakeCheck(*axleDescription, wheelParams, wheelRigidBody1dStates,
physxContext.physxActorWakeCounterThreshold, physxContext.physxActorWakeCounterResetValue, gearState, throttle,
*physxActor->rigidBody);
}
else
{
PX_ALWAYS_ASSERT();
}
return true;
}
};
#if !PX_DOXYGEN
} // namespace vehicle2
} // namespace physx
#endif

View File

@@ -0,0 +1,196 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#pragma once
#include "foundation/PxSimpleTypes.h"
#include "foundation/PxTransform.h"
#include "vehicle2/PxVehicleParams.h"
#if !PX_DOXYGEN
namespace physx
{
class PxRigidBody;
class PxShape;
namespace vehicle2
{
#endif
struct PxVehicleCommandState;
struct PxVehicleEngineDriveTransmissionCommandState;
struct PxVehicleEngineParams;
struct PxVehicleEngineState;
struct PxVehicleGearboxParams;
struct PxVehicleGearboxState;
struct PxVehicleRigidBodyState;
struct PxVehiclePhysXConstraints;
struct PxVehicleWheelLocalPose;
struct PxVehicleWheelParams;
struct PxVehicleWheelRigidBody1dState;
struct PxVehiclePhysXSteerState;
/**
\brief Wake up the physx actor if the actor is asleep and the commands signal an intent to
change the state of the vehicle.
\param[in] commands are the brake, throttle and steer values that will drive the vehicle.
\param[in] transmissionCommands are the target gear and clutch values that will control
the transmission. If the target gear is different from the current gearbox
target gear, then the physx actor will get woken up. Can be set to NULL if the
vehicle does not have a gearbox or if this is not a desired behavior. If
specified, then gearParams and gearState has to be specifed too.
\param[in] gearParams The gearbox parameters. Can be set to NULL if the vehicle does
not have a gearbox and transmissionCommands is NULL.
\param[in] gearState The state of the gearbox. Can be set to NULL if the vehicle does
not have a gearbox and transmissionCommands is NULL.
\param[in] physxActor is the PxRigidBody instance associated with the vehicle.
\param[in,out] physxSteerState and commands are compared to
determine if the steering state has changed since the last call to PxVehiclePhysxActorWakeup().
\note If the steering has changed, the actor will be woken up.
\note On exit from PxVehiclePhysxActorWakeup, physxSteerState.previousSteerCommand is assigned to the value
of commands.steer so that the steer state may be propagated to the subsequent call to PxVehiclePhysxActorWakeup().
\note If physxSteerState.previousSteerCommand has value PX_VEHICLE_UNSPECIFIED_STEER_STATE, the steering state
is treated as though it has not changed.
*/
void PxVehiclePhysxActorWakeup(
const PxVehicleCommandState& commands,
const PxVehicleEngineDriveTransmissionCommandState* transmissionCommands,
const PxVehicleGearboxParams* gearParams,
const PxVehicleGearboxState* gearState,
PxRigidBody& physxActor,
PxVehiclePhysXSteerState& physxSteerState);
/**
\brief Check if the physx actor is sleeping and clear certain vehicle states if it is.
\param[in] axleDescription identifies the wheels on each axle.
\param[in] physxActor is the PxRigidBody instance associated with the vehicle.
\param[in] engineParams The engine parameters. Can be set to NULL if the vehicle does
not have an engine. Must be specified, if engineState is specified.
\param[in,out] rigidBodyState is the state of the rigid body used by the Vehicle SDK.
\param[in,out] physxConstraints The state of the suspension limit and low speed tire constraints.
If the vehicle actor is sleeping and constraints are active, they will be
deactivated and marked as dirty.
\param[in,out] wheelRigidBody1dStates describes the angular speed of the wheels.
\param[out] engineState The engine state. Can be set to NULL if the vehicle does
not have an engine. If specified, then engineParams has to be specifed too.
The engine rotation speed will get set to the idle rotation speed if
the actor is sleeping.
\return True if the actor was sleeping, else false.
*/
bool PxVehiclePhysxActorSleepCheck
(const PxVehicleAxleDescription& axleDescription,
const PxRigidBody& physxActor,
const PxVehicleEngineParams* engineParams,
PxVehicleRigidBodyState& rigidBodyState,
PxVehiclePhysXConstraints& physxConstraints,
PxVehicleArrayData<PxVehicleWheelRigidBody1dState>& wheelRigidBody1dStates,
PxVehicleEngineState* engineState);
/**
\brief Check if the physx actor has to be kept awake.
Certain criteria should keep the vehicle physx actor awake, for example, if the
(mass normalized) rotational kinetic energy of the wheels is above a certain
threshold or if a gear change is pending or if throttle is applied.
This method will reset the wake counter of the physx actor to a specified value,
if any of the mentioned criteria are met.
\note The physx actor's sleep threshold will be used as threshold to test against
for the energy criteria.
\param[in] axleDescription identifies the wheels on each axle.
\param[in] wheelParams describes the radius, mass etc. of the wheels.
\param[in] wheelRigidBody1dStates describes the angular speed of the wheels.
\param[in] wakeCounterThreshold Once the wake counter of the physx actor falls
below this threshold, the method will start testing if the wake
counter needs to be reset.
\param[in] wakeCounterResetValue The value to set the physx actor wake counter
to, if any of the criteria to do so are met.
\param[in] gearState The gear state. Can be set to NULL if the vehicle does
not have gears or if the mentioned behavior is not desired.
\param[in] throttle The throttle command state (see #PxVehicleCommandState).
Can be set to NULL if the vehicle is not controlled through
PxVehicleCommandState or if the mentioned behavior is not desired.
\param[in] physxActor is the PxRigidBody instance associated with the vehicle.
*/
void PxVehiclePhysxActorKeepAwakeCheck
(const PxVehicleAxleDescription& axleDescription,
const PxVehicleArrayData<const PxVehicleWheelParams>& wheelParams,
const PxVehicleArrayData<const PxVehicleWheelRigidBody1dState>& wheelRigidBody1dStates,
const PxReal wakeCounterThreshold,
const PxReal wakeCounterResetValue,
const PxVehicleGearboxState* gearState,
const PxReal* throttle,
PxRigidBody& physxActor);
/**
\brief Read the rigid body state from a PhysX actor.
\param[in] physxActor is a reference to a PhysX actor.
\param[out] rigidBodyState is the state of the rigid body used by the Vehicle SDK.
*/
void PxVehicleReadRigidBodyStateFromPhysXActor
(const PxRigidBody& physxActor,
PxVehicleRigidBodyState& rigidBodyState);
/**
\brief Update the local pose of a PxShape that is associated with a wheel.
\param[in] wheelLocalPose describes the local pose of each wheel in the rigid body frame.
\param[in] wheelShapeLocalPose describes the local pose to apply to the PxShape instance in the wheel's frame.
\param[in] shape is the target PxShape.
*/
void PxVehicleWriteWheelLocalPoseToPhysXWheelShape
(const PxTransform& wheelLocalPose, const PxTransform& wheelShapeLocalPose, PxShape* shape);
/**
\brief Write the rigid body state to a PhysX actor.
\param[in] physxActorUpdateMode controls whether the PhysX actor is to be updated with
instantaneous velocity changes or with accumulated accelerations to be applied in
the next simulation step of the associated PxScene.
\param[in] rigidBodyState is the state of the rigid body.
\param[in] dt is the simulation time that has elapsed since the last call to
PxVehicleWriteRigidBodyStateToPhysXActor().
\param[out] physXActor is a reference to the PhysX actor.
*/
void PxVehicleWriteRigidBodyStateToPhysXActor
(const PxVehiclePhysXActorUpdateMode::Enum physxActorUpdateMode,
const PxVehicleRigidBodyState& rigidBodyState,
const PxReal dt,
PxRigidBody& physXActor);
#if !PX_DOXYGEN
} // namespace vehicle2
} // namespace physx
#endif

View File

@@ -0,0 +1,205 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#pragma once
#include "PxFiltering.h"
#include "PxShape.h"
#if !PX_DOXYGEN
namespace physx
{
class PxGeometry;
class PxMaterial;
struct PxCookingParams;
namespace vehicle2
{
#endif
struct PxVehicleRigidBodyParams;
struct PxVehicleAxleDescription;
struct PxVehicleWheelParams;
struct PxVehiclePhysXActor;
struct PxVehicleFrame;
struct PxVehicleSuspensionParams;
class PxVehiclePhysXRigidActorParams
{
PX_NOCOPY(PxVehiclePhysXRigidActorParams)
public:
PxVehiclePhysXRigidActorParams(const PxVehicleRigidBodyParams& _physxActorRigidBodyParams, const char* _physxActorName)
: rigidBodyParams(_physxActorRigidBodyParams),
physxActorName(_physxActorName)
{
}
const PxVehicleRigidBodyParams& rigidBodyParams;
const char* physxActorName;
};
class PxVehiclePhysXRigidActorShapeParams
{
PX_NOCOPY(PxVehiclePhysXRigidActorShapeParams)
public:
PxVehiclePhysXRigidActorShapeParams
(const PxGeometry& _geometry, const PxTransform& _localPose, const PxMaterial& _material,
const PxShapeFlags _flags, const PxFilterData& _simulationFilterData, const PxFilterData& _queryFilterData)
: geometry(_geometry),
localPose(_localPose),
material(_material),
flags(_flags),
simulationFilterData(_simulationFilterData),
queryFilterData(_queryFilterData)
{
}
const PxGeometry& geometry;
const PxTransform& localPose;
const PxMaterial& material;
PxShapeFlags flags;
PxFilterData simulationFilterData;
PxFilterData queryFilterData;
};
class PxVehiclePhysXWheelParams
{
PX_NOCOPY(PxVehiclePhysXWheelParams)
public:
PxVehiclePhysXWheelParams(const PxVehicleAxleDescription& _axleDescription, const PxVehicleWheelParams* _wheelParams)
: axleDescription(_axleDescription),
wheelParams(_wheelParams)
{
}
const PxVehicleAxleDescription& axleDescription;
const PxVehicleWheelParams* wheelParams;
};
class PxVehiclePhysXWheelShapeParams
{
PX_NOCOPY(PxVehiclePhysXWheelShapeParams)
public:
PxVehiclePhysXWheelShapeParams(const PxMaterial& _material, const PxShapeFlags _flags, const PxFilterData _simulationFilterData, const PxFilterData _queryFilterData)
: material(_material),
flags(_flags),
simulationFilterData(_simulationFilterData),
queryFilterData(_queryFilterData)
{
}
const PxMaterial& material;
PxShapeFlags flags;
PxFilterData simulationFilterData;
PxFilterData queryFilterData;
};
/**
\brief Create a PxRigidDynamic instance, instantiate it with desired properties and populate it with PxShape instances.
\param[in] vehicleFrame describes the frame of the vehicle.
\param[in] rigidActorParams describes the mass and moment of inertia of the rigid body.
\param[in] rigidActorCmassLocalPose specifies the mapping between actor and rigid body frame.
\param[in] rigidActorShapeParams describes the collision geometry associated with the rigid body.
\param[in] wheelParams describes the radius and half-width of the wheels.
\param[in] wheelShapeParams describes the PxMaterial and PxShapeFlags to apply to the wheel shapes.
\param[in] physics is a PxPhysics instance.
\param[in] params is a PxCookingParams instance
\param[in] vehiclePhysXActor is a record of the PxRigidDynamic and PxShape instances instantiated.
\note This is an alternative to PxVehiclePhysXArticulationLinkCreate.
\note PxVehiclePhysXActorCreate primarily serves as an illustration of the instantiation of the PhysX class instances
required to simulate a vehicle with a PxRigidDynamic.
\see PxVehiclePhysXActorDestroy
*/
void PxVehiclePhysXActorCreate
(const PxVehicleFrame& vehicleFrame,
const PxVehiclePhysXRigidActorParams& rigidActorParams, const PxTransform& rigidActorCmassLocalPose,
const PxVehiclePhysXRigidActorShapeParams& rigidActorShapeParams,
const PxVehiclePhysXWheelParams& wheelParams, const PxVehiclePhysXWheelShapeParams& wheelShapeParams,
PxPhysics& physics, const PxCookingParams& params,
PxVehiclePhysXActor& vehiclePhysXActor);
/**
\brief Configure an actor so that it is ready for vehicle simulation.
\param[in] rigidActorParams describes the mass and moment of inertia of the rigid body.
\param[in] rigidActorCmassLocalPose specifies the mapping between actor and rigid body frame.
\param[out] rigidBody is the body to be prepared for simulation.
*/
void PxVehiclePhysXActorConfigure
(const PxVehiclePhysXRigidActorParams& rigidActorParams, const PxTransform& rigidActorCmassLocalPose,
PxRigidBody& rigidBody);
/**
\brief Create a PxArticulationReducedCoordinate and a single PxArticulationLink,
instantiate the PxArticulationLink with desired properties and populate it with PxShape instances.
\param[in] vehicleFrame describes the frame of the vehicle.
\param[in] rigidActorParams describes the mass and moment of inertia of the rigid body.
\param[in] rigidActorCmassLocalPose specifies the mapping between actor and rigid body frame.
\param[in] rigidActorShapeParams describes the collision geometry associated with the rigid body.
\param[in] wheelParams describes the radius and half-width of the wheels.
\param[in] wheelShapeParams describes the PxMaterial and PxShapeFlags to apply to the wheel shapes.
\param[in] physics is a PxPhysics instance.
\param[in] params is a PxCookingParams instance
\param[in] vehiclePhysXActor is a record of the PxArticulationReducedCoordinate, PxArticulationLink and PxShape instances instantiated.
\note This is an alternative to PxVehiclePhysXActorCreate.
\note PxVehiclePhysXArticulationLinkCreate primarily serves as an illustration of the instantiation of the PhysX class instances
required to simulate a vehicle as part of an articulated ensemble.
\see PxVehiclePhysXActorDestroy
*/
void PxVehiclePhysXArticulationLinkCreate
(const PxVehicleFrame& vehicleFrame,
const PxVehiclePhysXRigidActorParams& rigidActorParams, const PxTransform& rigidActorCmassLocalPose,
const PxVehiclePhysXRigidActorShapeParams& rigidActorShapeParams,
const PxVehiclePhysXWheelParams& wheelParams, const PxVehiclePhysXWheelShapeParams& wheelShapeParams,
PxPhysics& physics, const PxCookingParams& params,
PxVehiclePhysXActor& vehiclePhysXActor);
/**
\brief Release the PxRigidDynamic, PxArticulationReducedCoordinate, PxArticulationLink and PxShape instances
instantiated by PxVehiclePhysXActorCreate or PxVehiclePhysXArticulationLinkCreate.
\param[in] vehiclePhysXActor is a description of the PhysX instances to be released.
*/
void PxVehiclePhysXActorDestroy(PxVehiclePhysXActor& vehiclePhysXActor);
#if !PX_DOXYGEN
} // namespace vehicle2
} // namespace physx
#endif

View File

@@ -0,0 +1,94 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#pragma once
#include "foundation/PxPreprocessor.h"
#include "foundation/PxMemory.h"
#include "PxRigidBody.h"
#include "vehicle2/PxVehicleLimits.h"
#if !PX_DOXYGEN
namespace physx
{
class PxShape;
namespace vehicle2
{
#endif
/**
\brief A description of the PhysX actor and shapes that represent the vehicle in an associated PxScene.
*/
struct PxVehiclePhysXActor
{
/**
\brief The PhysX rigid body that represents the vehcle in the associated PhysX scene.
\note PxActorFlag::eDISABLE_GRAVITY must be set true on the PxRigidBody
*/
PxRigidBody* rigidBody;
/**
\brief An array of shapes with one shape pointer (or NULL) for each wheel.
*/
PxShape* wheelShapes[PxVehicleLimits::eMAX_NB_WHEELS];
PX_FORCE_INLINE void setToDefault()
{
PxMemZero(this, sizeof(PxVehiclePhysXActor));
}
};
#define PX_VEHICLE_UNSPECIFIED_STEER_STATE PX_MAX_F32
/**
\brief A description of the previous steer command applied to the vehicle.
*/
struct PxVehiclePhysXSteerState
{
/**
\brief The steer command that was most previously applied to the vehicle.
*/
PxReal previousSteerCommand;
PX_FORCE_INLINE void setToDefault()
{
previousSteerCommand = PX_VEHICLE_UNSPECIFIED_STEER_STATE;
}
};
#if !PX_DOXYGEN
} // namespace vehicle2
} // namespace physx
#endif