int main (int argc, char* argv[]) { _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF)); // initialize graphics system if (!InitGraphicsSystem (800, 600)) { exit (0); } // set a callback for destroying the world ate termination atexit (ShutDown); // Create a Simple Scene Manager g_sceneManager = new SceneManager(); // set the memory allocators NewtonSetMemorySystem (AllocMemory, FreeMemory); // create the Newton World g_world = NewtonCreate (); // use the standard x87 floating point model NewtonSetPlatformArchitecture (g_world, 0); // set a fix world size // dVector minSize (-500.0f, -500.0f, -500.0f); // dVector maxSize ( 500.0f, 500.0f, 500.0f); // NewtonSetWorldSize (g_world, &minSize[0], &maxSize[0]); // initialize Newton Visual Debugger #ifdef USE_VISUAL_DEBUGGER g_newtonDebugger = NewtonDebuggerCreateServer (); #endif // configure the Newton world to use iterative solve mode 0 // this is the most efficient but the less accurate mode NewtonSetSolverModel (g_world, 1); // now populate the world with Graphic and physical entities CreateScene(g_world, g_sceneManager); // run the main application loop until the user terminate the app for (;;) { // Draw the screen. AdvanceSimulation (GetTimeInMicrosenconds ()); } // Never reached. return 0; }
virtual bool OnInit() { if (!wxApp::OnInit()) return false; // check for memory leaks #if defined(_DEBUG) && defined(_MSC_VER) // Track all memory leaks at the operating system level. // make sure no Newton tool or utility leaves leaks behind. _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF)); #endif // wxJoystick stick(wxJOYSTICK1); // if (!stick.IsOk()) { // wxMessageBox(wxT("No joystick detected!")); // return false; // } // Set the memory allocation function before creation the newton world // this is the only function that can be called before the creation of the newton world. // it should be called once, and the the call is optional NewtonSetMemorySystem (PhysicsAlloc, PhysicsFree); int version = NewtonWorldGetVersion(); wxString title; title.Printf (wxT ("Newton %d.%02d SDK demos"), version / 100, version % 100); NewtonDemos* const frame = new NewtonDemos(title, wxDefaultPosition, wxSize(DEMO_WIDTH, DEMO_HEIGHT)); frame->Show(true); SetTopWindow(frame); // initialize opengl graphics if (frame->m_scene) { frame->m_scene->InitGraphicsSystem(); } // load the default Scene wxMenuEvent loadDemo (wxEVT_COMMAND_MENU_SELECTED, NewtonDemos::ID_RUN_DEMO + DEFAULT_SCENE); frame->GetEventHandler()->ProcessEvent(loadDemo); // select solve mode wxMenuEvent solverMode (wxEVT_COMMAND_MENU_SELECTED, NewtonDemos::ID_SOLVER_MODE + 3); frame->GetEventHandler()->ProcessEvent(solverMode); return true; }
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; }
bool NewtonModelEditorApp::OnInit() { // check for memory leaks #if defined(_DEBUG) && defined(_MSC_VER) // Track all memory leaks at the operating system level. // make sure no Newton tool or utility leaves leaks behind. _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF)); #endif // Set the memory allocation function before creation the newton world // this is the only function that can be called before the creation of the newton world. // it should be called once, and the the call is optional NewtonSetMemorySystem (PhysicsAlloc, PhysicsFree); // int version = NewtonWorldGetVersion(); // wxString tittle; // tittle.Printf (wxT ("Newton %d.%02d SDK demos"), version / 100, version % 100); NewtonModelEditor* const frame = new NewtonModelEditor (APPLICATION_NAME, wxDefaultPosition, wxSize(1280, 960)); frame->Show(true); SetTopWindow(frame); return true; }
// Set allocators void World::SetAllocators (NewtonAllocMemory newtonAlloc, NewtonFreeMemory newtonFree) { NewtonSetMemorySystem (newtonAlloc, newtonFree); }
iPhysics::iPhysics() { NewtonSetMemorySystem(AllocMemory, FreeMemory); createDefaultWorld(); createDefaultMaterial(); }