Box2d drip trap diary: Joint (joint) and rotating joint (b2revolutejoint)

Source: Internet
Author: User

The joint is in the object organizational structure of box2d, and is parallel with b2body (rigid body. Therefore, both objects are created and managed directly by b2world.

However, joint depends on b2body, that is, its destruction: When the rigid body involved in the joint is destroyed, the joint is also destroyed. Access the joint pointer again to get an error. Therefore, when destroying the body, you should traverse the involved joint and destroy it.

In addition, it can be considered another major component of b2world, which is tied together with b2body. We have such a physical world: a pile of Rigid Bodies and joints. The heap of rigid bodies operates according to the laws of physics, and the joints limit or drive the movements of some rigid bodies.

Note:

1. To create a rotating joint, you need two rigid bodies (nonsense). If you want a rigid body to move around a point with the maximum and minimum angle constraints, you can also choose to use the rotating joint, select a rigid body without fiction and set it to b2_kinematicbody.

2. When creating a rotating joint, you need to place the two objects in their respective locations and then use a world coordinate as the axis. Then, the factory method calculates the axes of the Two Objects Based on the world coordinates and matches them with the current positional relationship.

3. Joint Angle Control. When the joint is created, the relative angle of the two is recorded as 0. The clockwise rotation is the positive angle, and the clockwise side is the inverse angle.

4-joint motor. The joint motor has two settings: Speed and maximum torque. The speed indicates that the target speed of the motor may not be able to be reached, depending on the torque. If the maximum torque cannot meet this speed, the current speed is calculated based on the maximum torque. The maximum torque is the maximum torque applied by the motor. This torque may not need to be reached, depending on the force of the current object that hinders the target speed of the motor. Therefore, the speed and maximum torque are not immediately achieved, but only two standard values.

However, there is a pitfall here. If your torque is not large enough, the gravity of the object may cause the preset speed to be unable to reach. After this problem occurs, at first, I thought that the speed was not set up. Later I modified the torque to find out that the reason is that the torque is not enough to combat gravity. Therefore, if you want to set the speed, you must consider setting enough torque.

5 whether it is a motor or joint restriction, the additional attributes of joint need to take effect. Almost all of them need to set an enablexxx. If this is false, the settings will not take effect, and there will be no effect.

Box2d drip trap diary: Joint (joint) and rotating joint (b2revolutejoint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.