physxCAPI/physxCDLL/physxApi.hpp

1447 lines
68 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifdef _WIN32
#define EXPORT_API __declspec(dllexport)
#endif
//¸øc# ʹÓà ²»ÐèÒª¶¨Òådllimport
#ifdef __linux__
#define EXPORT_API __attribute__((visibility ("default")))
#endif
#define CALL _cdecl
#include "physxABIStruct.hpp";
extern "C"
{
physx::PxDefaultAllocator gAllocator;
physx::PxDefaultErrorCallback gErrorCallback;
EXPORT_API physx_PxFoundation_Pod* CALL physx_create_foundation()
{
physx::PxFoundation* return_val = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
auto return_val_pod = reinterpret_cast<physx_PxFoundation_Pod*>(return_val);
return return_val_pod;
}
//// fixme[tolsson]: this might be iffy on Windows with DLLs if we have multiple packages
//// linking against the raw interface
//physx::PxAllocatorCallback* CALL get_default_allocator()
//{
// return &gAllocator;
//}
EXPORT_API physx_PxPvd_Pod* CALL phys_PxCreatePvd(physx_PxFoundation_Pod* foundation_pod) {
physx::PxFoundation& foundation = reinterpret_cast<physx::PxFoundation&>(*foundation_pod);
physx::PxPvd* return_val = nullptr;
try
{
return_val = PxCreatePvd(foundation);
auto return_val_pod = reinterpret_cast<physx_PxPvd_Pod*>(return_val);
return return_val_pod;
}
catch (const std::exception&)
{
if (return_val == nullptr)
{
printf("hello world");
}
printf("phys_PxCreatePvd error\n");
}
}
EXPORT_API physx_PxPhysics_Pod* CALL physx_create_physics(physx_PxFoundation_Pod* foundation)
{
physx::PxFoundation& foundation1 = reinterpret_cast<physx::PxFoundation&>(*foundation);
physx::PxPhysics* return_val = PxCreatePhysics(PX_PHYSICS_VERSION, foundation1, physx::PxTolerancesScale(), true, nullptr, nullptr);
auto return_val_pod = reinterpret_cast<physx_PxPhysics_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API physx_PxPhysics_Pod* CALL phys_PxCreatePhysics(uint32_t version, physx_PxFoundation_Pod* foundation_pod, physx_PxTolerancesScale_Pod const* scale_pod, bool trackOutstandingAllocations, physx_PxPvd_Pod* pvd_pod, physx_PxOmniPvd_Pod* omniPvd_pod) {
physx::PxFoundation& foundation = reinterpret_cast<physx::PxFoundation&>(*foundation_pod);
physx::PxTolerancesScale const& scale = reinterpret_cast<physx::PxTolerancesScale const&>(*scale_pod);
physx::PxPvd* pvd = reinterpret_cast<physx::PxPvd*>(pvd_pod);
physx::PxOmniPvd* omniPvd = reinterpret_cast<physx::PxOmniPvd*>(omniPvd_pod);
physx::PxPhysics* return_val = PxCreatePhysics(version, foundation, scale, trackOutstandingAllocations, pvd, omniPvd);
auto return_val_pod = reinterpret_cast<physx_PxPhysics_Pod*>(return_val);
return return_val_pod;
//return nullptr;
}
EXPORT_API physx_PxDefaultCpuDispatcher_Pod* CALL phys_PxDefaultCpuDispatcherCreate(uint32_t numThreads, uint32_t* affinityMasks, int32_t mode_pod, uint32_t yieldProcessorCount) {
auto mode = static_cast<physx::PxDefaultCpuDispatcherWaitForWorkMode::Enum>(mode_pod);
physx::PxDefaultCpuDispatcher* return_val = PxDefaultCpuDispatcherCreate(numThreads, affinityMasks, mode, yieldProcessorCount);
auto return_val_pod = reinterpret_cast<physx_PxDefaultCpuDispatcher_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API physx_PxMaterial_Pod* CALL PxPhysics_createMaterial_mut(physx_PxPhysics_Pod* self__pod, float staticFriction, float dynamicFriction, float restitution) {
physx::PxPhysics* self_ = reinterpret_cast<physx::PxPhysics*>(self__pod);
physx::PxMaterial* return_val = self_->createMaterial(staticFriction, dynamicFriction, restitution);
auto return_val_pod = reinterpret_cast<physx_PxMaterial_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API physx_PxPvdTransport_Pod* CALL phys_PxDefaultPvdSocketTransportCreate(char const* host, int32_t port, uint32_t timeoutInMilliseconds) {
physx::PxPvdTransport* return_val = physx::PxDefaultPvdSocketTransportCreate(host, port, timeoutInMilliseconds);
auto return_val_pod = reinterpret_cast<physx_PxPvdTransport_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API bool CALL PxPvd_connect_mut(physx_PxPvd_Pod* self__pod, physx_PxPvdTransport_Pod* transport_pod, uint8_t flags_pod) {
physx::PxPvd* self_ = reinterpret_cast<physx::PxPvd*>(self__pod);
physx::PxPvdTransport& transport = reinterpret_cast<physx::PxPvdTransport&>(*transport_pod);
auto flags = physx::PxPvdInstrumentationFlags(flags_pod);
bool return_val = self_->connect(transport, flags);
return return_val;
}
EXPORT_API physx_PxTolerancesScale_Pod const* CALL PxPhysics_getTolerancesScale(physx_PxPhysics_Pod const* self__pod) {
physx::PxPhysics const* self_ = reinterpret_cast<physx::PxPhysics const*>(self__pod);
physx::PxTolerancesScale const& return_val = self_->getTolerancesScale();
auto return_val_pod = reinterpret_cast<physx_PxTolerancesScale_Pod const*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxSceneDesc_Pod CALL PxSceneDesc_new(physx_PxTolerancesScale_Pod const* scale_pod) {
physx::PxTolerancesScale const& scale = reinterpret_cast<physx::PxTolerancesScale const&>(*scale_pod);
physx::PxSceneDesc return_val(scale);
physx_PxSceneDesc_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxScene_Pod* CALL PxPhysics_createScene_mut(physx_PxPhysics_Pod* self__pod, physx_PxSceneDesc_Pod const* sceneDesc_pod) {
physx::PxPhysics* self_ = reinterpret_cast<physx::PxPhysics*>(self__pod);
physx::PxSceneDesc const& sceneDesc = reinterpret_cast<physx::PxSceneDesc const&>(*sceneDesc_pod);
physx::PxScene* return_val = self_->createScene(sceneDesc);
auto return_val_pod = reinterpret_cast<physx_PxScene_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API bool CALL PxScene_addActor_mut(physx_PxScene_Pod* self__pod, physx_PxActor_Pod* actor_pod, physx_PxBVH_Pod const* bvh_pod) {
physx::PxScene* self_ = reinterpret_cast<physx::PxScene*>(self__pod);
physx::PxActor& actor = reinterpret_cast<physx::PxActor&>(*actor_pod);
physx::PxBVH const* bvh = reinterpret_cast<physx::PxBVH const*>(bvh_pod);
bool return_val = self_->addActor(actor, bvh);
return return_val;
}
EXPORT_API physx_PxSphereGeometry_Pod CALL PxSphereGeometry_new(float ir) {
physx::PxSphereGeometry return_val(ir);
physx_PxSphereGeometry_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxSphereGeometry_Pod CALL PxSphereGeometry_new_pointer(float ir) {
physx::PxSphereGeometry return_val(ir);
physx_PxSphereGeometry_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API bool CALL PxSphereGeometry_isValid(physx_PxSphereGeometry_Pod const* self__pod) {
physx::PxSphereGeometry const* self_ = reinterpret_cast<physx::PxSphereGeometry const*>(self__pod);
bool return_val = self_->isValid();
return return_val;
}
EXPORT_API void CALL PxScene_lockWrite_mut(physx_PxScene_Pod* self__pod, char const* file, uint32_t line) {
physx::PxScene* self_ = reinterpret_cast<physx::PxScene*>(self__pod);
self_->lockWrite(file, line);
}
EXPORT_API void CALL PxScene_unlockWrite_mut(physx_PxScene_Pod* self__pod) {
physx::PxScene* self_ = reinterpret_cast<physx::PxScene*>(self__pod);
self_->unlockWrite();
}
EXPORT_API physx_PxTransform_Pod CALL PxTransform_new_2(int32_t anon_param0_pod) {
auto anon_param0 = static_cast<physx::PxIDENTITY>(anon_param0_pod);
physx::PxTransform return_val(anon_param0);
physx_PxTransform_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxRigidDynamic_Pod* CALL phys_PxCreateDynamic(physx_PxPhysics_Pod* sdk_pod, physx_PxTransform_Pod const* transform_pod,
physx_PxGeometry_Pod const* geometry_pod, physx_PxMaterial_Pod* material_pod, float density, physx_PxTransform_Pod const* shapeOffset_pod)
{
physx::PxPhysics& sdk = reinterpret_cast<physx::PxPhysics&>(*sdk_pod);
physx::PxTransform const& transform = reinterpret_cast<physx::PxTransform const&>(*transform_pod);
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const &>(*geometry_pod);
physx::PxMaterial& material = reinterpret_cast<physx::PxMaterial&>(*material_pod);
physx::PxTransform const& shapeOffset = reinterpret_cast<physx::PxTransform const&>(*shapeOffset_pod);
physx::PxRigidDynamic* return_val = PxCreateDynamic(sdk, transform, geometry, material, density, shapeOffset);
auto return_val_pod = reinterpret_cast<physx_PxRigidDynamic_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API physx_PxRigidDynamic_Pod* CALL phys_PxCreateDynamic_1(physx_PxPhysics_Pod* sdk_pod, physx_PxTransform_Pod const* transform_pod, physx_PxShape_Pod* shape_pod, float density) {
physx::PxPhysics& sdk = reinterpret_cast<physx::PxPhysics&>(*sdk_pod);
physx::PxTransform const& transform = reinterpret_cast<physx::PxTransform const&>(*transform_pod);
physx::PxShape& shape = reinterpret_cast<physx::PxShape&>(*shape_pod);
physx::PxRigidDynamic* return_val = PxCreateDynamic(sdk, transform, shape, density);
auto return_val_pod = reinterpret_cast<physx_PxRigidDynamic_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API void CALL PxActor_setActorFlag_mut(physx_PxActor_Pod* self__pod, int32_t flag_pod, bool value) {
physx::PxActor* self_ = reinterpret_cast<physx::PxActor*>(self__pod);
auto flag = static_cast<physx::PxActorFlag::Enum>(flag_pod);
self_->setActorFlag(flag, value);
}
EXPORT_API bool CALL PxRigidBodyExt_updateMassAndInertia_1(physx_PxRigidBody_Pod* body_pod, float density, physx_PxVec3_Pod const* massLocalPose_pod, bool includeNonSimShapes) {
physx::PxRigidBody& body = reinterpret_cast<physx::PxRigidBody&>(*body_pod);
physx::PxVec3 const* massLocalPose = reinterpret_cast<physx::PxVec3 const*>(massLocalPose_pod);
bool return_val = physx::PxRigidBodyExt::updateMassAndInertia(body, density, massLocalPose, includeNonSimShapes);
return return_val;
}
EXPORT_API void CALL PxRigidBody_setRigidBodyFlag_mut(physx_PxRigidBody_Pod* self__pod, int32_t flag_pod, bool value) {
physx::PxRigidBody* self_ = reinterpret_cast<physx::PxRigidBody*>(self__pod);
auto flag = static_cast<physx::PxRigidBodyFlag::Enum>(flag_pod);
self_->setRigidBodyFlag(flag, value);
}
EXPORT_API void CALL PxShape_setName_mut(physx_PxShape_Pod* self__pod, char const* name) {
physx::PxShape* self_ = reinterpret_cast<physx::PxShape*>(self__pod);
self_->setName(name);
}
EXPORT_API bool CALL PxRigidActor_attachShape_mut(physx_PxRigidActor_Pod* self__pod, physx_PxShape_Pod* shape_pod) {
physx::PxRigidActor* self_ = reinterpret_cast<physx::PxRigidActor*>(self__pod);
physx::PxShape& shape = reinterpret_cast<physx::PxShape&>(*shape_pod);
bool return_val = self_->attachShape(shape);
return return_val;
}
EXPORT_API void CALL PxRigidActor_detachShape_mut(physx_PxRigidActor_Pod* self__pod, physx_PxShape_Pod* shape_pod, bool wakeOnLostTouch) {
physx::PxRigidActor* self_ = reinterpret_cast<physx::PxRigidActor*>(self__pod);
physx::PxShape& shape = reinterpret_cast<physx::PxShape&>(*shape_pod);
self_->detachShape(shape, wakeOnLostTouch);
}
EXPORT_API uint32_t CALL PxRigidActor_getShapes(physx_PxRigidActor_Pod const* self__pod, physx_PxShape_Pod** userBuffer_pod, uint32_t bufferSize, uint32_t startIndex) {
physx::PxRigidActor const* self_ = reinterpret_cast<physx::PxRigidActor const*>(self__pod);
physx::PxShape** userBuffer = reinterpret_cast<physx::PxShape**>(userBuffer_pod);
uint32_t return_val = self_->getShapes(userBuffer, bufferSize, startIndex);
return return_val;
}
EXPORT_API void CALL PxShape_setSimulationFilterData_mut(physx_PxShape_Pod* self__pod, physx_PxFilterData_Pod const* data_pod) {
physx::PxShape* self_ = reinterpret_cast<physx::PxShape*>(self__pod);
physx::PxFilterData const& data = reinterpret_cast<physx::PxFilterData const&>(*data_pod);
self_->setSimulationFilterData(data);
}
EXPORT_API uint32_t CALL PxRigidActor_getNbShapes(physx_PxRigidActor_Pod const* self__pod) {
physx::PxRigidActor const* self_ = reinterpret_cast<physx::PxRigidActor const*>(self__pod);
uint32_t return_val = self_->getNbShapes();
return return_val;
}
EXPORT_API void CALL PxRigidActor_release_mut(physx_PxRigidActor_Pod* self__pod) {
physx::PxRigidActor* self_ = reinterpret_cast<physx::PxRigidActor*>(self__pod);
self_->release();
}
EXPORT_API char const* CALL PxShape_getName(physx_PxShape_Pod const* self__pod) {
physx::PxShape const* self_ = reinterpret_cast<physx::PxShape const*>(self__pod);
char const* return_val = self_->getName();
return return_val;
}
EXPORT_API void CALL PxRigidDynamic_setLinearVelocity_mut(physx_PxRigidDynamic_Pod* self__pod, physx_PxVec3_Pod const* linVel_pod, bool autowake) {
physx::PxRigidDynamic* self_ = reinterpret_cast<physx::PxRigidDynamic*>(self__pod);
physx::PxVec3 const& linVel = reinterpret_cast<physx::PxVec3 const&>(*linVel_pod);
self_->setLinearVelocity(linVel, autowake);
}
EXPORT_API void CALL PxRigidBody_setLinearDamping_mut(physx_PxRigidBody_Pod* self__pod, float linDamp) {
physx::PxRigidBody* self_ = reinterpret_cast<physx::PxRigidBody*>(self__pod);
self_->setLinearDamping(linDamp);
}
EXPORT_API void CALL PxRigidDynamic_setContactReportThreshold_mut(physx_PxRigidDynamic_Pod* self__pod, float threshold) {
physx::PxRigidDynamic* self_ = reinterpret_cast<physx::PxRigidDynamic*>(self__pod);
self_->setContactReportThreshold(threshold);
}
EXPORT_API float CALL PxRigidBody_getLinearDamping(physx_PxRigidBody_Pod const* self__pod) {
physx::PxRigidBody const* self_ = reinterpret_cast<physx::PxRigidBody const*>(self__pod);
float return_val = self_->getLinearDamping();
return return_val;
}
EXPORT_API void CALL PxRigidBody_setAngularDamping_mut(physx_PxRigidBody_Pod* self__pod, float angDamp) {
physx::PxRigidBody* self_ = reinterpret_cast<physx::PxRigidBody*>(self__pod);
self_->setAngularDamping(angDamp);
}
EXPORT_API float CALL PxRigidBody_getAngularDamping(physx_PxRigidBody_Pod const* self__pod) {
physx::PxRigidBody const* self_ = reinterpret_cast<physx::PxRigidBody const*>(self__pod);
float return_val = self_->getAngularDamping();
return return_val;
}
EXPORT_API void CALL PxShape_setFlag_mut(physx_PxShape_Pod* self__pod, int32_t flag_pod, bool value) {
physx::PxShape* self_ = reinterpret_cast<physx::PxShape*>(self__pod);
auto flag = static_cast<physx::PxShapeFlag::Enum>(flag_pod);
self_->setFlag(flag, value);
}
EXPORT_API void CALL PxShape_setFlags_mut(physx_PxShape_Pod* self__pod, uint8_t inFlags_pod) {
physx::PxShape* self_ = reinterpret_cast<physx::PxShape*>(self__pod);
auto inFlags = physx::PxShapeFlags(inFlags_pod);
self_->setFlags(inFlags);
}
EXPORT_API physx_PxVec3_Pod CALL PxVec3_getNormalized(physx_PxVec3_Pod const* self__pod) {
physx::PxVec3 const* self_ = reinterpret_cast<physx::PxVec3 const*>(self__pod);
physx::PxVec3 return_val = self_->getNormalized();
physx_PxVec3_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API bool CALL PxSceneQueryExt_raycastAny(physx_PxScene_Pod const* scene_pod, physx_PxVec3_Pod const* origin_pod, physx_PxVec3_Pod const* unitDir_pod, float distance, physx_PxQueryHit_Pod* hit_pod, physx_PxQueryFilterData_Pod const* filterData_pod, physx_PxQueryFilterCallback_Pod* filterCall_pod, physx_PxQueryCache_Pod const* cache_pod) {
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxVec3 const& origin = reinterpret_cast<physx::PxVec3 const&>(*origin_pod);
physx::PxVec3 const& unitDir = reinterpret_cast<physx::PxVec3 const&>(*unitDir_pod);
physx::PxQueryHit& hit = reinterpret_cast<physx::PxQueryHit&>(*hit_pod);
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
physx::PxQueryCache const* cache = reinterpret_cast<physx::PxQueryCache const*>(cache_pod);
bool return_val = physx::PxSceneQueryExt::raycastAny(scene, origin, unitDir, distance, hit, filterData, filterCall, cache);
return return_val;
}
EXPORT_API bool CALL PxSceneQueryExt_raycastSingle(physx_PxScene_Pod const* scene_pod, physx_PxVec3_Pod const* origin_pod, physx_PxVec3_Pod const* unitDir_pod, float distance, uint16_t outputFlags_pod,
physx_PxRaycastHit_Pod* hit_pod, physx_PxQueryFilterData_Pod const* filterData_pod, physx_PxQueryFilterCallback_Pod* filterCall_pod, physx_PxQueryCache_Pod const* cache_pod)
{
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxVec3 const& origin = reinterpret_cast<physx::PxVec3 const&>(*origin_pod);
physx::PxVec3 const& unitDir = reinterpret_cast<physx::PxVec3 const&>(*unitDir_pod);
auto outputFlags = physx::PxHitFlags(outputFlags_pod);
physx::PxRaycastHit& hit = reinterpret_cast<physx::PxRaycastHit&>(*hit_pod);
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
//physx::PxQueryFilterCallback* filterCall = preFilter1;
physx::PxQueryCache const* cache = reinterpret_cast<physx::PxQueryCache const*>(cache_pod);
bool return_val = physx::PxSceneQueryExt::raycastSingle(scene, origin, unitDir, distance, outputFlags, hit, filterData, filterCall, cache);
return return_val;
}
EXPORT_API int32_t CALL PxSceneQueryExt_raycastMultiple(physx_PxScene_Pod const* scene_pod, physx_PxVec3_Pod const* origin_pod, physx_PxVec3_Pod const* unitDir_pod,
float distance, uint16_t outputFlags_pod, physx_PxRaycastHit_Pod* hitBuffer_pod, uint32_t hitBufferSize, bool* blockingHit_pod,
physx_PxQueryFilterData_Pod const* filterData_pod, physx_PxQueryFilterCallback_Pod* filterCall_pod, physx_PxQueryCache_Pod const* cache_pod)
{
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxVec3 const& origin = reinterpret_cast<physx::PxVec3 const&>(*origin_pod);
physx::PxVec3 const& unitDir = reinterpret_cast<physx::PxVec3 const&>(*unitDir_pod);
auto outputFlags = physx::PxHitFlags(outputFlags_pod);
physx::PxRaycastHit* hitBuffer = reinterpret_cast<physx::PxRaycastHit*>(hitBuffer_pod);
bool& blockingHit = *blockingHit_pod;
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
physx::PxQueryCache const* cache = reinterpret_cast<physx::PxQueryCache const*>(cache_pod);
int32_t return_val = physx::PxSceneQueryExt::raycastMultiple(scene, origin, unitDir, distance, outputFlags, hitBuffer, hitBufferSize, blockingHit, filterData, filterCall, cache);
return return_val;
}
EXPORT_API bool CALL PxSceneQueryExt_sweepAny(physx_PxScene_Pod const* scene_pod, physx_PxGeometry_Pod const* geometry_pod,
physx_PxTransform_Pod const* pose_pod, physx_PxVec3_Pod const* unitDir_pod, float distance, uint16_t queryFlags_pod, physx_PxQueryHit_Pod* hit_pod,
physx_PxQueryFilterData_Pod const* filterData_pod, physx_PxQueryFilterCallback_Pod* filterCall_pod, physx_PxQueryCache_Pod const* cache_pod, float inflation)
{
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const&>(*geometry_pod);
physx::PxTransform const& pose = reinterpret_cast<physx::PxTransform const&>(*pose_pod);
physx::PxVec3 const& unitDir = reinterpret_cast<physx::PxVec3 const&>(*unitDir_pod);
auto queryFlags = physx::PxHitFlags(queryFlags_pod);
physx::PxQueryHit& hit = reinterpret_cast<physx::PxQueryHit&>(*hit_pod);
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
physx::PxQueryCache const* cache = reinterpret_cast<physx::PxQueryCache const*>(cache_pod);
bool return_val = physx::PxSceneQueryExt::sweepAny(scene, geometry, pose, unitDir, distance, queryFlags, hit, filterData, filterCall, cache, inflation);
return return_val;
}
EXPORT_API bool CALL PxSceneQueryExt_sweepSingle(physx_PxScene_Pod const* scene_pod, physx_PxGeometry_Pod const* geometry_pod, physx_PxTransform_Pod const* pose_pod,
physx_PxVec3_Pod const* unitDir_pod, float distance, uint16_t outputFlags_pod, physx_PxSweepHit_Pod* hit_pod, physx_PxQueryFilterData_Pod const* filterData_pod,
physx_PxQueryFilterCallback_Pod* filterCall_pod, physx_PxQueryCache_Pod const* cache_pod, float inflation)
{
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const&>(*geometry_pod);
physx::PxTransform const& pose = reinterpret_cast<physx::PxTransform const&>(*pose_pod);
physx::PxVec3 const& unitDir = reinterpret_cast<physx::PxVec3 const&>(*unitDir_pod);
auto outputFlags = physx::PxHitFlags(outputFlags_pod);
physx::PxSweepHit& hit = reinterpret_cast<physx::PxSweepHit&>(*hit_pod);
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
physx::PxQueryCache const* cache = reinterpret_cast<physx::PxQueryCache const*>(cache_pod);
bool return_val = physx::PxSceneQueryExt::sweepSingle(scene, geometry, pose, unitDir, distance, outputFlags, hit, filterData, filterCall, cache, inflation);
return return_val;
}
EXPORT_API int32_t CALL PxSceneQueryExt_sweepMultiple(physx_PxScene_Pod const* scene_pod, physx_PxGeometry_Pod const* geometry_pod, physx_PxTransform_Pod const* pose_pod,
physx_PxVec3_Pod const* unitDir_pod, float distance, uint16_t outputFlags_pod, physx_PxSweepHit_Pod* hitBuffer_pod, uint32_t hitBufferSize, bool* blockingHit_pod,
physx_PxQueryFilterData_Pod const* filterData_pod, physx_PxQueryFilterCallback_Pod* filterCall_pod, physx_PxQueryCache_Pod const* cache_pod, float inflation)
{
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const&>(*geometry_pod);
physx::PxTransform const& pose = reinterpret_cast<physx::PxTransform const&>(*pose_pod);
physx::PxVec3 const& unitDir = reinterpret_cast<physx::PxVec3 const&>(*unitDir_pod);
auto outputFlags = physx::PxHitFlags(outputFlags_pod);
physx::PxSweepHit* hitBuffer = reinterpret_cast<physx::PxSweepHit*>(hitBuffer_pod);
bool& blockingHit = *blockingHit_pod;
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
physx::PxQueryCache const* cache = reinterpret_cast<physx::PxQueryCache const*>(cache_pod);
int32_t return_val = physx::PxSceneQueryExt::sweepMultiple(scene, geometry, pose, unitDir, distance, outputFlags, hitBuffer, hitBufferSize, blockingHit, filterData, filterCall, cache, inflation);
return return_val;
}
EXPORT_API int32_t CALL PxSceneQueryExt_overlapMultiple(physx_PxScene_Pod const* scene_pod, physx_PxGeometry_Pod const* geometry_pod, physx_PxTransform_Pod const* pose_pod,
physx_PxOverlapHit_Pod* hitBuffer_pod, uint32_t hitBufferSize, physx_PxQueryFilterData_Pod const* filterData_pod, physx_PxQueryFilterCallback_Pod* filterCall_pod)
{
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const&>(*geometry_pod);
physx::PxTransform const& pose = reinterpret_cast<physx::PxTransform const&>(*pose_pod);
physx::PxOverlapHit* hitBuffer = reinterpret_cast<physx::PxOverlapHit*>(hitBuffer_pod);
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
int32_t return_val = physx::PxSceneQueryExt::overlapMultiple(scene, geometry, pose, hitBuffer, hitBufferSize, filterData, filterCall);
return return_val;
}
EXPORT_API bool CALL PxSceneQueryExt_overlapAny(physx_PxScene_Pod const* scene_pod, physx_PxGeometry_Pod const* geometry_pod,
physx_PxTransform_Pod const* pose_pod, physx_PxOverlapHit_Pod* hit_pod, physx_PxQueryFilterData_Pod const* filterData_pod, physx_PxQueryFilterCallback_Pod* filterCall_pod)
{
physx::PxScene const& scene = reinterpret_cast<physx::PxScene const&>(*scene_pod);
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const&>(*geometry_pod);
physx::PxTransform const& pose = reinterpret_cast<physx::PxTransform const&>(*pose_pod);
physx::PxOverlapHit& hit = reinterpret_cast<physx::PxOverlapHit&>(*hit_pod);
physx::PxQueryFilterData const& filterData = reinterpret_cast<physx::PxQueryFilterData const&>(*filterData_pod);
physx::PxQueryFilterCallback* filterCall = reinterpret_cast<physx::PxQueryFilterCallback*>(filterCall_pod);
bool return_val = physx::PxSceneQueryExt::overlapAny(scene, geometry, pose, hit, filterData, filterCall);
return return_val;
}
EXPORT_API physx_PxFilterData_Pod CALL PxFilterData_new(int32_t anon_param0_pod) {
auto anon_param0 = static_cast<physx::PxEMPTY>(anon_param0_pod);
physx::PxFilterData return_val(anon_param0);
physx_PxFilterData_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxFilterData_Pod CALL PxFilterData_new_1() {
physx::PxFilterData return_val;
physx_PxFilterData_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxQueryFilterData_Pod CALL PxQueryFilterData_new() {
physx::PxQueryFilterData return_val;
physx_PxQueryFilterData_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxQueryFilterData_Pod CALL PxQueryFilterData_new_1(physx_PxFilterData_Pod const* fd_pod, uint16_t f_pod) {
physx::PxFilterData const& fd = reinterpret_cast<physx::PxFilterData const&>(*fd_pod);
auto f = physx::PxQueryFlags(f_pod);
physx::PxQueryFilterData return_val(fd, f);
physx_PxQueryFilterData_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxQueryFilterData_Pod CALL PxQueryFilterData_new_2(uint16_t f_pod) {
auto f = physx::PxQueryFlags(f_pod);
physx::PxQueryFilterData return_val(f);
physx_PxQueryFilterData_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API bool CALL PxScene_simulate_mut(physx_PxScene_Pod* self__pod, float elapsedTime, physx_PxBaseTask_Pod* completionTask_pod, void* scratchMemBlock, uint32_t scratchMemBlockSize, bool controlSimulation) {
physx::PxScene* self_ = reinterpret_cast<physx::PxScene*>(self__pod);
physx::PxBaseTask* completionTask = reinterpret_cast<physx::PxBaseTask*>(completionTask_pod);
bool return_val = self_->simulate(elapsedTime, completionTask, scratchMemBlock, scratchMemBlockSize, controlSimulation);
return return_val;
}
EXPORT_API bool CALL PxScene_fetchResults_mut(physx_PxScene_Pod* self__pod, bool block, uint32_t* errorState) {
physx::PxScene* self_ = reinterpret_cast<physx::PxScene*>(self__pod);
bool return_val = self_->fetchResults(block, errorState);
return return_val;
}
EXPORT_API physx_PxPvdSceneClient_Pod* CALL PxScene_getScenePvdClient_mut(physx_PxScene_Pod* self__pod) {
physx::PxScene* self_ = reinterpret_cast<physx::PxScene*>(self__pod);
physx::PxPvdSceneClient* return_val = self_->getScenePvdClient();
auto return_val_pod = reinterpret_cast<physx_PxPvdSceneClient_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API physx_PxPlane_Pod CALL PxPlane_new_1(float nx, float ny, float nz, float distance) {
physx::PxPlane return_val(nx, ny, nz, distance);
physx_PxPlane_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxRigidStatic_Pod* CALL phys_PxCreatePlane(physx_PxPhysics_Pod* sdk_pod, physx_PxPlane_Pod const* plane_pod, physx_PxMaterial_Pod* material_pod) {
physx::PxPhysics& sdk = reinterpret_cast<physx::PxPhysics&>(*sdk_pod);
physx::PxPlane const& plane = reinterpret_cast<physx::PxPlane const&>(*plane_pod);
physx::PxMaterial& material = reinterpret_cast<physx::PxMaterial&>(*material_pod);
physx::PxRigidStatic* return_val = PxCreatePlane(sdk, plane, material);
auto return_val_pod = reinterpret_cast<physx_PxRigidStatic_Pod*>(return_val);
return return_val_pod;
}
EXPORT_API void CALL PxPvdSceneClient_setScenePvdFlag_mut(physx_PxPvdSceneClient_Pod* self__pod, int32_t flag_pod, bool value) {
physx::PxPvdSceneClient* self_ = reinterpret_cast<physx::PxPvdSceneClient*>(self__pod);
auto flag = static_cast<physx::PxPvdSceneFlag::Enum>(flag_pod);
self_->setScenePvdFlag(flag, value);
}
EXPORT_API physx_PxQuat_Pod CALL PxQuat_new() {
physx::PxQuat return_val;
physx_PxQuat_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxQuat_Pod CALL PxQuat_new_1(int32_t anon_param0_pod) {
auto anon_param0 = static_cast<physx::PxIDENTITY>(anon_param0_pod);
physx::PxQuat return_val(anon_param0);
physx_PxQuat_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxQuat_Pod CALL PxQuat_new_2(float r) {
physx::PxQuat return_val(r);
physx_PxQuat_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxQuat_Pod CALL PxQuat_new_3(float nx, float ny, float nz, float nw) {
physx::PxQuat return_val(nx, ny, nz, nw);
physx_PxQuat_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxQuat_Pod CALL PxQuat_new_4(float angleRadians, physx_PxVec3_Pod const* unitAxis_pod) {
physx::PxVec3 const& unitAxis = reinterpret_cast<physx::PxVec3 const&>(*unitAxis_pod);
physx::PxQuat return_val(angleRadians, unitAxis);
physx_PxQuat_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxTolerancesScale_Pod CALL PxTolerancesScale_new(float defaultLength, float defaultSpeed) {
physx::PxTolerancesScale return_val(defaultLength, defaultSpeed);
physx_PxTolerancesScale_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
//EXPORT_API bool CALL phys_PxInitExtensions(physx_PxPhysics_Pod* physics_pod, physx_PxPvd_Pod* pvd_pod) {
// physx::PxPhysics& physics = reinterpret_cast<physx::PxPhysics&>(*physics_pod);
// physx::PxPvd* pvd = reinterpret_cast<physx::PxPvd*>(pvd_pod);
// bool return_val = PxInitExtensions(physics, pvd);
// return return_val;
//}
//EXPORT_API void CALL phys_PxCloseExtensions() {
// PxCloseExtensions();
//}
////¹¤¾ßº¯Êý
EXPORT_API physx_PxVec3_Pod CALL PxVec3_new() {
physx::PxVec3 return_val;
physx_PxVec3_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxVec3_Pod CALL PxVec3_new_1(int32_t anon_param0_pod) {
auto anon_param0 = static_cast<physx::PxZERO>(anon_param0_pod);
physx::PxVec3 return_val(anon_param0);
physx_PxVec3_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxVec3_Pod CALL PxVec3_new_2(float a) {
physx::PxVec3 return_val(a);
physx_PxVec3_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxVec3_Pod CALL PxVec3_new_3(float nx, float ny, float nz) {
physx::PxVec3 return_val(nx, ny, nz);
physx_PxVec3_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API bool CALL PxVec3_isZero(physx_PxVec3_Pod const* self__pod) {
physx::PxVec3 const* self_ = reinterpret_cast<physx::PxVec3 const*>(self__pod);
bool return_val = self_->isZero();
return return_val;
}
EXPORT_API bool CALL PxVec3_isFinite(physx_PxVec3_Pod const* self__pod) {
physx::PxVec3 const* self_ = reinterpret_cast<physx::PxVec3 const*>(self__pod);
bool return_val = self_->isFinite();
return return_val;
}
EXPORT_API bool CALL PxVec3_isNormalized(physx_PxVec3_Pod const* self__pod) {
physx::PxVec3 const* self_ = reinterpret_cast<physx::PxVec3 const*>(self__pod);
bool return_val = self_->isNormalized();
return return_val;
}
EXPORT_API float CALL PxVec3_magnitudeSquared(physx_PxVec3_Pod const* self__pod) {
physx::PxVec3 const* self_ = reinterpret_cast<physx::PxVec3 const*>(self__pod);
float return_val = self_->magnitudeSquared();
return return_val;
}
EXPORT_API float CALL PxVec3_magnitude(physx_PxVec3_Pod const* self__pod) {
physx::PxVec3 const* self_ = reinterpret_cast<physx::PxVec3 const*>(self__pod);
float return_val = self_->magnitude();
return return_val;
}
EXPORT_API bool CALL phys_PxFilterObjectIsTrigger(uint32_t attr) {
bool return_val = physx::PxFilterObjectIsTrigger(attr);
return return_val;
}
//»Øµ÷º¯Êý²¿·ÖµÄʵÏÖ
struct FilterShaderCallbackInfo
{
physx::PxFilterObjectAttributes attributes0;
physx::PxFilterObjectAttributes attributes1;
physx::PxFilterData filterData0;
physx::PxFilterData filterData1;
physx::PxPairFlags* pairFlags;
const void* constantBlock;
physx::PxU32 constantBlockSize;
};
typedef void (*CollisionCallback)(void*, physx::PxContactPairHeader const*, physx::PxContactPair const*, physx::PxU32);
typedef physx::PxU16(*SimulationShaderFilter)(FilterShaderCallbackInfo*);
struct FilterCallbackData {
SimulationShaderFilter filter;
bool call_default_filter_shader_first;
};
EXPORT_API physx::PxFilterFlags CALL FilterShaderTrampoline(physx::PxFilterObjectAttributes attributes0,
physx::PxFilterData filterData0,
physx::PxFilterObjectAttributes attributes1,
physx::PxFilterData filterData1,
physx::PxPairFlags& pairFlags,
const void* constantBlock,
physx::PxU32 constantBlockSize)
{
const FilterCallbackData* data = static_cast<const FilterCallbackData*>(constantBlock);
if (data->call_default_filter_shader_first) {
// Let the default handler set the pair flags, but ignore the collision filtering
return PxDefaultSimulationFilterShader(attributes0, filterData0, attributes1, filterData1, pairFlags, constantBlock,
constantBlockSize);
}
// Get the filter shader from the constant block
SimulationShaderFilter shaderfilter = data->filter;
// This is a bit expensive since we're putting things on the stack but with LTO this should optimize OK,
// and I was having issues with corrupted values when passing by value
FilterShaderCallbackInfo info{ attributes0, attributes1, filterData0, filterData1, &pairFlags, nullptr, 0 };
// We return a u16 since PxFilterFlags is a complex type and C++ wants it to be returned on the stack,
// but Rust thinks it's simple due to the codegen and wants to return it in EAX.
//pairFlags = physx::PxPairFlag::eSOLVE_CONTACT |
// physx::PxPairFlag::eDETECT_DISCRETE_CONTACT |
// physx::PxPairFlag::eNOTIFY_TOUCH_FOUND |
// physx::PxPairFlag::eNOTIFY_TOUCH_LOST |
// physx::PxPairFlag::eNOTIFY_CONTACT_POINTS;
//return (physx::PxFilterFlags)0x4;
//printf("%d ");
return physx::PxFilterFlags{ shaderfilter(&info) };
}
using PairFoundCallback = physx::PxFilterFlags(*)(physx::PxU32, physx::PxFilterObjectAttributes, physx::PxFilterData, const physx::PxActor*, const physx::PxShape*,
physx::PxFilterObjectAttributes, physx::PxFilterData, const physx::PxActor*, const physx::PxShape*, physx::PxPairFlags*);
using PairLostCallback = void (*)(physx::PxU32, physx::PxFilterObjectAttributes, physx::PxFilterData, physx::PxFilterObjectAttributes, physx::PxFilterData, bool);
using StatusChangeCallback = bool (*)(physx::PxU32*, physx::PxPairFlags*, physx::PxFilterFlags*);
struct SimuliationFilterCallBackInfo {
// Callback for pairFound
PairFoundCallback pairFoundCallback = nullptr;
PairLostCallback pairLostCallback = nullptr;
StatusChangeCallback statusChangeCallback = nullptr;
};
//
//
class SimulationFilterCallBackTrampoline : public physx::PxSimulationFilterCallback
{
public:
SimulationFilterCallBackTrampoline(const SimuliationFilterCallBackInfo* callbacks) : mCallbacks(*callbacks) {}
// Collisions
//¶þ¼¶´«µÝÒýÓÃÐèÒª´«µÝÍòÄÜÒýÓà ¿ÉÄÜ´æÔÚbug
physx::PxFilterFlags pairFound(physx::PxU32 pairID,
physx::PxFilterObjectAttributes attributes0, physx::PxFilterData filterData0, const physx::PxActor* a0, const physx::PxShape* s0,
physx::PxFilterObjectAttributes attributes1, physx::PxFilterData filterData1, const physx::PxActor* a1, const physx::PxShape* s1,
physx::PxPairFlags& pairFlags)
{
if (mCallbacks.pairFoundCallback) {
return mCallbacks.pairFoundCallback(pairID,
attributes0, filterData0, a0, s0,
attributes1, filterData1, a1, s1,
&pairFlags);
}
else{
return physx::PxFilterFlag::eDEFAULT;
}
}
// Triggers
void pairLost(physx::PxU32 pairID,
physx::PxFilterObjectAttributes attributes0, physx::PxFilterData filterData0,
physx::PxFilterObjectAttributes attributes1, physx::PxFilterData filterData1,
bool objectRemoved)
{
if (mCallbacks.pairLostCallback) {
mCallbacks.pairLostCallback(pairID, attributes0, filterData0,
attributes1, filterData1, objectRemoved);
}
else
{
return;
}
}
// Constraint breaks
bool statusChange(physx::PxU32& pairID, physx::PxPairFlags& pairFlags, physx::PxFilterFlags& filterFlags)
{
if (mCallbacks.statusChangeCallback) {
return mCallbacks.statusChangeCallback(&pairID, &pairFlags, &filterFlags);
}
else
{
return false;
}
}
SimuliationFilterCallBackInfo mCallbacks;
};
//
//
//
using CollisionCallback = void (*)(void*, physx::PxContactPairHeader const*, physx::PxContactPair const*, physx::PxU32);
using TriggerCallback = void (*)(void*, physx::PxTriggerPair const*, physx::PxU32);
using ConstraintBreakCallback = void (*)(void*, physx::PxConstraintInfo const*, physx::PxU32);
using WakeSleepCallback = void (*)(void*, physx::PxActor** const, physx::PxU32, bool);
using AdvanceCallback = void (*)(void*, const physx::PxRigidBody* const*, const physx::PxTransform* const, physx::PxU32);
//
//
struct SimulationEventCallbackInfo {
// Callback for collision events.
CollisionCallback collisionCallback = nullptr;
void* collisionUserData = nullptr;
// Callback for trigger shape events (an object entered or left a trigger shape).
TriggerCallback triggerCallback = nullptr;
void* triggerUserData = nullptr;
// Callback for when a constraint breaks (such as a joint with a force limit)
ConstraintBreakCallback constraintBreakCallback = nullptr;
void* constraintBreakUserData = nullptr;
// Callback for when an object falls asleep or is awoken.
WakeSleepCallback wakeSleepCallback = nullptr;
void* wakeSleepUserData = nullptr;
// Callback to get the next pose early for objects (if flagged with eENABLE_POSE_INTEGRATION_PREVIEW).
AdvanceCallback advanceCallback = nullptr;
void* advanceUserData = nullptr;
};
//
//
//
class SimulationEventTrampoline : public physx::PxSimulationEventCallback
{
public:
SimulationEventTrampoline(const SimulationEventCallbackInfo* callbacks) : mCallbacks(*callbacks) {}
// Collisions
void onContact(const physx::PxContactPairHeader& pairHeader, const physx::PxContactPair* pairs, physx::PxU32 nbPairs) override {
if (mCallbacks.collisionCallback) {
mCallbacks.collisionCallback(mCallbacks.collisionUserData, &pairHeader, pairs, nbPairs);
}
else{
return;
}
}
// Triggers
void onTrigger(physx::PxTriggerPair* pairs, physx::PxU32 count) override {
if (mCallbacks.triggerCallback) {
mCallbacks.triggerCallback(mCallbacks.triggerUserData, pairs, count);
}
else {
return;
}
}
// Constraint breaks
void onConstraintBreak(physx::PxConstraintInfo* constraints, physx::PxU32 count) override {
if (mCallbacks.constraintBreakCallback) {
mCallbacks.constraintBreakCallback(mCallbacks.constraintBreakUserData, constraints, count);
}
else {
return;
}
}
// Wake/Sleep (combined for convenience)
void onWake(physx::PxActor** actors, physx::PxU32 count) override {
if (mCallbacks.wakeSleepCallback) {
mCallbacks.wakeSleepCallback(mCallbacks.wakeSleepUserData, actors, count, true);
}
else {
return;
}
}
void onSleep(physx::PxActor** actors, physx::PxU32 count) override {
if (mCallbacks.wakeSleepCallback) {
mCallbacks.wakeSleepCallback(mCallbacks.wakeSleepUserData, actors, count, false);
}
else {
return;
}
}
// Advance
void onAdvance(const physx::PxRigidBody* const* bodyBuffer, const physx::PxTransform* poseBuffer, const physx::PxU32 count) override {
if (mCallbacks.advanceCallback) {
mCallbacks.advanceCallback(mCallbacks.advanceUserData, bodyBuffer, poseBuffer, count);
}
else {
return;
}
}
SimulationEventCallbackInfo mCallbacks;
};
//
class RaycastFilterCallback : public physx::PxQueryFilterCallback
{
public:
explicit RaycastFilterCallback(physx::PxRigidActor* actor) : mActor(actor) {}
physx::PxRigidActor* mActor;
virtual physx::PxQueryHitType::Enum preFilter(const physx::PxFilterData&, const physx::PxShape* shape,
const physx::PxRigidActor* actor, physx::PxHitFlags&)
{
if (mActor == actor)
{
return physx::PxQueryHitType::eNONE;
}
else
{
return physx::PxQueryHitType::eBLOCK;
}
}
virtual physx::PxQueryHitType::Enum postFilter(const physx::PxFilterData& filterData, const physx::PxQueryHit& hit, const physx::PxShape* shape,
const physx::PxRigidActor* actor)
{
return physx::PxQueryHitType::eNONE;
}
};
typedef physx::PxQueryHitType::Enum(*RaycastHitCallback)(const physx::PxRigidActor* actor, const physx::PxFilterData* filterData, const physx::PxShape* shape, physx::PxU32 hitFlags, const void* userData);
typedef physx::PxQueryHitType::Enum(*PostFilterCallback)(const physx::PxFilterData* filterData, const physx::PxQueryHit* hit, const void* userData);
physx::PxQueryHitType::Enum sanitize_hit_type(uint32_t hit_type) {
switch (hit_type) {
case physx::PxQueryHitType::eNONE:
case physx::PxQueryHitType::eTOUCH:
case physx::PxQueryHitType::eBLOCK: return (physx::PxQueryHitType::Enum)hit_type;
default: return physx::PxQueryHitType::eNONE;
}
}
//
class RaycastFilterTrampoline : public physx::PxQueryFilterCallback
{
public:
RaycastFilterTrampoline(RaycastHitCallback callback, const void* userdata)
: mCallback(callback), mUserData(userdata) {}
RaycastHitCallback mCallback;
const void* mUserData;
virtual physx::PxQueryHitType::Enum preFilter(const physx::PxFilterData& filterData, const physx::PxShape* shape, const physx::PxRigidActor* actor, physx::PxHitFlags& hitFlags)
{
return sanitize_hit_type(mCallback(actor, &filterData, shape, (uint32_t)hitFlags, mUserData));
}
virtual physx::PxQueryHitType::Enum postFilter(const physx::PxFilterData& filterData, const physx::PxQueryHit& hit,
const physx::PxShape* shape, const physx::PxRigidActor* actor)
{
return physx::PxQueryHitType::eNONE;
}
};
//
//
class RaycastFilterPrePostTrampoline : public physx::PxQueryFilterCallback
{
public:
RaycastFilterPrePostTrampoline(RaycastHitCallback preFilter, PostFilterCallback postFilter, const void* userdata)
: mPreFilter(preFilter), mPostFilter(postFilter), mUserData(userdata) {}
RaycastHitCallback mPreFilter;
PostFilterCallback mPostFilter;
const void* mUserData;
virtual physx::PxQueryHitType::Enum preFilter(const physx::PxFilterData& filterData, const physx::PxShape* shape, const physx::PxRigidActor* actor, physx::PxHitFlags& hitFlags)
{
if (mPreFilter == nullptr)
{
return physx::PxQueryHitType::eNONE;
}
return sanitize_hit_type(mPreFilter(actor, &filterData, shape, (uint32_t)hitFlags, mUserData));
}
virtual physx::PxQueryHitType::Enum postFilter(const physx::PxFilterData& filterData, const physx::PxQueryHit& hit,
const physx::PxShape* shape, const physx::PxRigidActor* actor)
{
if (mPostFilter == nullptr)
{
return physx::PxQueryHitType::eNONE;
}
return sanitize_hit_type(mPostFilter(&filterData, &hit, mUserData));
}
};
typedef physx::PxAgain(*RaycastHitProcessTouchesCallback)(const physx::PxRaycastHit* buffer, physx::PxU32 nbHits, void* userdata);
typedef physx::PxAgain(*SweepHitProcessTouchesCallback)(const physx::PxSweepHit* buffer, physx::PxU32 nbHits, void* userdata);
typedef physx::PxAgain(*OverlapHitProcessTouchesCallback)(const physx::PxOverlapHit* buffer, physx::PxU32 nbHits, void* userdata);
typedef void (*HitFinalizeQueryCallback)(void* userdata);
//
class RaycastHitCallbackTrampoline : public physx::PxRaycastCallback
{
public:
RaycastHitCallbackTrampoline(
RaycastHitProcessTouchesCallback processTouchesCallback,
HitFinalizeQueryCallback finalizeQueryCallback,
physx::PxRaycastHit* touchesBuffer,
physx::PxU32 numTouches,
void* userdata)
: physx::PxRaycastCallback(touchesBuffer, numTouches),
mProcessTouchesCallback(processTouchesCallback),
mFinalizeQueryCallback(finalizeQueryCallback),
mUserData(userdata) {}
RaycastHitProcessTouchesCallback mProcessTouchesCallback;
HitFinalizeQueryCallback mFinalizeQueryCallback;
void* mUserData;
physx::PxAgain processTouches(const physx::PxRaycastHit* buffer, physx::PxU32 nbHits) override
{
return mProcessTouchesCallback(buffer, nbHits, mUserData);
}
void finalizeQuery() override
{
mFinalizeQueryCallback(mUserData);
}
};
//
class SweepHitCallbackTrampoline : public physx::PxSweepCallback
{
public:
SweepHitCallbackTrampoline(
SweepHitProcessTouchesCallback processTouchesCallback,
HitFinalizeQueryCallback finalizeQueryCallback,
physx::PxSweepHit* touchesBuffer,
physx::PxU32 numTouches,
void* userdata)
: physx::PxSweepCallback(touchesBuffer, numTouches),
mProcessTouchesCallback(processTouchesCallback),
mFinalizeQueryCallback(finalizeQueryCallback),
mUserData(userdata) {}
SweepHitProcessTouchesCallback mProcessTouchesCallback;
HitFinalizeQueryCallback mFinalizeQueryCallback;
void* mUserData;
physx::PxAgain processTouches(const physx::PxSweepHit* buffer, physx::PxU32 nbHits) override
{
return mProcessTouchesCallback(buffer, nbHits, mUserData);
}
void finalizeQuery() override
{
mFinalizeQueryCallback(mUserData);
}
};
//
class OverlapHitCallbackTrampoline : public physx::PxOverlapCallback
{
public:
OverlapHitCallbackTrampoline(
OverlapHitProcessTouchesCallback processTouchesCallback,
HitFinalizeQueryCallback finalizeQueryCallback,
physx::PxOverlapHit* touchesBuffer,
physx::PxU32 numTouches,
void* userdata)
: physx::PxOverlapCallback(touchesBuffer, numTouches),
mProcessTouchesCallback(processTouchesCallback),
mFinalizeQueryCallback(finalizeQueryCallback),
mUserData(userdata) {}
OverlapHitProcessTouchesCallback mProcessTouchesCallback;
HitFinalizeQueryCallback mFinalizeQueryCallback;
void* mUserData;
physx::PxAgain processTouches(const physx::PxOverlapHit* buffer, physx::PxU32 nbHits) override
{
return mProcessTouchesCallback(buffer, nbHits, mUserData);
}
void finalizeQuery() override
{
mFinalizeQueryCallback(mUserData);
}
};
typedef void* (*AllocCallback)(uint64_t size, const char* typeName, const char* filename, int line, void* userdata);
typedef void (*DeallocCallback)(void* ptr, void* userdata);
class CustomAllocatorTrampoline : public physx::PxAllocatorCallback {
public:
CustomAllocatorTrampoline(AllocCallback allocCb, DeallocCallback deallocCb, void* userdata)
: mAllocCallback(allocCb), mDeallocCallback(deallocCb), mUserData(userdata) {}
void* allocate(size_t size, const char* typeName, const char* filename, int line)
{
return mAllocCallback((uint64_t)size, typeName, filename, line, mUserData);
}
virtual void deallocate(void* ptr)
{
mDeallocCallback(ptr, mUserData);
}
private:
AllocCallback mAllocCallback;
DeallocCallback mDeallocCallback;
public:
void* mUserData;
};
typedef void* (*ZoneStartCallback)(const char* typeName, bool detached, uint64_t context, void* userdata);
typedef void (*ZoneEndCallback)(void* profilerData, const char* typeName, bool detached, uint64_t context, void* userdata);
class CustomProfilerTrampoline : public physx::PxProfilerCallback {
public:
CustomProfilerTrampoline(ZoneStartCallback startCb, ZoneEndCallback endCb, void* userdata)
: mStartCallback(startCb), mEndCallback(endCb), mUserData(userdata) {
}
virtual void* zoneStart(const char* eventName, bool detached, uint64_t contextId) override
{
return mStartCallback(eventName, detached, contextId, mUserData);
}
virtual void zoneEnd(void* profilerData, const char* eventName, bool detached, uint64_t contextId) override
{
return mEndCallback(profilerData, eventName, detached, contextId, mUserData);
}
private:
ZoneStartCallback mStartCallback;
ZoneEndCallback mEndCallback;
public:
void* mUserData;
};
using ErrorCallback = void (*)(int code, const char* message, const char* file, int line, void* userdata);
class ErrorTrampoline : public physx::PxErrorCallback {
public:
ErrorTrampoline(ErrorCallback errorCb, void* userdata)
: mErrorCallback(errorCb), mUserdata(userdata)
{}
void reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line) override {
mErrorCallback(code, message, file, line, mUserdata);
}
private:
ErrorCallback mErrorCallback = nullptr;
void* mUserdata = nullptr;
};
//using AssertHandler = void (*)(const char* expr, const char* file, int line, bool* should_ignore, void* userdata);
//class AssertTrampoline : public physx::PxAssertHandler {
//public:
// AssertTrampoline(AssertHandler onAssert, void* userdata)
// : mAssertHandler(onAssert), mUserdata(userdata)
// {}
//
// virtual void operator()(const char* exp, const char* file, int line, bool& ignore) override final {
// mAssertHandler(exp, file, line, &ignore, mUserdata);
// }
//
//private:
// AssertHandler mAssertHandler = nullptr;
// void* mUserdata = nullptr;
//};
// fixme[tolsson]: this might be iffy on Windows with DLLs if we have multiple packages
// linking against the raw interface
//physx::PxErrorCallback* get_default_error_callback()
//{
// return &gErrorCallback;
//}
EXPORT_API physx::PxQueryFilterCallback* CALL create_raycast_filter_callback(physx::PxRigidActor* actor_to_ignore)
{
return new RaycastFilterCallback(actor_to_ignore);
}
EXPORT_API physx::PxQueryFilterCallback* CALL create_raycast_filter_callback_func(RaycastHitCallback callback, void* userData)
{
return new RaycastFilterTrampoline(callback, userData);
}
EXPORT_API physx::PxQueryFilterCallback* CALL create_pre_and_post_raycast_filter_callback_func(RaycastHitCallback preFilter, PostFilterCallback postFilter, void* userData)
{
return new RaycastFilterPrePostTrampoline(preFilter, postFilter, userData);
}
EXPORT_API physx::PxRaycastCallback* create_raycast_callback(
RaycastHitProcessTouchesCallback process_touches_callback,
HitFinalizeQueryCallback finalize_query_callback,
physx::PxRaycastHit* touchesBuffer,
physx::PxU32 numTouches,
void* userdata )
{
return new RaycastHitCallbackTrampoline(
process_touches_callback, finalize_query_callback, touchesBuffer, numTouches, userdata);
}
EXPORT_API void CALL delete_raycast_callback(physx::PxRaycastCallback* callback)
{
delete callback;
}
EXPORT_API void CALL delete_sweep_callback(physx::PxSweepCallback* callback)
{
delete callback;
}
EXPORT_API void CALL delete_overlap_callback(physx::PxOverlapCallback* callback)
{
delete callback;
}
EXPORT_API physx::PxSweepCallback* CALL create_sweep_callback(
SweepHitProcessTouchesCallback process_touches_callback,
HitFinalizeQueryCallback finalize_query_callback,
physx::PxSweepHit* touchesBuffer,
physx::PxU32 numTouches,
void* userdata )
{
return new SweepHitCallbackTrampoline(
process_touches_callback, finalize_query_callback, touchesBuffer, numTouches, userdata
);
}
EXPORT_API physx::PxOverlapCallback* CALL create_overlap_callback(
OverlapHitProcessTouchesCallback process_touches_callback,
HitFinalizeQueryCallback finalize_query_callback,
physx::PxOverlapHit* touchesBuffer,
physx::PxU32 numTouches,
void* userdata)
{
return new OverlapHitCallbackTrampoline(
process_touches_callback, finalize_query_callback, touchesBuffer, numTouches, userdata
);
}
EXPORT_API physx::PxAllocatorCallback* CALL create_alloc_callback(
AllocCallback alloc_callback,
DeallocCallback dealloc_callback,
void* userdata)
{
return new CustomAllocatorTrampoline(alloc_callback, dealloc_callback, userdata);
}
void* CALL get_alloc_callback_user_data(physx::PxAllocatorCallback* allocator) {
CustomAllocatorTrampoline* trampoline = static_cast<CustomAllocatorTrampoline*>(allocator);
return trampoline->mUserData;
}
EXPORT_API physx::PxProfilerCallback* CALL create_profiler_callback(
ZoneStartCallback zone_start_callback,
ZoneEndCallback zone_end_callback,
void* userdata)
{
return new CustomProfilerTrampoline(zone_start_callback, zone_end_callback, userdata);
}
EXPORT_API physx::PxErrorCallback* CALL create_error_callback(
ErrorCallback error_callback,
void* userdata)
{
return new ErrorTrampoline(error_callback, userdata);
}
//physx::PxAssertHandler* create_assert_handler( AssertHandler on_assert,void* userdata )
//{
// return new AssertTrampoline(on_assert, userdata);
//}
EXPORT_API void* CALL get_default_simulation_filter_shader()
{
return (void*)physx::PxDefaultSimulationFilterShader;
}
EXPORT_API physx::PxSimulationFilterCallback* CALL create_simulation_filter_callbacks(const SimuliationFilterCallBackInfo* callbacks)
{
SimulationFilterCallBackTrampoline* trampoline = new SimulationFilterCallBackTrampoline(callbacks);
return static_cast<physx::PxSimulationFilterCallback*>(trampoline);
}
EXPORT_API void CALL destroy_simulation_filter_callbacks(physx::PxSimulationFilterCallback* callback)
{
SimulationFilterCallBackTrampoline* trampoline = static_cast<SimulationFilterCallBackTrampoline*>(callback);
delete trampoline;
}
EXPORT_API physx::PxSimulationEventCallback* CALL create_simulation_event_callbacks(const SimulationEventCallbackInfo* callbacks)
{
SimulationEventTrampoline* trampoline = new SimulationEventTrampoline(callbacks);
return static_cast<physx::PxSimulationEventCallback*>(trampoline);
}
EXPORT_API SimulationEventCallbackInfo* CALL get_simulation_event_info(physx::PxSimulationEventCallback* callback)
{
SimulationEventTrampoline* trampoline = static_cast<SimulationEventTrampoline*>(callback);
return &trampoline->mCallbacks;
}
EXPORT_API void CALL destroy_simulation_event_callbacks(physx::PxSimulationEventCallback* callback)
{
SimulationEventTrampoline* trampoline = static_cast<SimulationEventTrampoline*>(callback);
delete trampoline;
}
EXPORT_API void CALL enable_custom_filter_shader(physx::PxSceneDesc* desc, SimulationShaderFilter filter, uint32_t call_default_filter_shader_first)
{
/* Note: This is a workaround to PhysX copying the filter data */
static FilterCallbackData filterShaderData = {
filter,
call_default_filter_shader_first != 0
};
desc->filterShader = FilterShaderTrampoline;
// printf("Setting pointer to %p\n", filter);
desc->filterShaderData = (void*)&filterShaderData;
desc->filterShaderDataSize = sizeof(FilterCallbackData);
}
EXPORT_API int32_t CALL PxGeometryHolder_getType(physx_PxGeometryHolder_Pod const* self__pod) {
physx::PxGeometryHolder const* self_ = reinterpret_cast<physx::PxGeometryHolder const*>(self__pod);
physx::PxGeometryType::Enum return_val = self_->getType();
int32_t return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxGeometry_Pod* CALL PxGeometryHolder_any_mut(physx_PxGeometryHolder_Pod* self__pod) {
physx::PxGeometryHolder* self_ = reinterpret_cast<physx::PxGeometryHolder*>(self__pod);
physx::PxGeometry& return_val = self_->any();
auto return_val_pod = reinterpret_cast<physx_PxGeometry_Pod*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxGeometry_Pod const* CALL PxGeometryHolder_any(physx_PxGeometryHolder_Pod const* self__pod) {
physx::PxGeometryHolder const* self_ = reinterpret_cast<physx::PxGeometryHolder const*>(self__pod);
physx::PxGeometry const& return_val = self_->any();
auto return_val_pod = reinterpret_cast<physx_PxGeometry_Pod const*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxSphereGeometry_Pod* CALL PxGeometryHolder_sphere_mut(physx_PxGeometryHolder_Pod* self__pod) {
physx::PxGeometryHolder* self_ = reinterpret_cast<physx::PxGeometryHolder*>(self__pod);
physx::PxSphereGeometry& return_val = self_->sphere();
auto return_val_pod = reinterpret_cast<physx_PxSphereGeometry_Pod*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxSphereGeometry_Pod const* CALL PxGeometryHolder_sphere(physx_PxGeometryHolder_Pod const* self__pod) {
physx::PxGeometryHolder const* self_ = reinterpret_cast<physx::PxGeometryHolder const*>(self__pod);
physx::PxSphereGeometry const& return_val = self_->sphere();
auto return_val_pod = reinterpret_cast<physx_PxSphereGeometry_Pod const*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxPlaneGeometry_Pod* CALL PxGeometryHolder_plane_mut(physx_PxGeometryHolder_Pod* self__pod) {
physx::PxGeometryHolder* self_ = reinterpret_cast<physx::PxGeometryHolder*>(self__pod);
physx::PxPlaneGeometry& return_val = self_->plane();
auto return_val_pod = reinterpret_cast<physx_PxPlaneGeometry_Pod*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxPlaneGeometry_Pod const* CALL PxGeometryHolder_plane(physx_PxGeometryHolder_Pod const* self__pod) {
physx::PxGeometryHolder const* self_ = reinterpret_cast<physx::PxGeometryHolder const*>(self__pod);
physx::PxPlaneGeometry const& return_val = self_->plane();
auto return_val_pod = reinterpret_cast<physx_PxPlaneGeometry_Pod const*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxCapsuleGeometry_Pod* CALL PxGeometryHolder_capsule_mut(physx_PxGeometryHolder_Pod* self__pod) {
physx::PxGeometryHolder* self_ = reinterpret_cast<physx::PxGeometryHolder*>(self__pod);
physx::PxCapsuleGeometry& return_val = self_->capsule();
auto return_val_pod = reinterpret_cast<physx_PxCapsuleGeometry_Pod*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxCapsuleGeometry_Pod const* CALL PxGeometryHolder_capsule(physx_PxGeometryHolder_Pod const* self__pod) {
physx::PxGeometryHolder const* self_ = reinterpret_cast<physx::PxGeometryHolder const*>(self__pod);
physx::PxCapsuleGeometry const& return_val = self_->capsule();
auto return_val_pod = reinterpret_cast<physx_PxCapsuleGeometry_Pod const*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxBoxGeometry_Pod* CALL PxGeometryHolder_box_mut(physx_PxGeometryHolder_Pod* self__pod) {
physx::PxGeometryHolder* self_ = reinterpret_cast<physx::PxGeometryHolder*>(self__pod);
physx::PxBoxGeometry& return_val = self_->box();
auto return_val_pod = reinterpret_cast<physx_PxBoxGeometry_Pod*>(&return_val);
return return_val_pod;
}
EXPORT_API physx_PxBoxGeometry_Pod const* CALL PxGeometryHolder_box(physx_PxGeometryHolder_Pod const* self__pod) {
physx::PxGeometryHolder const* self_ = reinterpret_cast<physx::PxGeometryHolder const*>(self__pod);
physx::PxBoxGeometry const& return_val = self_->box();
auto return_val_pod = reinterpret_cast<physx_PxBoxGeometry_Pod const*>(&return_val);
return return_val_pod;
}
EXPORT_API void CALL PxGeometryHolder_storeAny_mut(physx_PxGeometryHolder_Pod* self__pod, physx_PxGeometry_Pod const* geometry_pod) {
physx::PxGeometryHolder* self_ = reinterpret_cast<physx::PxGeometryHolder*>(self__pod);
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const&>(*geometry_pod);
self_->storeAny(geometry);
}
EXPORT_API physx_PxGeometryHolder_Pod CALL PxGeometryHolder_new() {
physx::PxGeometryHolder return_val;
physx_PxGeometryHolder_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
EXPORT_API physx_PxGeometryHolder_Pod CALL PxGeometryHolder_new_1(physx_PxGeometry_Pod const* geometry_pod) {
physx::PxGeometry const& geometry = reinterpret_cast<physx::PxGeometry const&>(*geometry_pod);
physx::PxGeometryHolder return_val(geometry);
physx_PxGeometryHolder_Pod return_val_pod;
memcpy(&return_val_pod, &return_val, sizeof(return_val_pod));
return return_val_pod;
}
}