From 08c75b06c797e6ec152fe880734ddc1236cf1fbd Mon Sep 17 00:00:00 2001 From: tovjemam Date: Thu, 7 Mar 2024 21:44:41 +0100 Subject: [PATCH] dsdf --- karo.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/karo.cpp b/karo.cpp index 7cddb49..ad319a5 100644 --- a/karo.cpp +++ b/karo.cpp @@ -78,6 +78,45 @@ static void CheckProgramLinkErrors(GLuint program) { } } +enum ContactGroup { + CG_NONE = 0, + CG_BOX = (1 << 1), + CG_FLOOR = (1 << 2), +}; + +PxFilterFlags FilterShaderExample( + PxFilterObjectAttributes attributes0, PxFilterData filterData0, + PxFilterObjectAttributes attributes1, PxFilterData filterData1, + PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize) +{ + // let triggers through + if (PxFilterObjectIsTrigger(attributes0) || PxFilterObjectIsTrigger(attributes1)) + { + pairFlags = PxPairFlag::eTRIGGER_DEFAULT; + return PxFilterFlag::eDEFAULT; + } + // generate contacts for all that were not filtered above + pairFlags = PxPairFlag::eCONTACT_DEFAULT; + + // trigger the contact callback for pairs (A,B) where + // the filtermask of A contains the ID of B and vice versa. + if ((filterData0.word0 & filterData1.word1) && (filterData1.word0 & filterData0.word1)) { + pairFlags |= PxPairFlag::eNOTIFY_TOUCH_FOUND; + return PxFilterFlag::eDEFAULT; + + } + + return PxFilterFlag::eSUPPRESS; +} + +void SetupFiltering(PxShape* shape, PxU32 filterGroup, PxU32 filterMask) +{ + PxFilterData filterData; + filterData.word0 = filterGroup; // word0 = own ID + filterData.word1 = filterMask; // word1 = ID mask to filter pairs that trigger a contact callback + shape->setSimulationFilterData(filterData); +} + static std::vector s_draw_lines; static std::vector s_draw_points; @@ -113,9 +152,10 @@ static void InitPhysics() { exit(3); sceneDesc.cpuDispatcher = s_cpu_dispatcher; + sceneDesc.filterShader = &FilterShaderExample; - if (!sceneDesc.filterShader) - sceneDesc.filterShader = &PxDefaultSimulationFilterShader; + //if (!sceneDesc.filterShader) + // sceneDesc.filterShader = &PxDefaultSimulationFilterShader; s_scene = s_physics->createScene(sceneDesc); if (!s_scene) @@ -153,14 +193,20 @@ static void InitPhysics() { //m_scene->setVisualizationParameter(PxVisualizationParameter::eJOINT_LOCAL_FRAMES, enable ? 1.0f : 0.0f); m_scene->setVisualizationParameter(PxVisualizationParameter::eWORLD_AXES, enable ? 1.0f : 0.0f); + PxShape* shape; auto floor_material = s_physics->createMaterial(1.0f, 1.0f, 0.0f); s_material = s_physics->createMaterial(1.0f, 1.0f, 0.6f); auto floor = PxCreatePlane(*s_physics, PxPlane(PxVec3(0.f, 1.f, 0.f), 0.f), *floor_material); + floor->getShapes(&shape, 1); + SetupFiltering(shape, CG_FLOOR, CG_BOX | CG_FLOOR); s_scene->addActor(*floor); + s_box1 = PxCreateDynamic(*s_physics, PxTransform(PxVec3(0.f, 5.0f, 0.f)), PxBoxGeometry(0.5f, 0.5f, 0.5f), *s_material, 1.f); + s_box1->getShapes(&shape, 1); + SetupFiltering(shape, CG_BOX, CG_FLOOR); s_scene->addActor(*s_box1); } @@ -223,6 +269,7 @@ int main() { glfwWindowHint(GLFW_STENCIL_BITS, 0); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); + //GLFWwindow* window = glfwCreateWindow(1920, 1080, "Karo", glfwGetPrimaryMonitor(), NULL); GLFWwindow* window = glfwCreateWindow(800, 600, "Karo", NULL, NULL); if (!window) { std::cerr << "Failed to create window\n"; @@ -304,9 +351,12 @@ int main() { break; case GLFW_KEY_E: - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 1; i++) { auto newbox = PxCreateDynamic(*s_physics, PxTransform(PxVec3(0.f, 5.0f * i, 0.f)), PxBoxGeometry(0.5f, 0.5f, 0.5f), *s_material, 1.f); + PxShape* shape; + newbox->getShapes(&shape, 1); + SetupFiltering(shape, CG_BOX, CG_FLOOR | CG_BOX); s_scene->addActor(*newbox); s_count++; } @@ -331,7 +381,7 @@ int main() { glViewport(0, 0, width, height); glm::mat4 proj = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 0.1f, 1000.0f); - glm::mat4 view = glm::lookAt(glm::vec3(1.0f, 10.0f, 20.0f) * 10.0f, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0, 1.0, 0.0)); + glm::mat4 view = glm::lookAt(glm::vec3(1.0f, 10.0f, 20.0f) * 1.0f, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0, 1.0, 0.0)); glm::mat4 mvp = proj * view;