Function: The object can be rotated around the anchor point set. Use: Wheels. First paragraph of the Code:
1 var New P2. Revoluteconstraint (Holderbody, Circlebody, {2 worldpivot: [0, 5]3 // Localpivota: [1,-1],4 //LOCALPIVOTB: [0, 0]5 }); 6 r1.enablemotor (); 7 r1.setmotorspeed (5); 8 World.addconstraint (R1);
The red dot in the rectangle represents the center point of the rectangle, and the global coordinate is [0,4], and now the circle is circling around a certain point in a circular motion. Tell me about some of the properties that this code uses. Worldpivot,a pivot Point given on world coordinates. If specified, Localpivota and LOCALPIVOTB is automatically computed from this value. Translation: The center point of the rotation is a given global coordinate. If this property is set, the Localpivota and LOCALPIVOTB properties will automatically be calculated as this value (that is, you do not have to set Localpivota and LOCALPIVOTB). The circle of the essence is in the coordinate [0,5] for the circular motion, that is, the center point of the rectangle to go up a bit of position for the rotation center point. Change the code slightly and change it to:
1 var New P2. Revoluteconstraint (Holderbody, Circlebody, {2// worldpivot: [0, 5]3 Localpivota: [1,-1],4 LOCALPIVOTB: [0, 0]5}); 6 r1.enablemotor (); 7 r1.setmotorspeed (5); 8 World.addconstraint (R1);
At this point, as above. This is useful to the Localpivota and LOCALPIVOTB properties. Localpivota,the points relative to the center of mass of Bodya which Bodya are constrained to. Translation: The coordinates of this point are relative to the Bodya center of mass (in fact, The center of the Bodya, because the density of our rigid bodies is the ideal average distribution of LOCALPIVOTB and localpivota the same concept. This will explain why the circle is rotated around the plum dot at this point. In addition, the motor can be turned on for further observation. When the parameter of Setmotorspeed (XX) is passed a positive number, the circular motion is clockwise (CW). To make a circular motion counterclockwise (CCW), a negative parameter can be passed. Practice Source Address: https://gist.github.com/yxzblue/3a66babfb93b889f0833#file-revoluteconstraint-html p2.js v0.6.0 Compression package, Link: Http://pan.baidu.com/s/1mgsW7xA Password: Bj85p2.js's github address: https://github.com/schteppe/p2.js
P2. JS rotation constraint (revoluteconstraint) memo