// start simulation - set viewpoint static void start() { dAllocateODEDataForThread(dAllocateMaskAll); dsSetViewpoint (xyz,hpr); printf ("This program demonstrates how the Piston joint works.\n"); printf ("A Piston joint enables the sliding of a body with respect to another body\n"); printf ("and the 2 bodies are free to rotate about the sliding axis.\n\n"); printf ("The yellow body is fixed to the world\n"); printf ("The yellow body and the blue body are attached by a Piston joint with\n"); printf ("the axis along the x direction.\n"); printf ("The purple object is a geometry obstacle.\n"); printKeyBoardShortCut(); }
// start simulation - set viewpoint static void start() { dAllocateODEDataForThread(dAllocateMaskAll); dsSetViewpoint (xyz,hpr); printf ("This program demonstrates how the PU joint works.\n"); printf ("A PU joint is a combination of a Universal joint and a Slider joint.\n"); printf ("It is a universal joint with a slider between the anchor point and \n"); printf ("body 1.\n\n"); printf ("The upper yellow body is fixed to the world\n"); printf ("The lower yellow body is attached to the upper body by a PU joint\n"); printf ("The green object is one aprt of the slider.\n"); printf ("The purple object is the second part of the slider.\n"); printf ("The red object represent the axis1 of the universal part. \n"); printf ("The blue object represent the axis2 of the universal part. \n"); printf ("The gray object represent the anchor2 of the PU joint. \n"); printKeyBoardShortCut(); }
// called when a key pressed static void command (int cmd) { switch (cmd) { case 'h' : case 'H' : case '?' : printKeyBoardShortCut(); break; // Force case 'q' : case 'Q' : body[D].addForce(40,0,0); break; case 'w' : case 'W' : body[D].addForce(-40,0,0); break; case 'a' : case 'A' : body[D].addForce(0,40,0); break; case 's' : case 'S' : body[D].addForce(0,-40,0); break; case 'z' : case 'Z' : body[D].addForce(0,0,40); break; case 'x' : case 'X' : body[D].addForce(0,0,-40); break; // Torque case 'e': case 'E': body[D].addTorque(0.1,0,0); break; case 'r': case 'R': body[D].addTorque(-0.1,0,0); break; case 'd': case 'D': body[D].addTorque(0, 0.1,0); break; case 'f': case 'F': body[D].addTorque(0,-0.1,0); break; case 'c': case 'C': body[D].addTorque(0,0,0.1); break; case 'v': case 'V': body[D].addTorque(0,0,0.1); break; // Velocity of joint case ',': case '<' : { dReal vel = joint->getParam (dParamVel3) - VEL_INC; joint->setParam (dParamVel3, vel); std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; } break; case '.': case '>' : { dReal vel = joint->getParam (dParamVel3) + VEL_INC; joint->setParam (dParamVel3, vel); std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; } break; case 'l': case 'L' : { dReal aLimit, lLimit, fmax; if ( joint->getParam (dParamFMax) ) { aLimit = dInfinity; lLimit = dInfinity; fmax = 0; } else { aLimit = 0.25*PI; lLimit = 0.5*axDim[LENGTH]; fmax = 0.02; } joint->setParam (dParamFMax1, fmax); joint->setParam (dParamFMax2, fmax); joint->setParam (dParamFMax3, fmax); switch (joint->getType() ) { case dJointTypePR : { dPRJoint *pr = reinterpret_cast<dPRJoint *> (joint); pr->setParam (dParamLoStop, -lLimit); pr->setParam (dParamHiStop, -lLimit); pr->setParam (dParamLoStop2, aLimit); pr->setParam (dParamHiStop2, -aLimit); } break; case dJointTypePU : { dPUJoint *pu = reinterpret_cast<dPUJoint *> (joint); pu->setParam (dParamLoStop1, -aLimit); pu->setParam (dParamHiStop1, aLimit); pu->setParam (dParamLoStop2, -aLimit); pu->setParam (dParamHiStop2, aLimit); pu->setParam (dParamLoStop3, -lLimit); pu->setParam (dParamHiStop3, lLimit); } break; default: {} // keep the compiler happy } } break; case 'g': case 'G' : { dVector3 g; world.getGravity(g); if ( g[2]< -0.1 ) world.setGravity(0, 0, 0); else world.setGravity(0, 0, -0.5); } case 'p' :case 'P' : { switch (joint->getType() ) { case dJointTypeSlider : { dSliderJoint *sj = reinterpret_cast<dSliderJoint *> (joint); std::cout<<"Position ="<<sj->getPosition() <<"\n"; } break; case dJointTypePU : { dPUJoint *pu = reinterpret_cast<dPUJoint *> (joint); std::cout<<"Position ="<<pu->getPosition() <<"\n"; std::cout<<"Position Rate="<<pu->getPositionRate() <<"\n"; std::cout<<"Angle1 ="<<pu->getAngle1() <<"\n"; std::cout<<"Angle1 Rate="<<pu->getAngle1Rate() <<"\n"; std::cout<<"Angle2 ="<<pu->getAngle2() <<"\n"; std::cout<<"Angle2 Rate="<<pu->getAngle2Rate() <<"\n"; } break; default: {} // keep the compiler happy } } break; } }
// called when a key pressed static void command (int cmd) { switch (cmd) { case 'h' : case 'H' : case '?' : printKeyBoardShortCut(); break; // Force case 'q' : case 'Q' : dBodyAddForce (body[BODY1],4,0,0); break; case 'w' : case 'W' : dBodyAddForce (body[BODY1],-4,0,0); break; case 'a' : case 'A' : dBodyAddForce (body[BODY1],0,40,0); break; case 's' : case 'S' : dBodyAddForce (body[BODY1],0,-40,0); break; case 'z' : case 'Z' : dBodyAddForce (body[BODY1],0,0,4); break; case 'x' : case 'X' : dBodyAddForce (body[BODY1],0,0,-4); break; // Torque case 'e': case 'E': dBodyAddTorque (body[BODY1],0.1,0,0); break; case 'r': case 'R': dBodyAddTorque (body[BODY1],-0.1,0,0); break; case 'd': case 'D': dBodyAddTorque (body[BODY1],0, 0.1,0); break; case 'f': case 'F': dBodyAddTorque (body[BODY1],0,-0.1,0); break; case 'c': case 'C': dBodyAddTorque (body[BODY1],0.1,0,0); break; case 'v': case 'V': dBodyAddTorque (body[BODY1],-0.1,0,0); break; case 't': case 'T': if (joint->getType() == dJointTypePiston) dJointAddPistonForce (joint->id(),1); else dJointAddSliderForce (joint->id(),1); break; case 'y': case 'Y': if (joint->getType() == dJointTypePiston) dJointAddPistonForce (joint->id(),-1); else dJointAddSliderForce (joint->id(),-1); break; case '8' : dJointAttach(joint->id(), body[0], 0); break; case '9' : dJointAttach(joint->id(), 0, body[0]); break; case 'i': case 'I' : joint->setParam (dParamLoStop, 0); joint->setParam (dParamHiStop, 0); break; case 'o': case 'O' : joint->setParam (dParamLoStop2, 0); joint->setParam (dParamHiStop2, 0); break; case 'k': case 'K': joint->setParam (dParamLoStop2, -45.0*3.14159267/180.0); joint->setParam (dParamHiStop2, 45.0*3.14159267/180.0); break; case 'l': case 'L': joint->setParam (dParamLoStop2, -dInfinity); joint->setParam (dParamHiStop2, dInfinity); break; // Velocity of joint case ',': case '<' : { dReal vel = joint->getParam (dParamVel) - VEL_INC; joint->setParam (dParamVel, vel); std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; } break; case '.': case '>' : { dReal vel = joint->getParam (dParamVel) + VEL_INC; joint->setParam (dParamVel, vel); std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; } break; case 'p' : case 'P' : { switch (joint->getType() ) { case dJointTypeSlider : { dSliderJoint *sj = reinterpret_cast<dSliderJoint *> (joint); std::cout<<"Position ="<<sj->getPosition() <<"\n"; } break; case dJointTypePiston : { dPistonJoint *rj = reinterpret_cast<dPistonJoint *> (joint); std::cout<<"Position ="<<rj->getPosition() <<"\n"; } break; default: {} // keep the compiler happy } } break; case '+' : (++tc) %= 4; setPositionBodies (tc); break; case '-' : (--tc) %= 4; setPositionBodies (tc); break; } }