static void LoadPlayGroundScene(DemoEntityManager* const scene, TriggerManager* const triggerManager) { NewtonWorld* const world = scene->GetNewton(); // CreateLevelMesh (scene, "flatPlane.ngd", true); // return; // make the body with a dummy null collision, so that we can use for attaching world objects dMatrix matrix (dGetIdentityMatrix()); NewtonCollision* const dommyCollision = NewtonCreateNull(world); NewtonBody* const playGroundBody = NewtonCreateDynamicBody (world, dommyCollision, &matrix[0][0]); NewtonDestroyCollision (dommyCollision); // use a multi shape static scene collision NewtonCollision* const sceneCollision = NewtonCreateSceneCollision (world, 0); // start adding shapes to this scene collisions NewtonSceneCollisionBeginAddRemove (sceneCollision); // populate the scene collision { // load a flat floor LoadFloor(scene, sceneCollision); // load a slide platform dMatrix slideMatrix(dGetIdentityMatrix()); slideMatrix.m_posit.m_x += 80.0f; slideMatrix.m_posit.m_z = -20.0f; //LoadSlide(scene, triggerManager, sceneCollision, "slide.ngd", slideMatrix, playGroundBody); LoadFerryBridge(scene, triggerManager, sceneCollision, "platformBridge.ngd", slideMatrix, playGroundBody); // load another hanging bridge dMatrix bridgeMatrix(dGetIdentityMatrix()); bridgeMatrix.m_posit.m_x += 40.0f; LoadHangingBridge(scene, triggerManager, sceneCollision, "hangingBridge.ngd", bridgeMatrix, playGroundBody); // load another ferry bridge bridgeMatrix.m_posit.m_z += 20.0f; LoadFerryBridge(scene, triggerManager, sceneCollision, "platformBridge.ngd", bridgeMatrix, playGroundBody); } // finalize adding shapes to this scene collisions NewtonSceneCollisionEndAddRemove (sceneCollision); // attach this collision to the playground Body NewtonBodySetCollision(playGroundBody, sceneCollision); // set the reference to the visual //NewtonBodySetUserData(level, visualMesh); // do not forget to release the collision NewtonDestroyCollision (sceneCollision); }
Error PhysicsWorld::create(AllocAlignedCallback allocCb, void* allocCbData) { Error err = ErrorCode::NONE; m_alloc = HeapAllocator<U8>(allocCb, allocCbData); // Set allocators gAlloc = &m_alloc; NewtonSetMemorySystem(newtonAlloc, newtonFree); // Initialize world m_world = NewtonCreate(); if(!m_world) { ANKI_LOGE("NewtonCreate() failed"); return ErrorCode::FUNCTION_FAILED; } // Set the simplified solver mode (faster but less accurate) NewtonSetSolverModel(m_world, 1); // Create scene collision m_sceneCollision = NewtonCreateSceneCollision(m_world, 0); Mat4 trf = Mat4::getIdentity(); m_sceneBody = NewtonCreateDynamicBody(m_world, m_sceneCollision, &trf[0]); NewtonBodySetMaterialGroupID(m_sceneBody, NewtonMaterialGetDefaultGroupID(m_world)); NewtonDestroyCollision(m_sceneCollision); // destroy old scene m_sceneCollision = NewtonBodyGetCollision(m_sceneBody); // Set the post update listener NewtonWorldAddPostListener(m_world, "world", this, postUpdateCallback, destroyCallback); // Set callbacks NewtonMaterialSetCollisionCallback(m_world, NewtonMaterialGetDefaultGroupID(m_world), NewtonMaterialGetDefaultGroupID(m_world), nullptr, onAabbOverlapCallback, onContactCallback); return err; }
void SceneCollision (DemoEntityManager* const scene) { NewtonWorld* world = scene->GetNewton(); // add the Sky scene->CreateSkyBox(); // create a body and with a scene collision NewtonCollision* const sceneCollision = NewtonCreateSceneCollision (scene->GetNewton(), 0); // create a visual scene empty mesh ComplexScene* const visualMesh = new ComplexScene(sceneCollision); scene->Append (visualMesh); // add some shapes visualMesh->AddPrimitives(scene); // this is optional, finish the scene construction, optimize the collision scene dMatrix matrix (dGetIdentityMatrix()); // create the level body and add it to the world NewtonBody* const level = NewtonCreateDynamicBody (world, sceneCollision, &matrix[0][0]); // replace the collision with the newly created one the visualMesh->m_sceneCollision = NewtonBodyGetCollision(level); // set the reference to the visual NewtonBodySetUserData(level, visualMesh); // do not forget to release the collision NewtonDestroyCollision (sceneCollision); // add few objects int defaultMaterialID = NewtonMaterialGetDefaultGroupID (world); NewtonMaterialSetCollisionCallback (world, defaultMaterialID, defaultMaterialID, OnBodyAABBOverlap, OnContactCollision); NewtonMaterialSetCompoundCollisionCallback(world, defaultMaterialID, defaultMaterialID, OnSubShapeAABBOverlapTest); dVector location (0.0f, 0.0f, 0.0f, 0.0f); dVector size (0.5f, 0.5f, 0.5f, 0.0f); dMatrix shapeOffsetMatrix (dGetIdentityMatrix()); int count = 5; AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _SPHERE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _BOX_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _CHAMFER_CYLINDER_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _CONE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _CAPSULE_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _RANDOM_CONVEX_HULL_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); AddPrimitiveArray(scene, 10.0f, location, size, count, count, 1.7f, _COMPOUND_CONVEX_CRUZ_PRIMITIVE, defaultMaterialID, shapeOffsetMatrix); dMatrix camMatrix (dRollMatrix(-20.0f * 3.1416f /180.0f) * dYawMatrix(-45.0f * 3.1416f /180.0f)); dQuaternion rot (camMatrix); dVector origin (-15.0f, 5.0f, 0.0f, 0.0f); scene->SetCameraMatrix(rot, origin); }
dNewtonCollisionScene::dNewtonCollisionScene(dNewtonWorld* const world) :dNewtonCollision(world, 0) { NewtonWaitForUpdateToFinish(m_myWorld->m_world); SetShape(NewtonCreateSceneCollision(m_myWorld->m_world, 0)); }