From dfd0c57acb9de79d967e0c9eddd1aca40422ac2d Mon Sep 17 00:00:00 2001 From: duanping <1577379109@qq.com> Date: Mon, 31 Jul 2023 14:10:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=9C=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PhysxWorld.cs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/PhysxWorld.cs b/PhysxWorld.cs index c8dcdeb..ae0bfb9 100644 --- a/PhysxWorld.cs +++ b/PhysxWorld.cs @@ -534,7 +534,7 @@ namespace PhysX TriggerCallBack tmp = new TriggerCallBack(shape, effectType, effectValue, enter, leave); _worldUserData.trigger_mgr_.Push(&tmp); - //TODO 这一步删除 c++实现中 make智能指针了 这里会删除外部数据shape + //这一步是减少引用次数 和用户数据无关 防止内存泄露 //shape->ReleaseMut(); return true; } @@ -562,7 +562,7 @@ namespace PhysX PxVec3* hero_position = null) { - //这一部是错误的 api 有bug 不可以返回指针类型 必须在当前栈对象创建PxGemometry + //这一部是错误的 api 有bug 不可以返回指针类型 必须在当前栈对象创建PxGemometry !! PxGeometry* geometry = CreateGeometry(shape_type, min_position, max_position); if (geometry == null) @@ -640,6 +640,8 @@ namespace PhysX return null; } + + //可以简化逻辑 调用新的api 直接设置密度和质量 // add collision mask if (mass > 0) { @@ -766,14 +768,14 @@ namespace PhysX sceneDesc.filterShader = (void*)(delegate* unmanaged[Cdecl])callback; //sceneDesc.simulationEventCallback = this; - //TODO 根据自己理解实现 应该就是这么搞。。 delegate* tmpContact = &onContact; _event_call_back->collision_callback = (delegate* unmanaged[Cdecl])tmpContact; - _event_call_back->collision_user_data = (void*)_event_call_back->collision_callback; + //根据需要填写用户数据 + _event_call_back->collision_user_data = null; delegate* tmpTrigger = &onTrigger; _event_call_back->trigger_callback = (delegate* unmanaged[Cdecl])tmpTrigger; - _event_call_back->trigger_user_data = (void*)_event_call_back->trigger_callback; + _event_call_back->trigger_user_data = null; //其余方法没有重载 不需要设置回调函数 sceneDesc.simulationEventCallback = create_simulation_event_callbacks(_event_call_back); @@ -949,8 +951,6 @@ namespace PhysX // world 类自身方法 end - - //工具方法 start 既然是工具方法是否可以修改为static 放到common? bool RayTest( PxRigidActor* actor, PxVec3 start_position, PxVec3 normalizedDir, int mask, int group, @@ -971,7 +971,6 @@ namespace PhysX PxQueryFilterCallback* fliterCallBack = create_raycast_filter_callback_func( (delegate* unmanaged[Cdecl])(CB.callback), (void*)&CB.userData); - //根据原意图推测为 bool hasBlock = PxSceneQueryExt_raycastSingle(_worldUserData.px_scene_, &start_position, &normalizedDir, distance, PxHitFlags.Default,rayHit, &filterData, fliterCallBack, null); @@ -1014,7 +1013,6 @@ namespace PhysX //hit_result->actor_ptr = sweepHit.actor; return true; } - //PxSceneQueryExt_sweepMultiple return false; } @@ -1030,7 +1028,6 @@ namespace PhysX filterData.flags = PxQueryFlags.Dynamic; bool hasOverLap = PxSceneQueryExt_overlapAny(_worldUserData.px_scene_, geometry, shapePose, hitBuffer, null,null); - if (hasOverLap ) { return true; @@ -1127,7 +1124,6 @@ namespace PhysX public static void onContact(void* userData, PxContactPairHeader* pairHeader, PxContactPair* pairs, UInt32 nbPairs) { - if (userData == null) { return; } WorldUserData* _worldUserData = (WorldUserData*)userData; @@ -1137,7 +1133,6 @@ namespace PhysX for (UInt32 i = 0; i < nbPairs; i++) { PxContactPair* cp = &pairs[i]; - //TODO:这部分转化需要测试 PhysxObjectType type0 = PxConstValue.PhysxGetUserType((PxRigidActor*)pairHeader->actors[0]); PhysxObjectType type1 = PxConstValue.PhysxGetUserType((PxRigidActor*)pairHeader->actors[1]); @@ -1146,13 +1141,10 @@ namespace PhysX { UInt32 contactCount = cp->contactCount; if (contactCount < 1) continue; - //contactPoints.Capacity(contactCount); - //contactPoints.Re Array.Resize(ref contactPoints, (int)contactCount); //structgen_pad0 函数地址 fixed (IntPtr* contactPointsPtr = contactPoints) { - //TODO: 这部分代码需要验证 PxContactPairPoint* conPtr0 = (PxContactPairPoint*)contactPointsPtr->ToPointer(); cp->ExtractContacts(conPtr0, contactCount); }