void PhysicsServer::Init() { if (m_bInited) { return; } RemoveChildren(); m_Objects.clear(); dInitODE(); m_WorldID = dWorldCreate(); m_DefaultSpaceID = dHashSpaceCreate( NULL ); m_ContactGroupID = dJointGroupCreate( 0 ); dWorldSetAutoDisableFlag( m_WorldID, 1 ); dWorldSetAutoDisableAverageSamplesCount( m_WorldID, 1 ); if (m_WorldID) { SetERP( m_ERP ); SetCFM( m_CFM ); SetGravity( m_Gravity ); } m_pDefMaterial = g_pObjectServer->FindObject<PhysMaterial>( "defaullt_mtl", this ); if (!m_pDefMaterial) { m_pDefMaterial = new PhysMaterial(); m_pDefMaterial->SetName( "defaullt_mtl" ); AddChild( m_pDefMaterial ); } m_bInited = true; } // PhysicsServer::Init
int main (int argc, char **argv) { // setup pointers to drawstuff callback functions dsFunctions fn; fn.version = DS_VERSION; fn.start = &start; fn.step = &simLoop; fn.command = &command; fn.stop = 0; fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; if(argc==2) { fn.path_to_textures = argv[1]; } // create world dInitODE2(0); world = dWorldCreate(); space = dHashSpaceCreate (0); contactgroup = dJointGroupCreate (0); dWorldSetGravity (world,0,0,-GRAVITY); dWorldSetCFM (world,1e-5); dWorldSetAutoDisableFlag (world,1); #if 1 dWorldSetAutoDisableAverageSamplesCount( world, 10 ); #endif dWorldSetLinearDamping(world, 0.00001); dWorldSetAngularDamping(world, 0.005); dWorldSetMaxAngularSpeed(world, 200); dWorldSetContactMaxCorrectingVel (world,0.1); dWorldSetContactSurfaceLayer (world,0.001); dCreatePlane (space,0,0,1,0); memset (obj,0,sizeof(obj)); // run simulation dsSimulationLoop (argc,argv,352,288,&fn); dJointGroupDestroy (contactgroup); dSpaceDestroy (space); dWorldDestroy (world); dCloseODE(); return 0; }
int main (int argc, char **argv) { printf("ODE configuration: %s\n", dGetConfiguration()); // Is trimesh support built into this ODE? g_allow_trimesh = dCheckConfiguration( "ODE_EXT_trimesh" ); // setup pointers to drawstuff callback functions dsFunctions fn; fn.version = DS_VERSION; fn.start = &start; fn.step = &simLoop; fn.command = &command; fn.stop = 0; fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; // create world dInitODE2(0); world = dWorldCreate(); space = dHashSpaceCreate (0); contactgroup = dJointGroupCreate (0); dWorldSetGravity (world,0,0,-0.05); dWorldSetCFM (world,1e-5); dWorldSetAutoDisableFlag (world,1); dWorldSetContactMaxCorrectingVel (world,0.1); dWorldSetContactSurfaceLayer (world,0.001); memset (obj,0,sizeof(obj)); #if 1 dWorldSetAutoDisableAverageSamplesCount( world, 1 ); #endif // base plane to catch overspill dCreatePlane( space, 0, 0, 1, 0 ); // our heightfield floor dHeightfieldDataID heightid = dGeomHeightfieldDataCreate(); // Create an finite heightfield. dGeomHeightfieldDataBuildCallback( heightid, NULL, heightfield_callback, HFIELD_WIDTH, HFIELD_DEPTH, HFIELD_WSTEP, HFIELD_DSTEP, REAL( 1.0 ), REAL( 0.0 ), REAL( 0.0 ), 0 ); // Give some very bounds which, while conservative, // makes AABB computation more accurate than +/-INF. dGeomHeightfieldDataSetBounds( heightid, REAL( -4.0 ), REAL( +6.0 ) ); gheight = dCreateHeightfield( space, heightid, 1 ); dVector3 pos; pos[ 0 ] = 0; pos[ 1 ] = 0; pos[ 2 ] = 0; // Rotate so Z is up, not Y (which is the default orientation) dMatrix3 R; dRSetIdentity( R ); dRFromAxisAndAngle( R, 1, 0, 0, DEGTORAD * 90 ); // Place it. dGeomSetRotation( gheight, R ); dGeomSetPosition( gheight, pos[0], pos[1], pos[2] ); // run simulation dsSimulationLoop (argc,argv,352,288,&fn); dJointGroupDestroy (contactgroup); dSpaceDestroy (space); dWorldDestroy (world); // destroy heightfield data, because _we_ own it not ODE dGeomHeightfieldDataDestroy( heightid ); dCloseODE(); return 0; }