关于BOX2D的那些事儿(5)

http://hi.baidu.com/goodlad/blog/item/a83ea7b19eb67d42082302f9.html


bool m_collideConnected;

  void* m_userData;

  m_type是类型,分为 e_unknownJoint、e_revoluteJoint、 e_prismaticJoint、e_distanceJoint、e_pulleyJoint、e_mouseJoint、e_gearJoint。指针节点这些都应用在数据结构上,定义是两个刚体对象:m_body1、m_body2,m_collideConnected表示连接刚体之间是否碰撞,还有一个函数指针型的m_userData来存储自己的数据。m_islandFlag这个标识暂时不用去管。

  支持的方法有:

  1、b2JointType GetType() const;

  取得关节类型。

  2、b2Body* GetBody1();

  取得刚体1

  3、b2Body* GetBody2();

  取得刚体2

  4、virtual b2Vec2 GetAnchor1() const = 0;

  取得锚点1

  5、virtual b2Vec2 GetAnchor2() const = 0;

  取得锚点2

  6、virtual b2Vec2 GetReactionForce(float32 invTimeStep) const = 0;

  取得反作用力

  7、virtual float32 GetReactionTorque(float32 invTimeStep) const = 0;

  取得反作用扭矩

  8、b2Joint* GetNext();

  取得下一个关节

  9、void* GetUserData();

  取得用户数据

  10、static b2Joint* Create(const b2JointDef* def, b2BlockAllocator* allocator);

  创建关节

  11、static void Destroy(b2Joint* joint, b2BlockAllocator* allocator);

  销毁关节

  12、其他方法(暂不介绍)

  virtual void PrepareVelocitySolver() = 0;

  virtual void SolveVelocityConstraints(const b2TimeStep* step) = 0;

  virtual void PreparePositionSolver() {}

  virtual bool SolvePositionConstraints() = 0;

  以前所讨论过的几种关节都是继承于b2Joint而来,下面列出了相关附加属性和方法。不推荐直接使用相关成员变量来取值或赋值,要擅于利用相关功能函数来取值。

  Gear Joint:

  附加属性(常用):

  b2Body* m_ground1;

  地面刚体1指针

  b2Body* m_ground2;

  地面刚体2指针

  b2RevoluteJoint* m_revolute1;

  RevoluteJoint指针1

  b2PrismaticJoint* m_prismatic1;

  PrismaticJoint指针1

  b2RevoluteJoint* m_revolute2;

  RevoluteJoint指针2

  b2PrismaticJoint* m_prismatic2;

  PrismaticJoint指针2

  b2Vec2 m_groundAnchor1;

  地面锚点1

  b2Vec2 m_groundAnchor2;

  地面锚点2

  b2Vec2 m_localAnchor1;

  当前锚点1

  b2Vec2 m_localAnchor2;

  当前锚点2

  float32 m_ratio;

  比例关系

  float32 m_mass;

  质量

  float32 m_impulse;

  推力

  附加方法:

  1、float32 GetRatio() const;

  取得比例关系

  Revolute Joint:

  附加属性:

  b2Vec2 m_localAnchor1;

  b2Vec2 m_localAnchor2;

  b2Vec2 m_ptpImpulse;

  float32 m_motorImpulse;

  float32 m_limitImpulse;

  float32 m_limitPositionImpulse;

  b2Mat22 m_ptpMass; // effective mass for point-to-point constraint.

  float32 m_motorMass; // effective mass for motor/limit angular constraint.

  float32 m_intialAngle;

  float32 m_lowerAngle;

  float32 m_upperAngle;

  float32 m_maxMotorTorque;

  float32 m_motorSpeed;

  bool m_enableLimit;

  bool m_enableMotor;

  b2LimitState m_limitState;

  附加方法:

  1、float32 GetJointAngle() const;

  取得关节角度

  2、float32 GetJointSpeed() const;

  取得关节速度

  3、float32 GetMotorTorque(float32 invTimeStep) const;

  取得发动扭矩

  4、void SetMotorSpeed(float32 speed);

  取得发动速度

  5、void SetMotorTorque(float32 torque);

  设置发动扭矩

  Prismatic Joint:

  附加方法:

  1、float32 GetJointTranslation() const;

  取得关节位移

  2、float32 GetJointSpeed() const;

  取得关节速度

  3、float32 GetMotorForce(float32 invTimeStep) const;

  取得发动应力

  4、 void SetMotorSpeed(float32 speed);

  设置发动速度

  5、void SetMotorForce(float32 force);

  设置发动速度

  Revolute Joint:

  附加方法:

  1、float32 GetJointAngle () const;

  取得关节角度

  2、float32 GetJointSpeed() const;

  取得关节速度

  3、float32 GetMotorTorque (float32 invTimeStep) const;

  取得发动扭矩

  4、 void SetMotorSpeed(float32 speed);

  设置发动速度

  5、void SetMotorTorque (float32 torque);

  设置发动扭矩

  十一、Joint motor(MotorsAndLimits、SliderCrank)

  在开始之前,我们再来回顾一下Joint,我们前面讨论过的情况来看,在几种Joint中应用到motor的只有Prismatic Joint和Revolute Joint。在使用motor时总有那么几个常见量,float32 motorTorque或者float32 motorForce、 float32 motorSpeed、bool enableLimit、bool enableMotor。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值