void InitNx() { // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); // gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LOCAL_AXES, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene){ sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene CreateGroundPlane(); capsule1 = CreateCapsule(NxVec3(0,5,0), 1, 0.5, 10); capsule1->raiseBodyFlag(NX_BF_KINEMATIC); capsule2 = CreateCapsule(NxVec3(0,3,0), 1, 0.5, 10); // capsule2->setLinearDamping(0.1); capsule2->raiseBodyFlag(NX_BF_DISABLE_GRAVITY); NxVec3 globalAnchor = NxVec3(0,5,0); NxVec3 globalAxis = NxVec3(0,1,0); d6Joint = CreateD6Joint(capsule1, capsule2, globalAnchor, globalAxis); gSelectedActor = capsule2; gForceStrength = 50000; gCameraSpeed = 10; // Initialize HUD InitializeHUD(); InitializeSpecialHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void SetupTearingScene() { sprintf(gTitleString, "Tearing Demo"); // Create the objects in the scene groundPlane = CreateGroundPlane(); NxActor* bar = CreateBox(NxVec3(0,12,0), NxVec3(3,0.5,0.5), 0); NxActor* box = CreateBox(NxVec3(-2.3,4.0,0), NxVec3(0.5,0.5,0.5), 10); // Cloth NxClothDesc clothDesc; clothDesc.globalPose.t = NxVec3(2.5,12,0); clothDesc.globalPose.M.rotX(-NxHalfPiF32); clothDesc.thickness = 0.1; clothDesc.tearFactor = 2; clothDesc.flags |= NX_CLF_BENDING; clothDesc.flags |= NX_CLF_COLLISION_TWOWAY; clothDesc.flags |= NX_CLF_TEARABLE | NX_CLF_VISUALIZATION; // Tearable cloth if (gHardwareCloth) clothDesc.flags |= NX_CLF_HARDWARE; MyCloth* regularCloth = new MyCloth(gScene, clothDesc, 5, 8, 0.1, "rug512.bmp", gTearLines); gCloths.push_back(regularCloth); regularCloth->getNxCloth()->attachToShape(*bar->getShapes(), 0); regularCloth->getNxCloth()->attachToShape(*box->getShapes(), NX_CLOTH_ATTACHMENT_TWOWAY); }
void SetupAttachmentScene() { sprintf(gTitleString, "Attachment Demo"); // Create objects in scene groundPlane = CreateGroundPlane(); NxActor* box1 = CreateBox(NxVec3(-7,12.25,0), NxVec3(2.5,1,1), 0); NxActor* box2 = CreateBox(NxVec3(0,12.25,0), NxVec3(2.5,1,1), 0); NxActor* box3 = CreateBox(NxVec3(7,12.25,0), NxVec3(2.5,1,1), 0); NxActor* attachedBox = CreateBox(NxVec3(-7.2,4.5,1.6), NxVec3(1.25,1,1), 1); NxActor* attachedSphere = CreateSphere(NxVec3(-0.25,4.0,2.0), 1.3, 1); NxActor* attachedCapsule = CreateCapsule(NxVec3(9.0,5.5,2.0),2.0, 1, 1); NxReal damping = 0.3; attachedBox->setAngularDamping(damping); attachedBox->setLinearDamping(damping); attachedSphere->setAngularDamping(damping); attachedSphere->setLinearDamping(damping); attachedCapsule->setAngularDamping(damping); attachedCapsule->setLinearDamping(damping); NxQuat q; q.fromAngleAxis(90,NxVec3(0,0,1)); attachedCapsule->setGlobalOrientationQuat(q); // Cloth NxClothDesc clothDesc; clothDesc.globalPose.M.rotX(1.3); clothDesc.thickness = 0.3; clothDesc.attachmentResponseCoefficient = 1; clothDesc.flags |= NX_CLF_BENDING; clothDesc.flags |= NX_CLF_BENDING_ORTHO; clothDesc.flags |= NX_CLF_DAMPING | NX_CLF_VISUALIZATION; if (gHardwareCloth) clothDesc.flags |= NX_CLF_HARDWARE; // Cloth attaching to sphere clothDesc.globalPose.t = NxVec3(0.75,5,2); MyCloth* regularCloth1 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth1->getNxCloth()->attachToCollidingShapes(NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth1); // Cloth attaching to box clothDesc.globalPose.t = NxVec3(-6.2,5,2); MyCloth* regularCloth2 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth2->getNxCloth()->attachToCollidingShapes(NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth2); // Cloth attaching to capsule clothDesc.globalPose.t = NxVec3(8.0,5,2); clothDesc.attachmentTearFactor = 2.0; MyCloth* regularCloth3 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth3->getNxCloth()->attachToShape(box3->getShapes()[0], NX_CLOTH_ATTACHMENT_TEARABLE); regularCloth3->getNxCloth()->attachToShape(attachedCapsule->getShapes()[0], NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth3); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = CreatePhysics(); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene){ sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Set Core Dump directory char buff[512]; FindMediaFile(fnameCD, buff); #ifdef WIN32 SetCurrentDirectory(buff); #elif LINUX chdir(buff); #endif // Create the objects in the scene NxActor* groundPlane = CreateGroundPlane(); NxActor* box = CreateBox(NxVec3(5,0,0), NxVec3(0.5,1,0.5), 20); NxActor* sphere = CreateSphere(NxVec3(0,0,0), 1, 10); NxActor* capsule = CreateCapsule(NxVec3(-5,0,0), 2, 0.5, 10); // pyramid = CreatePyramid(NxVec3(0,0,0), NxVec3(1,0.5,1.5), 10); AddUserDataToActors(gScene); gSelectedActor = capsule; // gSelectedActor = pyramid; // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 2); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene){ sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene CreateGroundPlane(); mainBox = CreateMainObject(); gSelectedActor = mainBox; gCameraPos = NxVec3(0,15,-50); gCameraSpeed = 20; gForceStrength = 50000000; // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
bool CreateScenario() { DestroyScenario(); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = bHWScene? NX_SIMULATION_HW : NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(0 == gScene) { bHWScene = !bHWScene; sceneDesc.simType = bHWScene? NX_SIMULATION_HW : NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(0 == gScene) return false; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the plane in primary scene groundPlane = CreateGroundPlane(); // Create compartment(HSM, managed hardware scene) attached to this scene NxCompartmentDesc desc; desc.type = NX_SCT_RIGIDBODY; desc.deviceCode = NxU32(NX_DC_PPU_0); gCompartmentHW = gScene->createCompartment(desc); desc.deviceCode = NxU32(NX_DC_CPU); gCompartmentSW = gScene->createCompartment(desc); // Create objects boxHW = CreateManagedBox(NxVec3(6, 0, 0), NxVec3(0.5, 1, 0.5), 20, gCompartmentHW); boxSW = CreateManagedBox(NxVec3(3, 0, 0), NxVec3(0.5, 1, 0.5), 20, gCompartmentSW); sphereHW = CreateManagedSphere(NxVec3(-6,0,0), 1, 10, gCompartmentHW); sphereHW = CreateManagedSphere(NxVec3(-3,0,0), 1, 10, gCompartmentSW); capsule = CreateManagedCapsule(NxVec3(0,0,0), 2, 1, 5, 0); gSelectedActor = boxHW; // Initialize HUD InitializeHUD(); // Start the first frame of the simulation StartPhysics(); return true; }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); //gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); //gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); //gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.simType = NX_SIMULATION_SW; sceneDesc.gravity = gDefaultGravity; gScene = gPhysicsSDK->createScene(sceneDesc); // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); groundPlane = CreateGroundPlane(); //groundPlane->getShapes()[0]->setFlag(NX_SF_FLUID_DRAIN,true); // Create drain actors CreateDrainActors(); fluidEmitter = CreateFluidEmitter(0.35, 0.35); // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void InitNx() { // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); if (!gPhysicsSDK) return; // Set the debug visualization parameters for forcefield visualization gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_FORCE_FIELDS, 1.0f); // Create the scene NxSceneDesc sceneDesc; sceneDesc.simType = NX_SIMULATION_HW; sceneDesc.gravity = gDefaultGravity; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) { sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the objects in the scene groundPlane = CreateGroundPlane(); box1 = CreateBox(NxVec3(5,3.5,0)); // Create a Custome kernel and a Linear kernel CreateFFCustomKernel(); CreateFFLinearKernel(); //Create the forcefield in the scene gForceField = CreateForcefield(); // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
// Experiment specific functions called from ARSS.cpp void CreateExperiment() { // This is how you turn on the grid display. (There is also an XY Grid.) gDebug.bXZGridOn=true; // This is how you create a ground plane (and save its address in gExp.VIPs). CreateGroundPlane(); // This is how you create a compound, multi-shape, static actor. PxRigidStatic* basket = gPhysX.mPhysics->createRigidStatic(PxTransform(PxVec3(0))); if (!basket) ncc__error("basket fail!"); PxMaterial* defmat=gPhysX.mDefaultMaterial; PxBoxGeometry base(0.5,0.1,0.5); PxBoxGeometry pole(0.05,1,0.05); PxBoxGeometry board(0.5,0.5,0.01); PxBoxGeometry hoopel(0.01,0.01,0.15); basket->createShape(base,*defmat,PxTransform(PxVec3(0,0.1,0))); basket->createShape(pole,*defmat,PxTransform(PxVec3(0,1,0))); PxShape* sboard = basket->createShape(board,*defmat,PxTransform(PxVec3(0,2,0.05))); PxShape* shoopel1 = basket->createShape(hoopel,*defmat,PxTransform(PxVec3(-0.15,2,0.15+0.06))); PxShape* shoopel2 = basket->createShape(hoopel,*defmat,PxTransform(PxVec3(+0.15,2,0.15+0.06))); PxShape* shoopel3 = basket->createShape(hoopel,*defmat,PxTransform(PxVec3(+0.00,2,0.30+0.05),PxQuat(PxPi/2,PxVec3(0,1,0)))); gPhysX.mScene->addActor(*basket); // We saved the pointers to the shapes we wish to color separately, with a call to the convenience function... ColorShape(sboard, ncc::rgb::yLightYellow); // ... or manually (in case we wish to be efficient with duplicate colors). gColors.colorBucket.push_back(vector<GLubyte>(3)); gColors.colorBucket.back()[0]=ncc::rgb::grBlack[0]; gColors.colorBucket.back()[1]=ncc::rgb::grBlack[1]; gColors.colorBucket.back()[2]=ncc::rgb::grBlack[2]; shoopel1->userData=&(gColors.colorBucket.back()[0]); shoopel2->userData=&(gColors.colorBucket.back()[0]); shoopel3->userData=&(gColors.colorBucket.back()[0]); // We signal that the experiment is ready for simulation by setting this flag. gSim.isRunning = true; }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LOCAL_AXES, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene){ sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene CreateGroundPlane(); // Slider Joint capsule1 = CreateCapsule(NxVec3(0,5,0), 1, 0.5, 10); capsule1->raiseBodyFlag(NX_BF_KINEMATIC); capsule2 = CreateCapsule(NxVec3(0,3,0), 1, 0.5, 10); capsule2->raiseBodyFlag(NX_BF_DISABLE_GRAVITY); NxVec3 globalAnchor = gJointStartPos; NxVec3 globalAxis = NxVec3(0,1,0); d6Joint = CreateD6Joint(capsule1, capsule2, globalAnchor, globalAxis); ball = CreateFollowBall(gBallStartPos,0.25,1); ball->raiseBodyFlag(NX_BF_KINEMATIC); NxMat33 orient = ball->getGlobalOrientation(); NxMat33 controlOrient; controlOrient.setRow(0, orient.getRow(2)); controlOrient.setRow(1, orient.getRow(0)); controlOrient.setRow(2, orient.getRow(1)); ball->setGlobalOrientation(controlOrient); gSelectedActor = ball; gForceStrength = 1500; gCameraSpeed = 10; box = CreateBox(NxVec3(3,0,0), NxVec3(0.5,1,0.5), 20); sphere = CreateSphere(NxVec3(0,0,3), 1, 10); capsule = CreateCapsule(NxVec3(-3,0,0), 2, 0.5, 10); pyramid = CreatePyramid(NxVec3(0,0,-3), NxVec3(0.75,1.5,0.75), 10); box->setLinearDamping(0.5); sphere->setLinearDamping(0.5); capsule->setLinearDamping(0.5); pyramid->setLinearDamping(0.5); AddUserDataToActors(gScene); // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
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(); }
void InitNx() { // Initialize Camera Parameters gCameraAspectRatio = 1.0f; gCameraPos = NxVec3(0,5,-15); gCameraForward = NxVec3(0,0,1); gCameraRight = NxVec3(-1,0,0); // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); gPhysicsSDK->setParameter(NX_DEFAULT_SLEEP_LIN_VEL_SQUARED, 0.15*0.15); gPhysicsSDK->setParameter(NX_DEFAULT_SLEEP_ANG_VEL_SQUARED, 0.14*0.14); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_AABBS, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) { sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene groundPlane = CreateGroundPlane(); // Create dynamic actors CreateSphere(NxVec3(6.0f, 0.0f, 24.0f), 0); CreateBox(NxVec3(6.0f, 0.0f, 16.0f), 0); CreateCapsule(NxVec3(6.0f, 0.0f, 6.0f), 0); gSelectedActor = CreateConvex(NxVec3(6.0f, 0.0f, 0.0f), 0); // Create static actors CreateSphere(NxVec3(0.0f, 0.0f, 24.0f), 0); CreateBox(NxVec3(0.0f, 0.0f, 16.0f), 0); CreateCapsule(NxVec3(0.0f, 0.0f, 6.0f), 0); CreateConvex(NxVec3(0.0f, 0.0f, 0.0f), 0); // Create kinematic actors CreateSphere(NxVec3(-6.0f, 0.0f, 24.0f), 0); CreateBox(NxVec3(-6.0f, 0.0f, 16.0f), 0); CreateCapsule(NxVec3(-6.0f, 0.0f, 6.0f), 0); CreateConvex(NxVec3(-6.0f, 0.0f, 0.0f), 0); bPause = false; gCapsuleSegment.p0 = NxVec3(0, 1.2f, 0.5f); gCapsuleSegment.p1 = NxVec3(0, 3.2f, 0.5f); // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) { sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // gScene->setTiming(0.01); // timeStep, maxIter, TIMESTEP_FIXED // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene CreateGroundPlane(); NxU32 r; NxI32 x, z; NxReal fRX, fRZ; // create grass block for (x = -patchsize; x < patchsize; x++) { for (z = -patchsize; z < patchsize; z++) { fRX = NxMath::rand(-45,45)*0.01; fRZ = NxMath::rand(-45,45)*0.01; r = NxMath::rand(0,4); if (r == 0) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),3,4); } else if (r == 1) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),1.8,2); } else if (r == 1) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),2,3); } else if (r == 1) { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),1.5,2); } else { grassBlade[x+patchsize][z+patchsize] = new Blade(NxVec3(scale*(x+fRX),0,scale*(z+fRZ)),2.1,3); } } } gScene->setGroupCollisionFlag(1,1,false); ball = CreateBall(NxVec3(0,10,0),1.5,350); SetActorCollisionGroup(ball, 3); gSelectedActor = ball; gCameraSpeed = 20; gForceStrength = 850000; // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator, &gErrorStream); if (0 == gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; if (gbThreadScheduler) { sceneDesc.flags |= NX_SF_ENABLE_MULTITHREAD; sceneDesc.customScheduler = &gCustomScheduler; gCustomScheduler.CreateThreads(2); } else if (gbThreadPolling) { sceneDesc.flags |= NX_SF_ENABLE_MULTITHREAD; } else if (gbThreadSDKManage) { sceneDesc.flags |= NX_SF_ENABLE_MULTITHREAD; sceneDesc.internalThreadCount = 2; } else if (gbNoThread) { sceneDesc.flags &= ~NX_SF_SIMULATE_SEPARATE_THREAD; } else assert(0); gScene = gPhysicsSDK->createScene(sceneDesc); if(0 == gScene) { sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(0 == gScene) return; } if (gbThreadPolling) { gPollingThreads.CreateThreads(2, gScene); // We must reset the polling threads so they are ready for the next run gPollingThreads.ResetPollForWork(); } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene groundPlane = CreateGroundPlane(); box = CreateBox(NxVec3(5,0,0), NxVec3(0.5,1,0.5), 20); sphere = CreateSphere(NxVec3(0,0,5), 1, 10); capsule = CreateCapsule(NxVec3(-5,0,0), 2, 0.5, 10); pyramid = CreateHalfPyramid(NxVec3(0,0,0), NxVec3(1,0.5,1.5), 10); gSelectedActor = pyramid; AddUserDataToActors(gScene); // Initialize HUD InitializeHUD(); // Start the first frame of the simulation if (gScene) StartPhysics(); }