329 lines
12 KiB
C++
329 lines
12 KiB
C++
#include <stdio.h>
|
||
#include"physxApi.hpp"
|
||
|
||
|
||
//void (*)(void*, physx::PxTriggerPair const*, physx::PxU32);
|
||
static void onTrigger(void* userData, physx::PxTriggerPair* pairs, physx::PxU32 count)
|
||
{
|
||
//userdataaaa* data = (userdataaaa*)userData;
|
||
//int a = data->value;
|
||
int a = 0;
|
||
}
|
||
|
||
//void (*)(void*, physx::PxContactPairHeader const*, physx::PxContactPair const*, physx::PxU32);
|
||
static void onContact(void* userData, physx::PxContactPairHeader const * pairHeader, physx::PxContactPair const* pairs, physx::PxU32 nbPairs)
|
||
{
|
||
//userdataaaa* data = (userdataaaa*)userData;
|
||
//int a = data->value;
|
||
int a = 0;
|
||
}
|
||
//onContact gOnContact;
|
||
|
||
void onConstraintBreak(void* userData, physx::PxConstraintInfo* info, physx::PxU32 flag)
|
||
{
|
||
int a = 0;
|
||
}
|
||
void onWake(void* userData, physx::PxActor** actors, physx::PxU32 count, bool isSleep)
|
||
{
|
||
int a = 0;
|
||
}
|
||
void onAdvance(void* userData, physx::PxRigidBody** ppRigid, physx::PxTransform* pTrans, unsigned int nb)
|
||
{
|
||
int a = 0;
|
||
|
||
}
|
||
//virtual PxFilterFlags pairFound(PxU64 pairID,
|
||
// PxFilterObjectAttributes attributes0, PxFilterData filterData0, const PxActor* a0, const PxShape* s0,
|
||
// PxFilterObjectAttributes attributes1, PxFilterData filterData1, const PxActor* a1, const PxShape* s1,
|
||
// PxPairFlags& pairFlags) = 0;
|
||
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)
|
||
{
|
||
|
||
*pairFlags = physx::PxPairFlag::eCONTACT_DEFAULT;
|
||
*pairFlags = physx::PxPairFlag::eTRIGGER_DEFAULT;
|
||
//return physx::PxFilterFlags();
|
||
return physx::PxFilterFlag::eCALLBACK;
|
||
}
|
||
//typedef physx::PxQueryHitType::Enum(*RaycastHitCallback)(const physx::PxRigidActor* actor, const physx::PxFilterData* filterData, const physx::PxShape* shape, physx::PxU32 hitFlags, const void* userData);
|
||
// uint32_t(*RaycastHitCallback)(const physx::PxRigidActor* actor, const physx::PxFilterData* filterData, const physx::PxShape* shape,
|
||
// uint32_t hitFlags, const void* userData);
|
||
static physx::PxQueryHitType::Enum preFilter(const physx::PxRigidActor* actor, const physx::PxFilterData* filterData, const physx::PxShape* shape,
|
||
physx::PxU32 flags, const void* userData)
|
||
{
|
||
|
||
return physx::PxQueryHitType::eBLOCK;
|
||
}
|
||
|
||
|
||
static physx::PxFilterFlags PhysxWorldFilterShader(
|
||
physx::PxU32 attributes0,
|
||
physx::PxFilterData filterData0,
|
||
physx::PxU32 attributes1,
|
||
physx::PxFilterData filterData1, physx::PxPairFlags& pairFlags,
|
||
void* constantBlock, physx::PxU32 constantBlockSize)
|
||
{
|
||
|
||
//var trigger0 = phys_PxFilterObjectIsTrigger(attributes0);
|
||
//var trigger1 = phys_PxFilterObjectIsTrigger(attributes1);
|
||
|
||
//var type0 = phys_PxGetFilterObjectType(attributes0);
|
||
//var type1 = phys_PxGetFilterObjectType(attributes1);
|
||
|
||
|
||
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;
|
||
//<2F><><EFBFBD><EFBFBD>killҲ<6C><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//return PxFilterFlags.Kill;
|
||
//return PxFilterFlags.Notify;
|
||
}
|
||
|
||
|
||
|
||
int main()
|
||
{
|
||
|
||
#define PX_PHYSICS_VERSION_MAJOR 5
|
||
#define PX_PHYSICS_VERSION_MINOR 1
|
||
#define PX_PHYSICS_VERSION_BUGFIX 3
|
||
#define PX_PHYSICS_VERSION ((PX_PHYSICS_VERSION_MAJOR<<24) + (PX_PHYSICS_VERSION_MINOR<<16) + (PX_PHYSICS_VERSION_BUGFIX<<8) + 0)
|
||
|
||
//<2F><><EFBFBD><EFBFBD>found
|
||
physx_PxFoundation_Pod* _Foundation = (physx_PxFoundation_Pod*)physx_create_foundation();
|
||
physx_PxPvd_Pod* _Pvd = phys_PxCreatePvd(_Foundation);
|
||
|
||
physx_PxTolerancesScale_Pod tolerancesScale;
|
||
tolerancesScale.length = 1;
|
||
tolerancesScale.speed = 10;
|
||
physx_PxPhysics_Pod * _Physics = phys_PxCreatePhysics(PX_PHYSICS_VERSION, _Foundation, &tolerancesScale, true, _Pvd, nullptr);
|
||
//physx_PxPhysics_Pod* _Physics = (physx_PxPhysics_Pod*)physx_create_physics(_Foundation);
|
||
physx_PxDefaultCpuDispatcher_Pod * _Dispatcher = phys_PxDefaultCpuDispatcherCreate(1, nullptr, 0, 0);
|
||
physx_PxMaterial_Pod * _Material = PxPhysics_createMaterial_mut(_Physics, 0.0f, 0.0f, 0.0f);
|
||
|
||
#define PVD_HOST "192.168.101.35"
|
||
|
||
physx_PxPvdTransport_Pod*transport = phys_PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10);
|
||
|
||
bool bSuccess = PxPvd_connect_mut(_Pvd, transport,0x7);
|
||
|
||
physx_PxSceneDesc_Pod sceneDesc = PxSceneDesc_new(PxPhysics_getTolerancesScale(_Physics));
|
||
//sceneDesc.gravity = new Vector3(9.8f, 0.0f, 0.0f);
|
||
physx_PxVec3_Pod gravity;
|
||
gravity.x = 9.8f;
|
||
gravity.y = 0;
|
||
gravity.z = 0;
|
||
|
||
sceneDesc.gravity = gravity;
|
||
sceneDesc.cpuDispatcher = (physx_PxCpuDispatcher_Pod*)_Dispatcher;
|
||
|
||
|
||
//<2F><>Ҫ<EFBFBD><D2AA>ͷдһ<D0B4><D2BB>
|
||
//sceneDesc.filterShader = get_default_simulation_filter_shader();
|
||
//<2F><>һ<EFBFBD><D2BB>ʵ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
|
||
//enable_custom_filter_shader <20><>Ҫʹ<D2AA><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>api c#<23>汾<EFBFBD><E6B1BE><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><DEB8><EFBFBD>
|
||
//ֱ<><D6B1>ʹ<EFBFBD><CAB9>filterShader c apiû<69><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> c#<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
sceneDesc.filterShader = PhysxWorldFilterShader;
|
||
//
|
||
|
||
SimuliationFilterCallBackInfo _filter_call_back;
|
||
_filter_call_back.pairFoundCallback = pairFound;
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ϊnullptr _filter_call_back<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>Ա<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>Ϊ nullptr <20><><EFBFBD><EFBFBD> physx <20>ᱨ<EFBFBD><E1B1A8>
|
||
_filter_call_back.statusChangeCallback = nullptr;
|
||
_filter_call_back.pairLostCallback = nullptr;
|
||
//<2F><><EFBFBD><EFBFBD> filter call back д<><D0B4>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>һ<EFBFBD>еĹ<D0B5><C4B9><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ް<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
sceneDesc.filterCallback = (physx_PxSimulationFilterCallback_Pod*)create_simulation_filter_callbacks(&_filter_call_back);
|
||
//sceneDesc.filterCallback = nullptr;
|
||
|
||
SimulationEventCallbackInfo _event_call_back;
|
||
//<2F><>Ҫ<EFBFBD><D2AA>ͷ<EFBFBD><CDB7>ϸдһ<D0B4><D2BB>
|
||
_event_call_back.collisionCallback = onContact;
|
||
_event_call_back.collisionUserData = nullptr;
|
||
|
||
|
||
sceneDesc.simulationEventCallback = (physx_PxSimulationEventCallback_Pod*)create_simulation_event_callbacks(&_event_call_back);
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
physx_PxScene_Pod *px_scene_ = PxPhysics_createScene_mut(_Physics, &sceneDesc);
|
||
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
physx_PxVec3_Pod startPosition ;
|
||
startPosition.x = 10;
|
||
startPosition.y = 0;
|
||
startPosition.z = 1;
|
||
physx_PxQuat_Pod startOrientation ;
|
||
startOrientation.x = 0;
|
||
startOrientation.y = 0;
|
||
startOrientation.z = 0;
|
||
startOrientation.w = 1;
|
||
|
||
physx_PxSphereGeometry_Pod sphere = PxSphereGeometry_new(2.0f);
|
||
physx_PxGeometry_Pod* geometry = (physx_PxGeometry_Pod*)&sphere;
|
||
PxScene_lockWrite_mut(px_scene_ ,nullptr ,0 );
|
||
physx_PxRigidActor_Pod* rigActor = nullptr;
|
||
|
||
|
||
physx_PxTransform_Pod identity = PxTransform_new_2(100);
|
||
physx_PxTransform_Pod pxTran ;
|
||
pxTran.p = startPosition;
|
||
pxTran.q = startOrientation;
|
||
|
||
rigActor = (physx_PxRigidActor_Pod*)phys_PxCreateDynamic(
|
||
_Physics, &pxTran, geometry,
|
||
_Material, 10.0f, &identity);
|
||
|
||
PxActor_setActorFlag_mut((physx_PxActor_Pod*)rigActor,2, true);
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CDB9><EFBFBD>
|
||
PxRigidBodyExt_updateMassAndInertia_1((physx_PxRigidBody_Pod*)rigActor, 1.0f, nullptr, false);
|
||
PxRigidBody_setRigidBodyFlag_mut((physx_PxRigidBody_Pod*)rigActor, 4, true);
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//PxShape* shape;
|
||
//rigActor->GetShapes(&shape, 1, 0);
|
||
//fixed(byte * bytePointer = Encoding.UTF8.GetBytes("niubi"))
|
||
//{
|
||
// shape->SetNameMut(bytePointer);
|
||
//}
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||
physx_PxVec3_Pod velocity ;
|
||
velocity.x = 1.0f;
|
||
velocity.y = 0.0f;
|
||
velocity.z = 0.0f;
|
||
PxRigidDynamic_setLinearVelocity_mut((physx_PxRigidDynamic_Pod*)rigActor, &velocity, true);
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD> <20><><EFBFBD>ٶ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
PxRigidBody_setLinearDamping_mut((physx_PxRigidBody_Pod*)rigActor, 0);
|
||
PxRigidBody_setAngularDamping_mut((physx_PxRigidBody_Pod*)rigActor, 0);
|
||
|
||
PxScene_addActor_mut(px_scene_,(physx_PxActor_Pod*)rigActor,nullptr);
|
||
//px_scene_->AddActorMut((PxActor*)rigActor, null);
|
||
PxScene_unlockWrite_mut(px_scene_);
|
||
|
||
|
||
PxScene_lockWrite_mut(px_scene_, nullptr, 0);
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
physx_PxVec3_Pod startPosition2 ;
|
||
startPosition2.x = 24;
|
||
startPosition2.y = 0;
|
||
startPosition2.z = 0;
|
||
physx_PxQuat_Pod startOrientation2 ;
|
||
startOrientation2.x = 0;
|
||
startOrientation2.y = 0;
|
||
startOrientation2.z = 0;
|
||
startOrientation2.w = 1;
|
||
|
||
|
||
physx_PxSphereGeometry_Pod sphere2 = PxSphereGeometry_new(1.0f);
|
||
physx_PxGeometry_Pod* geometry2 = (physx_PxGeometry_Pod*)&sphere2;
|
||
|
||
//PxScene_lockWrite_mut(px_scene_, nullptr, 0);
|
||
physx_PxRigidActor_Pod* rigActor2 = nullptr;
|
||
|
||
|
||
physx_PxTransform_Pod identity2 = PxTransform_new_2(100);
|
||
physx_PxTransform_Pod pxTran2 ;
|
||
pxTran2.p = startPosition2;
|
||
pxTran2.q = startOrientation2;
|
||
|
||
|
||
//PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
rigActor2 = (physx_PxRigidActor_Pod*)phys_PxCreateDynamic(
|
||
_Physics, &pxTran2, geometry2,
|
||
_Material, 10.0f, &identity2);
|
||
|
||
PxActor_setActorFlag_mut((physx_PxActor_Pod*)rigActor2, 2, true);
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CDB9><EFBFBD>
|
||
PxRigidBodyExt_updateMassAndInertia_1((physx_PxRigidBody_Pod*)rigActor2, 3.0f, nullptr, false);
|
||
PxRigidBody_setRigidBodyFlag_mut((physx_PxRigidBody_Pod*)rigActor2, 4, true);
|
||
|
||
|
||
physx_PxShape_Pod* shape2;
|
||
//rigActor2->GetShapes(&shape2, 1, 0);
|
||
PxRigidActor_getShapes((physx_PxRigidActor_Pod*)rigActor2, &shape2,1,0);
|
||
|
||
physx_PxFilterData_Pod filterData2 = PxFilterData_new_1();;
|
||
filterData2.word0 = 5;
|
||
filterData2.word1 = 0;
|
||
filterData2.word2 = 0;
|
||
filterData2.word3 = 0;
|
||
|
||
//shape2->SetSimulationFilterDataMut(&filterData2);
|
||
PxShape_setSimulationFilterData_mut(shape2, &filterData2);
|
||
PxShape_setFlag_mut(shape2, physx::PxShapeFlag::Enum::eSIMULATION_SHAPE,false);
|
||
PxShape_setFlag_mut(shape2, physx::PxShapeFlag::Enum::eTRIGGER_SHAPE, true);
|
||
PxShape_setFlag_mut(shape2, physx::PxShapeFlag::Enum::eSCENE_QUERY_SHAPE, true);
|
||
PxShape_setFlag_mut(shape2, physx::PxShapeFlag::Enum::eVISUALIZATION, true);
|
||
|
||
//shape2->SetFlagMut(physx::PxShapeFlag.SimulationShape, false); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>
|
||
//shape2->SetFlagMut(PxShapeFlag.TriggerShape, true);
|
||
//shape2->SetFlagMut(PxShapeFlag.SceneQueryShape, true);
|
||
//shape2->SetFlagMut(PxShapeFlag.Visualization, true);
|
||
|
||
|
||
physx_PxVec3_Pod velocity2 ;
|
||
velocity2.x = -1.0f;
|
||
velocity2.y = 0.0f;
|
||
velocity2.z = 0.0f;
|
||
PxRigidDynamic_setLinearVelocity_mut((physx_PxRigidDynamic_Pod*)rigActor2, &velocity2, true);
|
||
PxRigidBody_setLinearDamping_mut((physx_PxRigidBody_Pod*)rigActor2, 0);
|
||
PxRigidBody_setAngularDamping_mut((physx_PxRigidBody_Pod*)rigActor2, 0);
|
||
|
||
//px_scene_->AddActorMut((PxActor*)rigActor2, null);
|
||
PxScene_addActor_mut(px_scene_, (physx_PxActor_Pod*)rigActor2, nullptr);
|
||
|
||
PxRigidDynamic_setContactReportThreshold_mut((physx_PxRigidDynamic_Pod*)rigActor2, 0.1f);
|
||
PxScene_unlockWrite_mut(px_scene_);
|
||
|
||
|
||
physx_PxRaycastHit_Pod rayHit;
|
||
//rayHit.actor = nullptr;
|
||
//rayHit.shape = nullptr;
|
||
//rayHit.u = 0;
|
||
//rayHit.v = 0;
|
||
//rayHit.flags = 0x10;
|
||
physx_PxQueryFilterData_Pod filterData = PxQueryFilterData_new();
|
||
//filterData.data.word0 = 5;
|
||
//filterData.data.word1 = 0;
|
||
//filterData.data.word2 = 0;
|
||
//filterData.data.word3 = 0;
|
||
//<2F><><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD> ePREFILTER <20><> eDYNAMIC
|
||
filterData.flags = (1 << 2) | (1<<1); //ePREFILTER | eDYNAMIC = (1<<2),
|
||
|
||
physx_PxVec3_Pod normalizedDir ;
|
||
normalizedDir.x = 1.0f;
|
||
normalizedDir.y = 0.0f;
|
||
normalizedDir.z = 0.0f;
|
||
physx_PxVec3_Pod tmpNormalizedDir = PxVec3_getNormalized(&normalizedDir);
|
||
//normalizedDir.GetNormalized();
|
||
|
||
startPosition.x = 20.0f;
|
||
//startPosition.z = 0;
|
||
|
||
physx_PxQueryFilterCallback_Pod* fliterCallBack =
|
||
(physx_PxQueryFilterCallback_Pod*)create_pre_and_post_raycast_filter_callback_func(preFilter,nullptr,nullptr);
|
||
////<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>ͼ<EFBFBD>Ʋ<EFBFBD>Ϊ
|
||
bool hasBlock = PxSceneQueryExt_raycastSingle(px_scene_, &startPosition, &tmpNormalizedDir, 30, 0x20, &rayHit, &filterData, fliterCallBack, nullptr);
|
||
|
||
|
||
while (true)
|
||
{
|
||
unsigned int error = 0;
|
||
//px_scene_->SimulateMut(0.05f, null, null, 0, true);
|
||
PxScene_simulate_mut(px_scene_, 0.05f, nullptr,nullptr, 0,true);
|
||
PxScene_fetchResults_mut(px_scene_, true, &error);
|
||
}
|
||
|
||
|
||
return 0;
|
||
}
|
||
|