资料:
概念:
origin point:setPosition把这个点置于某处,polygonShape的vertices位置相对于origin point
centroid:形心 质心 当几何体为匀质物体时,重心与形心重合
Joint depends on JointDef
JointDef属性:
type = JointType.Unknown
bodyA = null //first attached body
bodyB = null
collideConnected = false
创建Joint
World::createJoint(JointDef def),根据def的type创建不同类型的Joint
1.DistanceJoint 两body的anchor间长度不变
DistanceJointDef extends JointDef
DistanceJointDef::initialize (Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB)
把world anchorA、anchorB转为bodyA、bodyB的Local anchor
距离关节的length = anchorA.dst(anchorB)
属性:
localAnchorA //relative to body1's origin
localAnchorB
length=1
frequencyHz=0 //The mass-spring-damper frequency in Hertz.
dampingRatio=0 //The damping ratio. 0 = no damping, 1 = critical damping.
2.FrictionJoint
FrictionJoint::initialize (Body bodyA, Body bodyB, Vector2 anchor)
把world anchor转为bodyA、bodyB的Local anchor
属性:
localAnchorA
localAnchorB
maxForce = 0 //The maximum friction force in N
maxTorque = 0 //The maximum friction torque in N-m anchor做轴心
3.RevoluteJoint
RevoluteJointDef::initialize (Body bodyA, Body bodyB, Vector2 anchor)
属性:
referenceAngle //The body2 angle minus body1 angle in the reference state (radians).
lowerAngle //The lower angle for the joint limit (radians)
upperAngle
motorSpeed //The desired motor speed. Usually in radians per second.
maxMotorTorque //The maximum motor torque used to achieve the desired motor speed. Usually in N-m.
body2逆时针旋转时关节角为正,initialize时旋转关节角为0,lower和upper应该包含0
4.PrismaticJoint
PrismaticJointDef::initialize (Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis)
eg. axis设置成(1,1),和anchor一起定位两body间移动的轴
属性:
localAxisA=new Vector2(1,0)//The local translation axis in body1
referenceAngle=0 //The constrained angle between the bodies: body2_angle - body1_angle.
enableLimit = false
lowerTranslation = 0//The lower translation limit, usually in meters
upperTranslation = 0
enableMotor = false
maxMotorForce = 0 //The maximum motor torque, usually in N-m.
motorSpeed = 0 // The desired motor speed in radians per second
5.PulleyJoint
PulleyJointDef::initialize (Body bodyA, Body bodyB, Vector2 groundAnchorA, Vector2 groundAnchorB, Vector2 anchorA,Vector2 anchorB, float ratio)
C = lengthA + ratio * lengthB;
eg ratio=2,length1变化是length2的两倍,连接body1的绳子的受力是连接body2的一半
属性:lengthA lengthB
libgdx 的box2d无maxLength1 maxLength2属性
6.GearJoint
由两个RevoluteJoint 或者PrismaticJoint组合而成,而且这两个Joint的body1都要是ground
7.RopeJoint
RopeJointDef::
localAnchorA
localAnchorB
maxLength
8.WeldJoint
WeldJointDef::initialize(Body body1, Body body2, Vector2 anchor)
属性:
localAnchorA
localAnchorB
referenceAngle
9.WheelJoint 模拟轮胎,可以颠簸,axis是body2的颠簸方向,eg.设置bodyA static,bodyB 轮子dynamic
WheelJointDef::initialize (Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis)
属性:
localAnchorA
localAnchorB
localAxisA //The local translation axis in body1
maxMotorTorque
motorSpeed
frequencyHz=2
dampingRatio=0.7
10.MouseJoint