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/textures";

  // create world

  world = dWorldCreate();
  space = dHashSpaceCreate (0);
  contactgroup = dJointGroupCreate (0);
  dWorldSetGravity (world,0,0,-0.5);
  dWorldSetCFM (world,1e-5);
  dWorldSetAutoDisableFlag (world,1);
  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);

  return 0;
}
Exemplo n.º 2
0
// Called by Physics::Server when the Level is attached to the server.
void CLevel::Activate()
{
	TimeToSim = 0.0;

	// Initialize ODE //???per-Level?
	dInitODE();
	ODEWorldID = dWorldCreate();
	dWorldSetQuickStepNumIterations(ODEWorldID, 20);

	// FIXME(enno): is a quadtree significantly faster? -- can't count geoms with quadtree
	ODECommonSpaceID  = dSimpleSpaceCreate(NULL);
	ODEDynamicSpaceID = dSimpleSpaceCreate(ODECommonSpaceID);
	ODEStaticSpaceID  = dSimpleSpaceCreate(ODECommonSpaceID);

	dWorldSetGravity(ODEWorldID, Gravity.x, Gravity.y, Gravity.z);
	dWorldSetContactSurfaceLayer(ODEWorldID, 0.001f);
	dWorldSetContactMaxCorrectingVel(ODEWorldID, 100.0f);
	dWorldSetERP(ODEWorldID, 0.2f);     // ODE's default value
	dWorldSetCFM(ODEWorldID, 0.001f);    // the default is 10^-5

	// setup autodisabling
	dWorldSetAutoDisableFlag(ODEWorldID, 1);
	dWorldSetAutoDisableSteps(ODEWorldID, 5);
	//dWorldSetAutoDisableTime(ODEWorldID, 1.f);
	dWorldSetAutoDisableLinearThreshold(ODEWorldID, 0.05f);   // default is 0.01
	dWorldSetAutoDisableAngularThreshold(ODEWorldID, 0.1f);  // default is 0.01

	// create a Contact group for joints
	ContactJointGroup = dJointGroupCreate(0);
}
Exemplo n.º 3
0
void HarrierSim::start2()
{
  //        setDrawStuff();
  world = dWorldCreate();
  space = dHashSpaceCreate(0);
  contactgroup = dJointGroupCreate(0);
  ground = dCreatePlane(space, 0, 0, 1, 0);
  dWorldSetGravity(world,0,0,-0.5);

  dWorldSetCFM (world,1e-6);
  dWorldSetERP (world,1);
  //dWorldSetAutoDisableFlag (world,1);
  dWorldSetContactMaxCorrectingVel (world,0.1);
  //set the contact penetration
  dWorldSetContactSurfaceLayer(world, 0.001);


  makeHarrier();

  itsHarrierObject = vp->load3DSObject("./etc/spaceship.3ds", "./etc/textures/spaceshiptexture.ppm");
  itsHarrierObject.scale = 0.1;


  //set the viewpoint
  double xyz[3] = {0 , 25.0, 20};
  double hpr[3] = {-90.0,-35,0.0};
  vp->dsSetViewpoint (xyz,hpr);
  vp->setZoom(1.5);

}
Exemplo n.º 4
0
CPhysicManager::CPhysicManager(IEngine* _Engine):CBaseObject(_Engine){

    SetParam("BaseClass","PhysicManager");
    SetParam("Type","CPhysicManager");
    SetParam("Name","-");

	dSetErrorHandler (SilenceMessage); //затыкаем рот идиотским ошибкам
    dSetDebugHandler (SilenceMessage); //затыкаем рот идиотским ошибкам
    dSetMessageHandler (SilenceMessage); //затыкаем рот идиотским ошибкам


    calc_time= 0.0f;

	world = dWorldCreate();
	dWorldSetGravity(world, 0, 0, -0.01 );
	space=dHashSpaceCreate(0);
	contactgroup = dJointGroupCreate(0);

    LOGGER->LogMsg("+CPhysicManager");

    ptr_world = world;
    ptr_contactgroup = contactgroup;

    dWorldSetCFM(world, 1e-5);
    dWorldSetERP(world, 0.2);
    dWorldSetContactMaxCorrectingVel(world, 0.9);
    dWorldSetContactSurfaceLayer(world, 0.001);
    dWorldSetAutoDisableFlag(world, 1);

//    ground =

#define SHIRINA 1000

    //dGeomID tmp = dCreateBox( space, SHIRINA, SHIRINA, 1);
    //dGeomSetPosition(tmp, SHIRINA/2, SHIRINA/2, 0); // двигаем центр координат

    //tmp = dCreateBox( space, 1, SHIRINA, SHIRINA);
    //dGeomSetPosition(tmp, 0, SHIRINA/2, SHIRINA/2); // двигаем центр координат

    //tmp = dCreateBox( space, SHIRINA, 1, SHIRINA);
    //dGeomSetPosition(tmp, SHIRINA/2, 0, SHIRINA/2); // двигаем центр координат

    dCreatePlane (space,0,0,1,0);

    //dCreatePlane (space,1,1,0,0);

    //dCreatePlane (space,0,1,0,0);
    //dCreatePlane (space,1,0,0,0);

    //dCreatePlane (space,0,0,20,0);
    //dCreatePlane (space,0,10,0,0);
    //dCreatePlane (space,10,0,0,0);

    //dCreatePlane (space,0,0,1,0);
    //dCreatePlane (space,0,0,1,0);
    //dCreatePlane (space,0,0,1,0);
    //dCreatePlane (space,0,0,1,0);
    //dCreatePlane (space,0,0,1,0);

};
Exemplo n.º 5
0
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;

    // create world
    dInitODE();
    world = dWorldCreate();

#if 1
    space = dHashSpaceCreate (0);
#elif 0
    dVector3 center = {0,0,0}, extents = { 100, 100, 100};
    space = dQuadTreeSpaceCreate(0, center, extents, 5);
#elif 0
    space = dSweepAndPruneSpaceCreate (0, dSAP_AXES_XYZ);
#else
    space = dSimpleSpaceCreate(0);
#endif

    contactgroup = dJointGroupCreate (0);
    dWorldSetGravity (world,0,0,-0.5);
    dWorldSetCFM (world,1e-5);
    
    dWorldSetLinearDamping(world, 0.00001);
    dWorldSetAngularDamping(world, 0.005);
    dWorldSetMaxAngularSpeed(world, 200);

    dWorldSetContactSurfaceLayer (world,0.001);
    ground = dCreatePlane (space,0,0,1,0);
    
    memset (obj,0,sizeof(obj));

    // create lift platform
    platform = dCreateBox(space, 4, 4, 1);

    dGeomSetCategoryBits(ground, 1ul);
    dGeomSetCategoryBits(platform, 2ul);
    dGeomSetCollideBits(ground, ~2ul);
    dGeomSetCollideBits(platform, ~1ul);

    // run simulation
    dsSimulationLoop (argc,argv,352,288,&fn);

    dJointGroupDestroy (contactgroup);
    dSpaceDestroy (space);
    dWorldDestroy (world);
    dCloseODE();
    return 0;
}
Exemplo n.º 6
0
void initWorldModelling(int testcase)
{
    /* create world */
    dRandSetSeed(1);
    dInitODE();
    //dInitODE2(dInitFlagManualThreadCleanup);
    //dAllocateODEDataForThread(dAllocateMaskAll);
    world = dWorldCreate();
    space = dHashSpaceCreate (0);

    //dWorldSetAutoDisableFlag(World, 1);

    // The parameter needs to be zero.
    contactgroup = dJointGroupCreate (0);
    dWorldSetGravity (world,0,-9.81f,0);
    dWorldSetCFM (world,1e-2f);   //1e-5f was the originally value used.
    dWorldSetERP(world,1.0f);   // 1 is Error Correction is applied.

    // Set Damping
    dWorldSetLinearDamping(world, 0.01f);  // 0.00001
    dWorldSetAngularDamping(world, 0.005f);     // 0.005
    dWorldSetMaxAngularSpeed(world, 200);

    // Set and get the depth of the surface layer around all geometry objects. Contacts are allowed to sink into the surface layer up to the given depth before coming to rest. The default value is zero. Increasing this to some small value (e.g. 0.001) can help prevent jittering problems due to contacts being repeatedly made and broken.
    dWorldSetContactSurfaceLayer (world,0.001f);

    ground = dCreatePlane (space,0,1,0,0);



    switch(testcase)
    {
    case 1:initIslands();test1();break;// Carrier stability
    case 2:initIslands();test1();test2();break;// Manta landing on island.
    case 3:initIslands();test1();test2();test3();break;// Manta crashing on structure
    case 4:initIslands();test1();test2();test3();test4();break;// Manta landing on runway
    case 5:initIslands();test1();test2();break;// Manta landing on aircraft
    case 6:initIslands();test1();test6();break;// Carrier stranded on island
    case 7:test1();test2();test7();break; //Manta crashing on water.
    case 8:initIslands();test1();test8();break; // Walrus reaching island.
    case 9:test1();test9();break; // Walrus stability.
    case 10:initIslands();test1();test10();break; // Walrus arrive to island and build the command center.
    case 11:initIslands();test11();break; // Carrier stability far away.
    case 12:initIslands();test1();test12();break; // Bullets
    case 13:initIslands();test13();break;
    default:initIslands();test1();break;
    }

    testing = testcase;

}
Exemplo n.º 7
0
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;
}
        void PhysicalWorld::onInit()
        {
          InternalMessage("Physic","Physic::PhysicalWorld::onInit entering " +
                                   Kernel::toString(getObject()->getIdentifier())) ;

          Kernel::Log::Block temp("Physic","PhysicalWorld::onInit") ;
          m_world = new dWorld() ;

          dWorldSetCFM(m_world->id(),Kernel::Parameters::getValue<float>("Physic","WorldCFM")) ;
          dWorldSetERP(m_world->id(),Kernel::Parameters::getValue<float>("Physic","WorldERP")) ;
          dWorldSetContactSurfaceLayer(m_world->id(),Kernel::Parameters::getValue<float>("Physic","WorldContactSurfaceLayer")) ;
          dWorldSetContactMaxCorrectingVel(m_world->id(),Kernel::Parameters::getValue<float>("Physic","WorldContactMaxCorrectingVelocity")) ;

          m_collision_space = new dSimpleSpace(0) ;

          m_contact_group = dJointGroupCreate(0) ;
        }
Exemplo n.º 9
0
bool DynamicsSolver::Init( int spaceDim, Real spaceWidth, Real spaceHeight)
{
	Shutdown();
	spaceDim = 1;

	WorldID = dWorldCreate();
	DynamicSpaceID = dHashSpaceCreate(0);
	ActiveSpaceID  = dSimpleSpaceCreate(0);
	dSpaceSetCleanup ( ActiveSpaceID, 0 );
	dSpaceSetCleanup ( DynamicSpaceID, 0 );

	SpaceDim    = spaceDim;
	SpaceWidth  = spaceWidth;
	SpaceHeight = spaceHeight;

	nCachedConstructions = 0;
	

	StaticSpaceID  = new dSpaceID[spaceDim*spaceDim];
	SpaceDist = new int[spaceDim*spaceDim];
	for (int i=0; i<spaceDim*spaceDim; i++)
	{
		StaticSpaceID[i]  = dHashSpaceCreate(0);
		//dVector3 center = { spaceWidth*.5f, 0, spaceHeight*.5f, 1.0f };
		//dVector3 extent = { spaceWidth, 10000, spaceHeight, 1.0f };
		//StaticSpaceID[i] = dQuadTreeSpaceCreate(NULL, center, extent, 4);
		SpaceDist[i] = 0;
	}

	ContactGroup = dJointGroupCreate (0);
	dWorldSetGravity (WorldID,0,-90, 0);
	//dWorldSetERP (WorldID, 0.9 );
	dWorldSetContactSurfaceLayer (WorldID, .01);

	IsSetup = true;

	return true;
}
Exemplo n.º 10
0
OdeInit::OdeInit(RobotConfig *config) : mutex(1), robot_config(config)
{
    //create the world parameters
    world = dWorldCreate();
    space = dHashSpaceCreate (0);
    contactgroup = dJointGroupCreate (0);
    verbose = false;
    
    dWorldSetGravity (world,0,-9.8,0);
    dWorldSetERP(world, config->getWorldERP());   // error reduction parameter: in [0.1,0.8], the higher, the more springy constraints are
    dWorldSetCFM(world, config->getWorldCFM());  // constraint force mixing: in [1e-9,1], the higher, the softer constraints are

    // Maximum correcting velocity the contacts are allowed to generate. Default value is infinity.
    // Reducing it can help prevent "popping" of deeply embedded objects
    dWorldSetContactMaxCorrectingVel(world, config->getMaxContactCorrectingVel());
    
    // Contacts are allowed to sink into the surface layer up to the given depth before coming to rest. 
    // The default value is zero. Increasing this to some small value (e.g. 0.001) can help prevent jittering 
    // problems due to contacts being repeatedly made and broken. 
    dWorldSetContactSurfaceLayer(world, config->getContactSurfaceLayer());

    ground = dCreatePlane (space,0, 1, 0, 0);
    //feedback = new dJointFeedback;
    //feedback1 = new dJointFeedback;
    //feedback_mat = new dJointFeedback;
    _iCub = new ICubSim(world, space, 0,0,0, *robot_config);
    _wrld = new worldSim(world, space, 0,0,0, *robot_config);
    _controls = new iCubSimulationControl*[MAX_PART];
    
   
//     // info on spaces created - relevant in actSelfCol mode   
//     printf("ICubSim::init(): overview of the spaces created: \n");
//     std::string s("space"); 
//     printInfoOnSpace(space,s);
//     s="iCub";
//     printInfoOnSpace(_iCub->iCub,s);
//     s="iCubHeadSpace";
//     printInfoOnSpace(_iCub->iCubHeadSpace,s);
//     s="iCubTorsoSpace";
//     printInfoOnSpace(_iCub->iCubTorsoSpace,s);
//     s="iCubLeftArmSpace";
//     printInfoOnSpace(_iCub->iCubLeftArmSpace,s);
//     s="iCubRightArmSpace";
//     printInfoOnSpace(_iCub->iCubRightArmSpace,s);
//     s="iCubLegsSpace";
//     printInfoOnSpace(_iCub->iCubLegsSpace,s);
       
    // initialize at NULL
    for (int i=0; i<MAX_PART; i++) 
    {
        _controls[i] = NULL; 
    }
    
    _wrld->OBJNUM = 0;
    _wrld->waitOBJ = 0;
    _wrld->S_OBJNUM = 0;

    _wrld->SPHNUM = 0;
    _wrld->waitSPH = 0;
    _wrld->S_SPHNUM = 0;
    
    _wrld->cylOBJNUM = 0;
    _wrld->waitOBJ1 = 0;
    _wrld->S_cylOBJNUM = 0;

    _wrld->waitMOD = 0;
    _wrld->MODEL_NUM = 0;

    _wrld->s_waitMOD = 0;
    _wrld->s_MODEL_NUM = 0;
}
Exemplo n.º 11
0
//Assistance with ode from http://www.alsprogrammingresource.com/basic_ode.html
//and from the ODE user manual, not a lot of resources out there!
void initODE()
{
	int i;
	int j = 0;//For placing skyPanels
	int k = 0;//For placing sphere in box
	int q = 0;//For placing target boxes
	int r = 0;//For placing targetBoxes
	int s = 0;//FOr placing targetBoxes
	dReal radius = 0.5;//For sphere's in scene that bounce around/ get shot
	dMass m;//For mass of sphere
	dMass mp;//For mass of platform
	dMass md;//For mass of doorway
	dMass mpy;//For mass of pyramid
	dMass mbox;//For box of balls
	dMass msp;//For skyPanels
	dMass mtb;//For targetBox

	// Create a new, empty world and assign its ID number to World. Most applications will only need one world.
    world = dWorldCreate();

    // Create a new collision space and assign its ID number to Space, passing 0 instead of an existing dSpaceID.
    // There are three different types of collision spaces we could create here depending on the number of objects
    // in the world but dSimpleSpaceCreate is fine for a small number of objects. If there were more objects we
    // would be using dHashSpaceCreate or dQuadTreeSpaceCreate (look these up in the ODE d
    spacePhy = dSimpleSpaceCreate(0);

    // Create a joint group object and assign its ID number to contactgroup. dJointGroupCreate used to have a
    // max_size parameter but it is no longer used so we just pass 0 as its argument.
    contactgroup = dJointGroupCreate(0);

    //Set the gravity of the world where y is up
    dWorldSetGravity(world, 0, -0.1, 0);

    // These next two functions control how much error correcting and constraint force mixing occurs in the world.
    // Don't worry about these for now as they are set to the default values and we could happily delete them from
    // this example. Different values, however, can drastically change the behaviour of the objects colliding, so
    // I suggest you look up the full info on them in the ODE docs.
    dWorldSetERP(world, 0.2);
    dWorldSetCFM(world, 1e-5);

    // This function sets the velocity that inter-penetrating objects will separate at. The default value is infinity.
    dWorldSetContactMaxCorrectingVel(world, 0.9);

    // This function sets the depth of the surface layer around the world objects. Contacts are allowed to sink into
    // each other up to this depth. Setting it to a small value reduces the amount of jittering between contacting
    // objects, the default value is 0.
    dWorldSetContactSurfaceLayer(world, 0.0);

    // To save some CPU time we set the auto disable flag to 1. This means that objects that have come to rest (based
    // on their current linear and angular velocity) will no longer participate in the simulation, unless acted upon
    // by a moving object. If you do not want to use this feature then set the flag to 0. You can also manually enable
    // or disable objects using dBodyEnable and dBodyDisable, see the docs for more info on this.
    dWorldSetAutoDisableFlag(world, 1);

    //This brings us to the end of the world settings, now we have to initialize the objects themselves.

    //****************Ball 1
    // Create a new body for our object in the world and get its ID.
    ball_body = dBodyCreate(world);
    //Set ball1 geometries
    dMassSetZero(&ball_mass);
    dMassSetSphereTotal(&ball_mass, DENSITY, 2.0);
    dBodySetMass(ball_body, &ball_mass);

    ball_geom = dCreateSphere(spacePhy, radius);
    dGeomSetData(ball_geom, (void *)"ball");
    dGeomSetBody(ball_geom, ball_body);
    dBodyEnable(ball_body);
    //Next we set the position of the new body
	dBodySetPosition(ball_body, 5, 100, 15);

    //****************Ball 2
    // Create a new body for our object in the world and get its ID.
	ball_body2 = dBodyCreate(world);
	//Set ball1 geometries
	dMassSetZero(&ball_mass2);
	dMassSetSphereTotal(&ball_mass2, DENSITY, 2.0);
	dBodySetMass(ball_body2, &ball_mass2);

	ball_geom2 = dCreateSphere(spacePhy, radius);
	dGeomSetData(ball_geom2, (void *)"ball2");
	dGeomSetBody(ball_geom2, ball_body2);
	dBodySetGravityMode (ball_body2, 0);

    //******End of ball 2

	//*************Ball 3, a new way of creating a ball with physical properties
	ball_body3 = dBodyCreate(world);
	dMatrix3 R;

	dBodySetPosition(ball_body3, -5, 100, 15);
	dRFromAxisAndAngle(R, 1, 0, 0, -1.57);
	dBodySetRotation(ball_body3, R);

	// Here we use dMassSetSphere instead of dMassSetBox
	// and we pass the local radius variable as the third parameter
	dMassSetSphere(&m, DENSITY, radius);

	// To create the sphere object we use dCreateSphere and pass it the same local radius variable
	ball_geom3 = dCreateSphere(spacePhy, radius);
	dGeomSetBody(ball_geom3, ball_body3);
	dBodySetMass(ball_body3, &m);
    //*****End of ball3

	//*************Box o balls properties
    for (i = 0; i < 61; i++)
    {
    	// Create a new body for our object in the world and get its ID.
		balls_body[i] = dBodyCreate(world);
		//Set ball1 geometries
		dMassSetZero(&balls_mass[i]);
		dMassSetSphereTotal(&balls_mass[i], DENSITY, 2.0);
		dBodySetMass(balls_body[i], &balls_mass[i]);

		balls_geom[i] = dCreateSphere(spacePhy, radius);
		dGeomSetData(balls_geom[i], (void *)"ball");
		dGeomSetBody(balls_geom[i], balls_body[i]);
		dBodyDisable(balls_body[i]);//Disable bodies, enabled auto after hit
		//Box 1
		if (i <31)
		{
		     dBodySetPosition(balls_body[i], (-20), 28.5, 7.0);//(xpos b/w -20 and -12, ypos b/w 28 and 32, zpos between 0 and 16)
		}
			//Box 2
			if (i >= 31)
			{
				 dBodySetPosition(balls_body[i], (25), 38.5, -14.0);//(xpos b/w -20 and -12, ypos b/w 28 and 32, zpos between 0 and 16)
			}
		k++;
    }
	//******End of Box o Balls

	//**************platform geometries
	//create 5 platform's with physics things
	for (i = 0; i < 15; i++)
	{
		platform_body[i] = dBodyCreate(world);//Add the platform body to the world
		//Set the geom platform

		// Here we use dMassSetBox
		//set DENSITY to be very high to prevent it from being moved from balls
		dMassSetBox(&mp, DENSITY*1500,  4.5, 0.5, 18.0);

		//It works better if the invisible physics box is slightly larger than the object we're drawing
		platform_geom[i] = dCreateBox(spacePhy,  4.5, 0.5, 18.0);
		dGeomSetBody(platform_geom[i], platform_body[i]);
		dBodySetMass(platform_body[i], &mp);

		//Set/get whether the body is influenced by the world's gravity or not. If mode is nonzero it is, if mode is zero, it isn't. Newly created bodies are always influenced by the world's gravity.
		dBodySetGravityMode (platform_body[i], 0);
	}
    //*******End of platform geometries

	//*******Set the doorway properties, 18 platforms make all 3 doors
    for (i = 0; i < 18; i++)
    {
		doorway_body[i] = dBodyCreate(world);//Add the platform body to the world
		//Set the geom platform

		// Here we use dMassSetBox
		//set DENSITY to be very high to prevent it from being moved from balls
		dMassSetBox(&md, DENSITY*1500, 4.0, 0.25, 2.0);

		//It works better if the invisible physics box is slightly larger than the object we're drawing
		doorway_geom[i] = dCreateBox(spacePhy, 4.0, 0.25, 2.0);
		dGeomSetBody(doorway_geom[i], doorway_body[i]);
		dBodySetMass(doorway_body[i], &md);

		//Set/get whether the body is influenced by the world's gravity or not. If mode is nonzero it is, if mode is zero, it isn't. Newly created bodies are always influenced by the world's gravity.
		dBodySetGravityMode (doorway_body[i], 0);
    }
	//*******End of doorway properties

    //*******Set the Box o' Balls properties, 6 sides total make the larger box
    for (i = 0; i < 12; i++)
    {
         boxSide_body[i] = dBodyCreate(world);
    }

    //Box 1
    //Need to set position here to affect the box with gravity
    dBodySetPosition(boxSide_body[0], -20.0, 28.0, 16);//Front, rotated 0 deg. on y axis
    dBodySetPosition(boxSide_body[1], -12.25, 28.0, 8.0);//Right, rotated 90 deg. on y axis
    dBodySetPosition(boxSide_body[2], -20.0, 28.0, 0);//Back, rotated 0 deg. on y axis
    dBodySetPosition(boxSide_body[3], -27.75, 28.0, 8.0);//Left, rotated 90 deg. on y axis
    dBodySetPosition(boxSide_body[4], -20.0, 32.0, -0.23);//Top, rotated 90 deg. on x axis
    dBodySetPosition(boxSide_body[5], -20.0, 28.0, -0.23);//Bottom, rotated 90 deg. on x axis

    //Need to set position here to affect the box with gravity
    //Box 2
	dBodySetPosition(boxSide_body[6], 30.0, 38.0, -16);//Front, rotated 0 deg. on y axis
	dBodySetPosition(boxSide_body[7], 22.25, 38.0, -8.0);//Right, rotated 90 deg. on y axis
	dBodySetPosition(boxSide_body[8], 30.0, 38.0, 0);//Back, rotated 0 deg. on y axis
	dBodySetPosition(boxSide_body[9], 37.75, 38.0, -8.0);//Left, rotated 90 deg. on y axis
	dBodySetPosition(boxSide_body[10], 30.0, 42.0, -16.23);//Top, rotated 90 deg. on x axis*****Unsure about z here
	dBodySetPosition(boxSide_body[11], 30.0, 38.0, -16.23);//Bottom, rotated 90 deg. on x axis

	//Box 1
    for (i = 0; i < 6; i++)
	{
		if (i < 4)//Small sides
		{
			// Here we use dMassSetBox, we want a lower density here to be able to destroy the box
			dMassSetBox(&mbox, DENSITY, 16, 1, 0.25);

			//It works better if the invisible physics box is slightly larger than the object we're drawing
			boxSide_geom[i] = dCreateBox(spacePhy, 16, 1, 0.25);

			dGeomSetBody(boxSide_geom[i], boxSide_body[i]);
			dBodySetMass(boxSide_body[i], &mbox);
		}
		     if (i >=4)//Large top and bottom
		     {
		    	// Here we use dMassSetBox, we want a lower density here to be able to destroy the box
				dMassSetBox(&mbox, DENSITY, 16, 16, 0.5);

				//It works better if the invisible physics box is slightly larger than the object we're drawing
				boxSide_geom[i] = dCreateBox(spacePhy, 16, 16, 0.5);

				dGeomSetBody(boxSide_geom[i], boxSide_body[i]);
				dBodySetMass(boxSide_body[i], &mbox);
		     }
		//Turn off colliding object force effects on this geom so that it is stationary (less density = greater effect on objects colliding into this one)
		dBodyDisable(boxSide_body[i]);

		//Set/get whether the body is influenced by the world's gravity or not. If mode is nonzero it is, if mode is zero, it isn't. Newly created bodies are always influenced by the world's gravity.
		dBodySetGravityMode (boxSide_body[i], 1);
	}
    //Box 2
    for (; i < 12; i++)
	{
    	if (i < 10)//Small sides
		{
			// Here we use dMassSetBox, we want a lower density here to be able to destroy the box
			dMassSetBox(&mbox, DENSITY, 16, 1, 0.5);

			//It works better if the invisible physics box is slightly larger than the object we're drawing
			boxSide_geom[i] = dCreateBox(spacePhy, 16, 1, 0.5);

			dGeomSetBody(boxSide_geom[i], boxSide_body[i]);
			dBodySetMass(boxSide_body[i], &mbox);
		}
			 if (i >=10)//Large top and bottom
			 {
				// Here we use dMassSetBox, we want a lower density here to be able to destroy the box
				dMassSetBox(&mbox, DENSITY, 16, 16, 1.0);

				//It works better if the invisible physics box is slightly larger than the object we're drawing
				boxSide_geom[i] = dCreateBox(spacePhy, 16, 16, 1.0);

				dGeomSetBody(boxSide_geom[i], boxSide_body[i]);
				dBodySetMass(boxSide_body[i], &mbox);
			 }
		//Turn off colliding object force effects on this geom so that it is stationary (less density = greater effect on objects colliding into this one)
		dBodyDisable(boxSide_body[i]);

		//Set/get whether the body is influenced by the world's gravity or not. If mode is nonzero it is, if mode is zero, it isn't. Newly created bodies are always influenced by the world's gravity.
		dBodySetGravityMode (boxSide_body[i], 1);
	}
    //*******End of Box o' Balls properties

    //*******Set the pyramid properties, 120 pyramids make diamond excluding inverted that fill holes (gotta cheat)
	pyramid_body = dBodyCreate(world);//Add the platform body to the world
	//Set the geom platform

	// Here we use dMassSetBox
	//set DENSITY to be very high to prevent it from being moved from balls
	dMassSetBox(&mpy, DENSITY*1500, 2.6, 4.5, 2.6);

	//It works better if the invisible physics box is slightly larger than the object we're drawing
	pyramid_geom = dCreateBox(spacePhy, 2.6, 4.5, 2.6);
	dGeomSetBody(pyramid_geom, pyramid_body);
	dBodySetMass(pyramid_body, &mpy);
	dBodyDisable(pyramid_body);
	//Set/get whether the body is influenced by the world's gravity or not. If mode is nonzero it is, if mode is zero, it isn't. Newly created bodies are always influenced by the world's gravity.
	dBodySetGravityMode (pyramid_body, 0);
    //*******End of pyramid properties

	//*******skyPanels physics
    for(j = 0; j < 60; j++)
    {
		skyPanel_body[j] = dBodyCreate(world);//Add the skypanel body to the world
		//Set the geom skypanel
		// Here we use dMassSetBox
		//set DENSITY to be very high to prevent it from being moved from balls
		dMassSetBox(&msp, DENSITY*1500, 3.0, 7.0, 1.0);

		//It works better if the invisible physics box is slightly larger than the object we're drawing
		skyPanel_geom[j] = dCreateBox(spacePhy, 3.0, 7.0, 1.0);
		dGeomSetBody(skyPanel_geom[j], skyPanel_body[j]);//Bind the geom to the body so that we only need to place the body to also set the geom
		dBodySetMass(skyPanel_body[j], &msp);
		dBodyDisable(skyPanel_body[j]);
		//Set/get whether the body is influenced by the world's gravity or not. If mode is nonzero it is, if mode is zero, it isn't. Newly created bodies are always influenced by the world's gravity.
		dBodySetGravityMode (skyPanel_body[j], 0);//Gravity off
    }
	//*******End of skyPanels physics
    //*******Set targetBox physics
    for(q = 0; q < 114; q++)
	{
    	targetBox_body[q] = dBodyCreate(world);//Add the skypanel body to the world
    	//Set the geom target box
		// Here we use dMassSetBox
		dMassSetBox(&mtb, (0.05), 4.0, 4.0, 4.0);

		//It works better if the invisible physics box is slightly larger than the object we're drawing
		targetBox_geom[q] = dCreateBox(spacePhy, 4.0, 4.0, 4.0);
		dGeomSetBody(targetBox_geom[q], targetBox_body[q]);//Bind the geom to the body so that we only need to place the body to also set the geom
		dBodySetMass(targetBox_body[q], &mtb);
		dBodyDisable(targetBox_body[q]);
		//Set/get whether the body is influenced by the world's gravity or not. If mode is nonzero it is, if mode is zero, it isn't. Newly created bodies are always influenced by the world's gravity.
		dBodySetGravityMode (targetBox_body[q], 1);//Gravity on
		//Pile 1
		if(q < 22)
		{
		     dBodySetPosition(targetBox_body[q], (-60 + (s * 4)), (2 + r), -30);//Set position here, otherwise unaffected by gravity
		     s++;//update x axis
		     if (q == 8)
		     {
		    	 r += 4;
		    	 s = 0;
		     }
		        if (q == 14)
		        {
		        	r += 4;
		        	s = 0;
		        }
		            if (q == 18)
		            {
		            	r += 4;
		            	s = 0;
		            }
		                if (q == 20)
		                {
		                	r += 4;
		                	s = 0;
		                }
							//Reset values for next pile of boxes
							if (q == 21)
							{
								r = 0;
								s = 0;
							}
		}
		     //Pile 2
			 if((q > 21) && (q < 43))
		     {
		    	 dBodySetPosition(targetBox_body[q], (-30 + (s * 4)), (2 + r), 90);
		    	 s++;//Update x pos
		    	 if (q == 29)
				 {
					 r += 4;
					 s = 0;
				 }
					if (q == 35)
					{
						r += 4;
						s = 0;
					}
						if (q == 39)
						{
							r += 4;
							s = 0;
						}
							if (q == 41)
							{
								r += 4;
								s = 0;
							}
								//Reset values for next pile of boxes
								if (q == 42)
								{
									r = 0;
									s = 0;
								}
		     }
             //Pile 3
		     if((q > 42) && (q < 64))
			 {
				 dBodySetPosition(targetBox_body[q], (110), (2 + r), (0 + (s * 4)));
				 s++;//Update x pos
				 if (q == 50)
				 {
					 r += 4;
					 s = 0;
				 }
					if (q == 56)
					{
						r += 4;
						s = 0;
					}
						if (q == 60)
						{
							r += 4;
							s = 0;
						}
							if (q == 62)
							{
								r += 4;
								s = 0;
							}
								//Reset values for next pile of boxes
								if (q == 63)
								{
									r = 0;
									s = 0;
								}
			 }
				 //Pile 4
		         if((q > 63) && (q < 85))
				 {
					 dBodySetPosition(targetBox_body[q], (-90), (2 + r), (0 + (s * 4)));
					 s++;//Update x pos
					 if (q == 71)
					 {
						 r += 4;
						 s = 0;
					 }
						if (q == 77)
						{
							r += 4;
							s = 0;
						}
							if (q == 81)
							{
								r += 4;
								s = 0;
							}
								if (q == 83)
								{
									r += 4;
									s = 0;
								}
									//Reset values for next pile of boxes
									if (q == 84)
									{
										r = 0;
										s = 0;
									}
				 }
	     //Box tower 1
		 if((q > 84) && (q < 94))
		 {
			 dBodySetPosition(targetBox_body[q], (-60), (2 + r), (30));
			 r+=1;//Put boxes slightly inside each other
			 if (q == 93)
			 {
				 r = 0;//Reset r
			 }
		 }
			 //Box tower 2
			 if((q > 93) && (q < 104))
			 {
				 dBodySetPosition(targetBox_body[q], (70), (2 + r), (-90));
				 r+=1;//Put boxes slightly inside each other
				 if (q == 103)
				 {
					 r = 0;//Reset r
				 }
			 }
				 //Box tower 3
				 if((q > 103) && (q < 114))
				 {
					 dBodySetPosition(targetBox_body[q], (60), (2 + r), (90));
					 r+=1;//Put boxes slightly inside each other
					 if (q == 103)
					 {
						 r = 0;//Reset r
					 }
				 }
	}
    //*******End of targetBox Physics
    //Set the ground location:
	//First three param's set the normal vector, last param sets the distance according to the plane equation equation a*x+b*y+c*z=d and must have length 1
	ground = dCreatePlane(spacePhy, 0, 2.0, 0, 0);//Plane where I have most objects sitting, y =2

    // Here I have set the initial linear velocity to stationary and let gravity do the work on our spheres, but you can experiment
    // with the velocity vector to change the starting behavior. You can also set the rotational velocity for the new
    // body using dBodySetAngularVel which takes the same parameters.
    tempVect.x = 0.0;
    tempVect.y = 0.0;
    tempVect.z = 0.0;
    dBodySetLinearVel(ball_body, tempVect.x, tempVect.y, tempVect.z);
    dBodySetLinearVel(ball_body2, tempVect.x, tempVect.y, tempVect.z);
    dBodySetLinearVel(ball_body3, tempVect.x, tempVect.y, tempVect.z);

    dWorldSetLinearDamping(world, 0.00001);
    dWorldSetAngularDamping(world, 0.005);
    dWorldSetMaxAngularSpeed(world, 200);
}
Exemplo n.º 12
0
signed ODE_Init()
{
	Quit = SDL_FALSE;
	dInitODE2(dInitFlagManualThreadCleanup);
	dSetMessageHandler(Error);
	dSetDebugHandler(Error);
	dSetErrorHandler(Error);

	World = dWorldCreate();
	Space = dHashSpaceCreate(0);
	Group = dJointGroupCreate(0);
	Step = 1.0/50.0;

	lua_getglobal(State, "World");
	int table = lua_gettop(State);

	if (!lua_isnil(State, table))
	{
	 lua_pushnil(State);
	 while (lua_next(State, table))
	 {
		const char *key = lua_tostring(State, -2);
		#define tointeger lua_tointeger(State, -1)
		#define toboolean lua_toboolean(State, -1)
		#define tonumber  lua_tonumber(State, -1)

		if (!SDL_strcasecmp(key, "FPS"))
		{
		 Step = 1.0/tonumber;
		}
		else
		if (!SDL_strcasecmp(key, "ERP"))
		{
		 dWorldSetERP(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "CFM"))
		{
		 dWorldSetCFM(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "LINEAR_DAMPING"))
		{
		 dWorldSetLinearDamping(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "LINEAR_DAMPING_THRESHOLD"))
		{
		 dWorldSetLinearDampingThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "ANGULAR_DAMPING"))
		{
		 dWorldSetAngularDamping(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "ANGULAR_DAMPING_THRESHOLD"))
		{
		 dWorldSetAngularDampingThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "MAX_ANGULAR_SPEED"))
		{
		 dWorldSetMaxAngularSpeed(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "CONTACT_MAX_CORRECTING_VELOCITY"))
		{
		 dWorldSetContactMaxCorrectingVel(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "CONTACT_SURFACE_LAYER"))
		{
		 dWorldSetContactSurfaceLayer(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE"))
		{
		 dWorldSetAutoDisableFlag(World, toboolean);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_LINEAR_THRESHOLD"))
		{
		 dWorldSetAutoDisableLinearThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_ANGULAR_THRESHOLD"))
		{
		 dWorldSetAutoDisableAngularThreshold(World, tonumber);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_STEPS"))
		{
		 dWorldSetAutoDisableSteps(World, tointeger);
		}
		else
		if (!SDL_strcasecmp(key, "AUTO_DISABLE_TIME"))
		{
		 dWorldSetAutoDisableTime(World, tonumber);
		}
		else
		{
		 SDL_Log("World: %s does not match", key);
		}
		lua_pop(State, 1);
	 }
	}
	lua_pop(State, 1);

	Cond = SDL_CreateCond();
	if (!Cond)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_perror("SDL_CreateCond");
	 return SDL_SetError("cannot create simulation signal");
	}
	Mutex = SDL_CreateMutex();
	if (!Mutex)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_DestroyCond(Cond);
	 SDL_perror("SDL_CreateMutex");
	 return SDL_SetError("cannot create simulation mutex");
	}
	Thread = SDL_CreateThread(SimulationThread, "ODE", NULL);
	if (!Thread)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_DestroyCond(Cond);
	 SDL_DestroyMutex(Mutex);
	 SDL_perror("SDL_CreateThread");
	 return SDL_SetError("cannot create simulation thread");
	}
	TimerID = SDL_AddTimer(Uint32(1000*Step), SimulationTimer, NULL);
	if (!TimerID)
	{
	 dWorldDestroy(World);
	 dSpaceDestroy(Space);
	 dJointGroupDestroy(Group);
	 SDL_DestroyCond(Cond);
	 SDL_DestroyMutex(Mutex);
	 SDL_perror("SDL_AddTimer");
	 return SDL_SetError("cannot create simulation timer");
	}
	return 0;
}
Exemplo n.º 13
0
	void ODESimulator::initData(SimulatorData data)
	{
		Simulator::initData(data);

		// We can only init ODE once.
		if (0 == mInitCounter)
		{
			dInitODE();
		}
		++mInitCounter;

		// Create ODE world.
		mWorldID = dWorldCreate();

		// Set default gravity.
		setGravity(defaults::gravity);

		// Create the root ODE space.
		//mRootSpaceID = dSimpleSpaceCreate(0);
		//dVector3 center = {0, 0, 0};
		//dVector3 extents = {200, 100, 200};
		//mRootSpaceID = dQuadTreeSpaceCreate(0, center, extents, 5);

		if (data.useOctreeInsteadHash)
		{
			dVector3 center = { data.worldCenter[0],
			                    data.worldCenter[1],
			                    data.worldCenter[2] };
			dVector3 extents = { data.worldSize[0],
			                     data.worldSize[1],
			                     data.worldSize[2] };
			mRootSpaceID = dQuadTreeSpaceCreate(0, center, extents, data.octreeDepth);
		}
		else
		{
			mRootSpaceID = dHashSpaceCreate(0);
			dHashSpaceSetLevels(mRootSpaceID, data.hashMinLevel, data.hashMaxLevel);
		}

		mRootSpace = new ODESpace(mRootSpaceID);

		// Create the ODE contact joint group.
		mContactJointGroupID = dJointGroupCreate(0);

		// Set the ODE global CFM value that will be used by all Joints
		// (including contacts).  This affects normal Joint constraint
		// operation and Joint limits.  The user cannot adjust CFM, but
		// they can adjust ERP (a.k.a. bounciness/restitution) for materials
		// (i.e. contact settings) and Joint limits.
		dWorldSetCFM(mWorldID, defaults::ode::globalCFM);

		// Set the ODE global ERP value.  This will only be used for Joints
		// under normal conditions, not at their limits.  Also, it will not
		// affect contacts at all since they use material properties to
		// calculate ERP.
		dWorldSetERP(mWorldID, (real) 0.5 * (defaults::ode::maxERP +
		              defaults::ode::minERP));

		dWorldSetContactSurfaceLayer(mWorldID, defaults::ode::surfaceLayer);

		setSolverAccuracy(defaults::solverAccuracy);
		mCollisionCount = 0;
		// "mRaycastResult" is initialized in its own constructor.
		mSensorSolid = NULL;
		mRayContactGroup = defaults::shape::contactGroup;
	}
Exemplo n.º 14
0
SimWorld::SimWorld(QObject *parent) :
    QObject(parent)
{
  dInitODE();
  world = dWorldCreate();
  space = dHashSpaceCreate(0);
  contact_group = dJointGroupCreate(0);

  // Setup gravity
  dWorldSetGravity (world,0,0,-9.8);

  // Setup constraint satisfaction parameters.
  dWorldSetERP (world, 0.2); // How hard the world pushes to fix unsatisfied constraints
  dWorldSetCFM(world, 0.000001);  // Constraint force mixing
  dWorldSetContactSurfaceLayer(world,.005); // How deeply an object can penetrate (in meters)
  dWorldSetMaxAngularSpeed(world,15); // A hard limit on how fast anything can spin
  //dWorldSetLinearDamping(world,.02);  // Linear Friction
  //dWorldSetAngularDamping(world,.02); // Angular friction
  stepsize=1/60.0;

  // Create the ground plane
  ground_plane = dCreatePlane (space,0,0,1,0.0);


  body = new CapBody(this);
  body->createBody(world,space);

  marker_space = dSimpleSpaceCreate(0);
  target_space = dSimpleSpaceCreate(0);

  //
  //markData = new SwingData(world,markSpace,this);
  //markData = new LiveMarkerData(world,markSpace,this);
  std::cout << "[Simworld] Loading marker_data..." << std::endl;
#if defined( BOARD_DATA )
  markData = new BoardMarkerData(world,markSpace,this);
#elif defined( POKE_DATA )
  markData = new PokeMarkerData(world,markSpace,this);
#else
  marker_data = new MarkerData(world,marker_space,this);
#endif
  marker_data->body_pointer=body;
  body->changeMarkLinks(marker_data->marker_count);
  std::cout << "marker_data created/loaded" <<  std::endl;
#if defined( BOARD_DATA )
  board0 = dCreateBox(space,.5,.5,.05);
  board1 = dCreateBox(space,.5,.5,.05);

  dGeomSetPosition(board0,0,.5,0.025);
  dGeomSetPosition(board1,0,-.5,0.025);
#endif

  paused=true;
  single_step=false;

  angle_sequence = new Sequence(this);
  torque_sequence = new Sequence(this);

  self_collide=false;
  follow_sequence_source_state=0;

  ground_squish = .00001;
  ground_friction = 1;

  main_file = fopen("totals.txt","w");

}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
/*******************************************************************************
Function to initialize ODE.
*******************************************************************************/
void initODE()
{
	///////////////// Initializing the ODE general features ////////////////////

	dInitODE();								//Initialize library.
	World = dWorldCreate();					//Crate a new dynamics, empty world.
	Space = dSimpleSpaceCreate(0);			//Create a new space for collision (independent).
	ContactGroup = dJointGroupCreate(0);	//Create a joints container, without specifying size.

	dWorldSetGravity( World, 0.0, -9.81, 0 );	//Add gravity to this World.

	//Define error conrrection constants.
	dWorldSetERP( World, 0.2 );
	dWorldSetCFM( World, 1e-5 );

	//Set the velocity that interpenetrating objects will separate at.
	dWorldSetContactMaxCorrectingVel( World, 0.9 );

	//Set the safety area for contacts to be considered at rest.
	dWorldSetContactSurfaceLayer( World, 0.001 );

	//Automatically disable objects that have come to a rest.
	dWorldSetAutoDisableFlag( World, false );

	/////////////// Initializing the rigid bodies in the world /////////////////

	//Create a collision plane and add it to space. The next parameters are the
	//literal components of ax + by + cz = d.
	dCreatePlane( Space, 0.0, 1.0, 0.0, 0.0 );

	const dReal xPos = 0;
	const dReal yPos = 5;
	const dReal zPos = 0;
	const dReal xRot = 0;
	const dReal yRot = 0;
	const dReal zRot = 0;
	const dReal radius = .75;
	const dReal length = 4;
	const dReal sides[3] = { 2, 2, 2 };
	

	//Create body
	body.Body = dBodyCreate(World);
	dBodySetPosition(body.Body, xPos, yPos, zPos);
	dMatrix3 Orient3;
	//dRFromAxisAndAngle(Orient3, 0, 0, 1, 3.14/4);
	dRFromEulerAngles(Orient3, xRot, yRot, zRot);
	//dRFromEulerAngles(Orient3, 0, 0, 0);
	dBodySetRotation(body.Body, Orient3);
	dBodySetLinearVel(body.Body, 0, 0, 0);
	dBodySetData(body.Body, (void *)0);
	dMass bodyMass;
	dMassSetCapsule(&bodyMass, 1.0, 3, radius, length);
	//dMassSetBox(&bodyMass, 10, sides[0], sides[1], sides[2]);
	dBodySetMass(body.Body, &bodyMass);
	body.Geom = dCreateCapsule(Space, radius, length);
	//body.Geom = dCreateBox(Space, sides[0], sides[1], sides[2]);
	dGeomSetBody(body.Geom, body.Body);

	float head_pos[ 3 ] = { 0.0f, 5.0f, -1.0f };
	createInvisibleHead( head_pos );
	
	createFrontLegs();
	createMiddleLegs();
	createBackLegs();

	rng_engine.seed( std::chrono::duration_cast< std::chrono::microseconds >( std::chrono::system_clock::now().time_since_epoch() ).count() );

	const int foodPrize = 10;

	dReal position[3] = { 10.0f, 0.0f, -20.0f };
	addFoodParticle( position, foodPrize, &World, &Space );
}