LIBGDX BOX2D JOINT介绍

资料:

http://box2d.org/manual.pdf

http://www.iforce2d.net/

概念:

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值