void RenderCallback() { // Clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ProcessCameraKeys(); SetupCamera(); if (gScene && !bPause) { GetPhysicsResults(); ProcessInputs(); StartPhysics(); } // Display scene RenderActors(bShadows); if (bForceMode) DrawForce(gSelectedActor, gForceVec, NxVec3(1,1,0)); else DrawForce(gSelectedActor, gForceVec, NxVec3(0,1,1)); gForceVec = NxVec3(0,0,0); // Render HUD hud.Render(); glFlush(); glutSwapBuffers(); }
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 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 RenderCallback() { // Clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ProcessCameraKeys(); SetupCamera(); UpdateEmitterPosition(); if (gScene && !bPause) { GetPhysicsResults(); ProcessInputs(); StartPhysics(); } // Display scene RenderActors(bShadows); RenderFluid(); if (bForceMode) DrawForce(gSelectedActor, gForceVec, NxVec3(1,1,0)); else DrawForce(gSelectedActor, gForceVec, NxVec3(0,1,1)); gForceVec = NxVec3(0,0,0); if (bEmitterWireframe) { NxMat34 fluidEmitterMat = fluidEmitter->getGlobalPose(); NxVec3 fluidEmitterPos, fluidEmitterDir; fluidEmitterPos = fluidEmitterMat.t; fluidEmitterMat.M.getColumn(2,fluidEmitterDir); DrawArrow(fluidEmitterPos, fluidEmitterPos + fluidEmitterDir, NxVec3(0,0,1)); DrawEllipse(20, fluidEmitter->getGlobalPose(), NxVec3(0.5,0,0.5), fluidEmitter->getDimensionX(), fluidEmitter->getDimensionY()); } if (!bPause) { if (gDeltaTime < 10) gTotalTime += gDeltaTime; } // Render HUD hud.Render(); glFlush(); glutSwapBuffers(); }
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(); }
void RenderCallback() { // Clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ProcessCameraKeys(); SetupCamera(); if (gScene && !bPause) { GetPhysicsResults(); ProcessInputs(); StartPhysics(); } // Display scene RenderActors(bShadows); // Display kernel Info if (gForceField) { if (gForceField->getForceFieldKernel() == gCustomKernel) { hud.SetDisplayString(2, "Using CustomKernel", 0.14f, 0.92f); } else if (gForceField->getForceFieldKernel() == gLinearKernel) { hud.SetDisplayString(2, "Using LinearKernel", 0.14f, 0.92f); } } // Render the HUD hud.Render(); glFlush(); glutSwapBuffers(); }
void RenderCallback() { if (gScene && !bPause) { StartPhysics(); GetPhysicsResults(); } // Clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ProcessInputs(); ProcessCameraKeys(); SetupCamera(); RenderActors(bShadows); // Render all the cloths in the scene for (MyCloth **cloth = gCloths.begin(); cloth != gCloths.end(); cloth++) { glColor4f(1.0f, 0.0f, 0.0f,1.0f); (*cloth)->draw(bShadows); } if (bForceMode) DrawForce(gSelectedActor, gForceVec, NxVec3(1,1,0)); else DrawForce(gSelectedActor, gForceVec, NxVec3(0,1,1)); gForceVec = NxVec3(0,0,0); // Render HUD hud.Render(); glFlush(); glutSwapBuffers(); }
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(); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Initialize physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.05); gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 10); //gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_POSITION, 1); //gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_VELOCITY, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_PACKETS, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_DRAINS, 1); // Create a 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); // Initialize cooking NxInitCooking(NULL, &gErrorStream); // Load ASE files int set = 0; #ifdef WIN32 set = SetCurrentDirectory(&fname[0]); if (!set) set = SetCurrentDirectory(&fname1[0]); if (!set) set = SetCurrentDirectory(&fname2[0]); if (!set) set = SetCurrentDirectory(&fname3[0]); if (!set) { char basePath[256]; GetModuleFileName(NULL, basePath, 256); char* pTmp = strrchr(basePath, '\\'); basePath[pTmp-basePath+1] = 0; SetCurrentDirectory(basePath);//for running from start menu set = SetCurrentDirectory(&fname2[0]); } #elif LINUX set = chdir(&fname[0]); if (set != 0) set = chdir(&fname2[0]); if (set != 0) set = chdir(&fname3[0]); #endif bowl = CookASE("fluidSample.ase", gScene, NxVec3(1,0,0)); flume = CookASE("coolFlow.ase", gScene, NxVec3(1,-4,-0), NxVec3(1,0.2,1)); box = CreateBox(NxVec3(2,5-0.75,7), NxVec3(0.75,0.75,0.75), 1); sphere = CreateSphere(NxVec3(0,4-0.4,1), 0.4, 1); capsule = CreateCapsule(NxVec3(3,0-(1+0.5),8), 1, 1, 1); CreateBox(NxVec3(0,-10-1,0), NxVec3(40,1,40), 0); fluid = CreateFluid(NxVec3(0,1.5,0), 19, 0.1, gScene); AddUserDataToActors(gScene); //((ActorUserData*)(drain->userData))->flags |= UD_IS_DRAIN; // Page in the hardware meshes if(bHardwareScene) PageInHardwareMeshes(gScene); gSelectedActor = box; // 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(); }
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() { // 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(); }
/*********************************************************** init function ***********************************************************/ void PhysXEngine::Init() { // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); if (!gPhysicsSDK) return; if (gPhysicsSDK->getFoundationSDK().getRemoteDebugger()) gPhysicsSDK->getFoundationSDK().getRemoteDebugger()->connect("localhost", 5425); // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01f); // 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.simType = NX_SIMULATION_SW; sceneDesc.gravity = NxVec3(0,-9.8f,0); 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); // add a cube and a plane //CreatePlane(NxVec3(0, 0, 0), NxVec3(0, 1, 0)); CreateBox(NxVec3(0, 4, 0), 3.0f, 3.0f, 3.0f, 10, false); CreateBox(NxVec3(7, 10, 7), 2.0f, 3.0f, 2.0f, 10, true); CreateBox(NxVec3(20, 1, 20), 30.0f, 1.0f, 30.0f, 10, false); // init time _lasttime = SynchronizedTimeHandler::getInstance()->GetCurrentTimeDouble(); // init character controllers gManager = NxCreateControllerManager(gAllocator); //float TimeStep = 1.0f / 60.0f; gScene->setTiming(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void InitNx() { // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, &gErrorStream); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.05); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); // gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_AXES, 1); // gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_CONTACT_POINT, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_CONTACT_NORMAL, 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; } NxU32 set = 0; #ifdef WIN32 set = SetCurrentDirectory(&fname[0]); if (!set) set = SetCurrentDirectory(&fname1[0]); if (!set) { char basePath[256]; GetModuleFileName(NULL, basePath, 256); char* pTmp = strrchr(basePath, '\\'); basePath[pTmp-basePath+1] = 0; SetCurrentDirectory(basePath);//for running from start menu set = SetCurrentDirectory(&fname2[0]); } if (!set) set = SetCurrentDirectory(&fname3[0]); #elif LINUX set = chdir(&fname[0]); if (set != 0) set = chdir(&fname2[0]); if (set != 0) set = chdir(&fname3[0]); #endif // Create the default material NxMaterialDesc defaultMaterial; defaultMaterial.restitution = 0; defaultMaterial.staticFriction = 0.5; defaultMaterial.dynamicFriction = 0.5; NxMaterial* m = gScene->getMaterialFromIndex(0); m->loadFromDesc(defaultMaterial); char buffer[512]; FindMediaFile("Course.pml", buffer); nxmlLoadScene(buffer, gPhysicsSDK, gScene); // Switch from Max Coordinate System to // Training Program Coordinate System NxMat34 mat; NxMat33 orient; orient.setColumn(0, NxVec3(-1,0,0)); orient.setColumn(1, NxVec3(0,0,1)); orient.setColumn(2, NxVec3(0,1,0)); mat.M = orient; SwitchCoordinateSystem(gScene, mat); // Reset wheel material wsm = NULL; // Create the trike actor trike = CreateTrike(NxVec3(0,3,0)); trike->wakeUp(1e30); AddUserDataToActors(gScene); gSelectedActor = trike; // Initialize HUD InitializeHUD(); InitializeSpecialHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }