bool InitNx() { // Initialize PhysicsSDK NxPhysicsSDKDesc desc; NxSDKCreateError errorCode = NXCE_NO_ERROR; gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, 0, 0, desc, &errorCode); if(gPhysicsSDK == NULL) { printf("\nSDK create error (%d - %s).\nUnable to initialize the PhysX SDK, exiting the sample.\n\n", errorCode, getNxSDKCreateError(errorCode)); return false; } gPhysicsSDK->setParameter(NX_SKIN_WIDTH, gSkinWidth); gPhysicsSDK->setParameter(NX_DEFAULT_SLEEP_ENERGY, 0.01f); // Create a scene NxSceneDesc sceneDesc; sceneDesc.gravity = NxVec3(0.0f, -9.81f, 0.0f); sceneDesc.userNotify = &g_SleepCallBack; //用户自定义事件 sceneDesc.userContactReport = &gMyContactReport; gScene = gPhysicsSDK->createScene(sceneDesc); if(gScene == NULL) { printf("\nError: Unable to create a PhysX scene, exiting the sample.\n\n"); return false; } gScene->setTiming(); // Set default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.0f); defaultMaterial->setStaticFriction(0.5f); defaultMaterial->setDynamicFriction(0.5f); CreatePhysicsTerrain(); return true; }
BenchmarkSuiteDemo::BenchmarkSuiteDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { const BenchmarkSuiteVariant& variant = g_variants[m_variantId]; // Disable warnings: hkError::getInstance().setEnabled(0x7dd65995, false); //'The system has requested a heap allocation on stack overflow.' hkError::getInstance().setEnabled(0xaf55adde, false); //'No runtime block of size 637136 currently available. Allocating new block from unmanaged memory.' // // Setup the camera // { hkVector4 from(55.0f, 50.0f, 55.0f); hkVector4 to ( 0.0f, 0.0f, 0.0f); hkVector4 up ( 0.0f, 1.0f, 0.0f); setupDefaultCameras(env, from, to, up, 0.1f, 20000.0f); } // // Create the world // { hkpWorldCinfo worldInfo; { worldInfo.m_gravity.set(-0.0f, -9.81f, -0.0f); worldInfo.setBroadPhaseWorldSize(500.0f); worldInfo.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM ); if (variant.m_type == TYPE_3000_BODY_PILE) { worldInfo.m_enableSimulationIslands = false; } worldInfo.m_enableDeactivation = false; } m_world = new hkpWorld(worldInfo); m_world->lock(); // Register ALL agents (though some may not be necessary) hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); setupGraphics(); // enable instancing (if present on platform). Call this after setup graphics (as it makes the local viewers..) hkpShapeDisplayViewer* shapeViewer = (hkpShapeDisplayViewer*)getLocalViewerByName( hkpShapeDisplayViewer::getName() ); if (shapeViewer) { shapeViewer->setInstancingEnabled( true ); } } // // Setup the camera // { hkVector4 from(15.0f, 15.0f, 15.0f); hkVector4 to (0.0f, 0.0f, 0.0f); hkVector4 up (0.0f, 1.0f, 0.0f); setupDefaultCameras( env, from, to, up ); } switch (variant.m_type) { case TYPE_10x10x1_ON_BOX: { CreateGroundPlane( m_world ); CreateStack(m_world, 10); break; } case TYPE_5x5x5_ON_BOX: { CreateGroundPlane(m_world); for (int q = -3; q <= 2; q++ ) { CreateStack(m_world,5, q * 10.0f); } break; } case TYPE_300_BODY_PILE: { CreateGroundPlane(m_world); CreateFall(m_world, 5); break; } case TYPE_OBJECTS_ON_MOPP_SMALL: { CreatePhysicsTerrain(m_world, 16, 1.0f); CreateFlatCubeGrid(m_world,8); break; } case TYPE_LIST_PILE_SMALL: { int side = 16; CreatePhysicsTerrain(m_world, side, 1.0f); CreateListGrid(m_world, hkReal(side), 3, 3); break; } case TYPE_30x30x1_ON_BOX: { CreateGroundPlane( m_world ); CreateStack(m_world, 30); break; } case TYPE_20x20x5_ON_BOX: { CreateGroundPlane(m_world); for (int q = -3; q <= 2; q++ ) { CreateStack(m_world,20, q * 10.0f); } break; } case TYPE_12x12x10_ON_BOX: { CreateGroundPlane(m_world); for (int q = -5; q <= 4; q++ ) { CreateStack(m_world,12, q * 2.5f); } break; } case TYPE_3000_BODY_PILE: { CreateGroundPlane(m_world); CreateFall(m_world, 50); break; } case TYPE_OBJECTS_ON_MOPP_LARGE: { CreatePhysicsTerrain(m_world, 64, 1.0f); CreateFlatCubeGrid(m_world,30); break; } case TYPE_LIST_PILE_LARGE: { int side = 16; CreatePhysicsTerrain(m_world, side, 1.0f); CreateListGrid(m_world, hkReal(side), 5, 5); break; } default: { CreateGroundPlane(m_world); CreateStack(m_world, 20); break; } } // // Some values // m_world->unlock(); }