ODE Tutorial 6: Collision Detection ODE Tutorial 8: Joint Motion
11 月 28
This page was mainly translated from http://demura.net/archives/9ode by Babel Fish Translation. ODE (Open Dynamics Engine) lecture time it is 7th. This time we speak concerning the joint the story whose collision detection is detailed with afterwards. Previous topic coming out, the て it was, but it is possible and increase is high? As for answering, it is in nearCallback function Contact [ i ] surface.bounce = 0.0; / (0.0 - 1.0)   as for coefficient of rebound from 0 up to 1 Being value should have been designated as the 1.0 or less of 0.0 or more, it does. Don't you think? coefficient of rebound was speed ratio before the colliding and after the collision. So, it explains concerning the joint. Around us, you fold up the joint and are suitable to the hinge of carrying and the hinge of the door. Small speaking seriously, it meaning that position of two bodies and the restraint which maintains attitude at a certain fixed relationship are with the joint, it does. With ODE the joint and restraint are used in the same sense. The source code where the object which connects the ball and the cylinder which have shown right away in the upper figure with the hinge joint bounces is shown below. Furthermore, it abbreviates the same function to as the last time and declaration.
CODE:
  1. //  sample3.cpp by Kosei Demura
  2.  
  3. #ifdef  dDOUBLE
  4. #define dsDrawSphere   dsDrawSphereD
  5. #define dsDrawCapsule  dsDrawCapsuleD
  6. #endif
  7.  
  8. typedef struct {
  9. dBodyID body;
  10. dGeomID geom;
  11. dReal   radius, length, mass;
  12. } MyLink;
  13. MyLink ball,  pole;
  14.  
  15. static void simLoop (int pause)
  16. {
  17. const dReal *pos1, *R1, *pos2, *R2;
  18. dSpaceCollide (space,0, &nearCallback);
  19. dWorldStep (world,0.01);
  20. dJointGroupEmpty (contactgroup);
  21. dsSetColor (1.0,0.0,0.0);
  22. // Drawing of ball
  23. pos1 = dBodyGetPosition (ball.body);
  24. R1   = dBodyGetRotation (ball.body);
  25. dsDrawSphere (pos1, R1, ball.radius);
  26. // Drawing of cylinder
  27. pos2 = dBodyGetPosition (pole.body);
  28. R2    = dBodyGetRotation (pole.body);
  29. dsDrawCapsule (pos2, R2, pole.length, pole.radius);
  30. }
  31.  
  32. // Compilation of object
  33. void createBallandPole ()
  34. {
  35. dMass m1;
  36. dReal x0 = 0.0, y0 = 0.0, z0 = 2.5;
  37.  
  38. // Ball
  39. ball.radius = 0.2;  Ball.mass   = 1.0;
  40. ball.body = dBodyCreate (world);
  41. dMassSetZero (&m1);
  42. dMassSetSphereTotal (&m1, ball.mass, ball.radius);
  43. dBodySetMass (ball.body, &m1);
  44. dBodySetPosition (ball.body, x0, y0, z0);
  45. ball.geom = dCreateSphere (space, ball.radius);
  46. dGeomSetBody (ball.geom, ball.body);
  47.  
  48. // Cylinder
  49. pole.radius = 0.025;  pole.length = 1.0;  pole.mass   = 1.0;
  50. pole.body = dBodyCreate (world);
  51. dMassSetZero (&m1);
  52. dMassSetCapsuleTotal (&m1, pole.mass,3, pole.radius, pole.length);
  53. dBodySetMass (pole.body, &m1);
  54. dBodySetPosition (pole.body, x0, y0, z0 - 0.5 * pole.length);
  55. pole.geom = dCreateCapsule (space, pole.radius, pole.length);
  56. dGeomSetBody (pole.geom, pole.body);
  57.  
  58. // Hinge joint
  59. joint = dJointCreateHinge (world, 0)// Creation of hinge joint
  60. dJointAttach (joint, ball.body, pole.body)// Connecting the body of the ball and the body of the cylinder with the joint
  61. dJointSetHingeAnchor (joint, x0, y0, z0 - ball.radius)// The anchor of the hinge joint (the central point) it sets
  62. dJointSetHingeAxis (joint, 1, 0, 0); // Axis of rotation vector of hinge joint setting (1,0,0)
  63. }
  64.  
  65. int main (int argc, char **argv)
  66. {
  67. setDrawStuff ();
  68. world = dWorldCreate ();
  69. space = dHashSpaceCreate (0);
  70. contactgroup = dJointGroupCreate (0);
  71. dWorldSetGravity(world,0,0,-9.8);                                                                    ground=dCreatePlane(space,0,0,1,0);
  72. createBallandPole ();
  73. dsSimulationLoop (argc and argv,352,288, &fn);
  74. dWorldDestroy (world);
  75. return 0;
  76. }

With this example the body of the ball and the cylinder is tied with the hinge joint. Method of using the joint becomes like below.
  1. Creation of a Joint:       dJointCreate***()
  2. Connection:                 dJointAttach()
  3. Set an anchor of a joint:dJointSet***Anchor ()
  4. Set an axis of a joint:    dJointSet***Axis ()
*** denotes a type of joint, i.e., Hinge, Ball, Slider, Universal, and so on. Let's read the source code. With createBallandPall function the ball is made first, after that, the cylinder is made, then dJointCreateHinge () with it forms the hinge joint, dJointAttach () with two bodies is connected with the hinge joint. After that dSetHingeAnchor () while turning of the joint position of the heart point is set, dJointSetHingeAxis () with axis of rotation vector is set. With this example as for axis of rotation vector (1,0,0) being to be, it becomes x axial direction. Referring to details the manual. Formation of the joint is end with this. This time parameter of the joint was not set for simplicity, but also the movable limits and largest torque and setting etc. of maximum angular velocity are possible. Clicking here,downloading the sample program, please play.
The next time explains the method of moving the joint and the setting method of parameter.
To be continued.
投稿:06年11月28日

Leave a Reply

カウンタ (since 2008-1-11)
Copyright © 1998-2008    Kosei Demura