示例#1
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;
}
示例#2
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;

}
示例#3
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;
}
示例#4
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);
}
示例#5
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;
}
示例#6
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");

}