예제 #1
0
ODEDomain::ODEDomain(char const *space_type, Input *input) : BaseDomain(input)
{
    printf("ODEDomain constructor\n");   
    dInitODE();
    world = dWorldCreate();
    contactgroup = dJointGroupCreate (0);
           
    //dWorldSetAutoDisableFlag(world,1);
    
    //dWorldSetCFM(world,1e-5);
    //Set and get the global CFM (constraint force mixing) value. Typical values are in the range 10-9 -- 1. The default is 10-5 if single precision is being used, or 10-10 if double precision is being used.
    
    //TODO HERE HAS TO BE ANOTHER PARAMETR
    //dWorldSetContactSurfaceLayer(world,0.001);

    //dWorldSetQuickStepNumIterations (world,ITERS);
    
    dRandSetSeed (time(NULL));
    setGravity(m_input->gravity_v[0],m_input->gravity_v[1],m_input->gravity_v[2]);

    if (space_type == std::string("quad"))
    {
        dVector3 Center = {boundaries[0][0]+delta[0]*0.5, boundaries[1][0]+delta[1]*0.5, boundaries[2][0]+delta[2]*0.5, 0};
        dVector3 Extents = {delta[0] * 0.55, delta[1] * 0.55, delta[2] * 0.55, 0};                
        printf(":::: Using Quad Tree Space\n");
        space = dQuadTreeSpaceCreate (0, Center, Extents, 6);        
    }
    else if (space_type == std::string("hash"))
    {                
        printf(":::: Using Hash Space\n");
        space = dHashSpaceCreate (0);
        //dHashSpaceSetLevels (space,-10,10);
    }
    else if (space_type == std::string("sap")) 
    {
        printf(":::: Using Sweep And Prune Space\n");
        space = dSweepAndPruneSpaceCreate (0, dSAP_AXES_XYZ);
    }
    else if (space_type == std::string("simple")) 
    {
        printf(":::: Using Simple Space\n");
        space = dSimpleSpaceCreate(0);
    }

    if (!space) 
    {
        printf(":::: Using Sweep And Prune Space\n");
        space = dSweepAndPruneSpaceCreate (0, dSAP_AXES_XYZ);            
    }
    
    //TODO redo tests
    //I did tests: deposition of 10000 particles without& (~catBits[PARTICLES])& (~catBits[PARTICLES]) collisions.
    //SWAP: 6 sec
    //HASH: 7.15 sec
    //QUAD: 41.8 sec
    //SIMLE: 59 sec
    
    printf("ODE conf: %s", dGetConfiguration());      
    printf("\n:::: sizeof(dReal)=%lu\n\n", sizeof(dReal));
}
bool OdeSdlSimulationBundle::onBegin() {
    dInitODE2(0); 
    yDebug("\nODE configuration: %s\n\n", dGetConfiguration());
    return true;
}
예제 #3
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;
}