cocos2d-x节点(b2PulleyJoint.h)API

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(b2PulleyJoint.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

//pulley(带轮) joints(接头)用于使用两个固定的环绕点,连接两个 bodies

///cocos2d-x-3.0alpha0/external/Box2D/Dynamics/Joints
//pulley(带轮) joints(接头)用于使用 两个固定的环绕点,连接两个 bodies

#ifndef B2_PULLEY_JOINT_H
#define B2_PULLEY_JOINT_H

#include <Box2D/Dynamics/Joints/b2Joint.h>

const float32 b2_minPulleyLength = 2.0f;

/// Pulley(带轮) joints(接头)定义. 这需要两个环绕锚点,两个动态物体的锚点和一个滑轮比率
struct b2PulleyJointDef : public b2JointDef
{
    b2PulleyJointDef()
    {
        type = e_pulleyJoint;
        groundAnchorA.Set(-1.0f, 1.0f);
        groundAnchorB.Set(1.0f, 1.0f);
        localAnchorA.Set(-1.0f, 0.0f);
        localAnchorB.Set(1.0f, 0.0f);
        lengthA = 0.0f;
        lengthB = 0.0f;
        ratio = 1.0f;
        collideConnected = true;
    }

    /// 使用 锚,长度,最大长度,使用的 world anchors(锚点) ratio 初始化 bodies            //比率
    void Initialize(b2Body* bodyA, b2Body* bodyB,
                    const b2Vec2& groundAnchorA, const b2Vec2& groundAnchorB,
                    const b2Vec2& anchorA, const b2Vec2& anchorB,
                    float32 ratio);

    /// 在世界坐标系中的第一个环绕锚点,这个点永远不会移动
    b2Vec2 groundAnchorA;

    /// 在世界坐标系中的第二个环绕锚点,这个点永远不会移动
    b2Vec2 groundAnchorB;

    /// 相对与 bodyA's 原点的本地锚点.
    b2Vec2 localAnchorA;

    /// 相对与 bodyB's 原点的本地锚点.
    b2Vec2 localAnchorB;

    ///  关联到 bodyA 的段的参考长度
    float32 lengthA;

    /// 关联到 bodyB 的段的参考长度
    float32 lengthB;

    /// pulley(带轮)比率,用来模拟 block-and-tackle.         //块处理
    float32 ratio;
};
//pulley(带轮) joints(接头)用于使用 两个固定的环绕点,连接两个 bodies
/// The pulley(带轮) 支持比率:
/// length1 + ratio * length2 <= constant       //常数
/// 传递的力根据 ratio 缩放.            //比率
/// Warning: 使用 /pulley(带轮) joints(接头)可以得到一个疯狂的 bit         //比特
// 它们和 prismatic(移动)joints(接头)结合的很好
class b2PulleyJoint : public b2Joint
{
public:
    b2Vec2 GetAnchorA() const;
    b2Vec2 GetAnchorB() const;

    b2Vec2 GetReactionForce(float32 inv_dt) const;
    float32 GetReactionTorque(float32 inv_dt) const;

    /// Get 第一个环绕锚点.
    b2Vec2 GetGroundAnchorA() const;

    /// Get 第二个环绕锚点.
    b2Vec2 GetGroundAnchorB() const;

    /// 关联到 bodyA 的段的当前长度.
    float32 GetLengthA() const;

    /// 关联到 bodyB 的段的当前长度.
    float32 GetLengthB() const;

    /// Get the pulley ratio.
    float32 GetRatio() const;

    /// 把 joints(接头)的阻尼输出到 dmLog
    void Dump();

protected:

    friend class b2Joint;
    b2PulleyJoint(const b2PulleyJointDef* data);

    void InitVelocityConstraints(const b2SolverData& data);
    void SolveVelocityConstraints(const b2SolverData& data);
    bool SolvePositionConstraints(const b2SolverData& data);

    b2Vec2 m_groundAnchorA;
    b2Vec2 m_groundAnchorB;
    float32 m_lengthA;
    float32 m_lengthB;
    
    // Solver shared
    b2Vec2 m_localAnchorA;
    b2Vec2 m_localAnchorB;
    float32 m_constant;
    float32 m_ratio;
    float32 m_impulse;

    // Solver temp
    int32 m_indexA;
    int32 m_indexB;
    b2Vec2 m_uA;
    b2Vec2 m_uB;
    b2Vec2 m_rA;
    b2Vec2 m_rB;
    b2Vec2 m_localCenterA;
    b2Vec2 m_localCenterB;
    float32 m_invMassA;
    float32 m_invMassB;
    float32 m_invIA;
    float32 m_invIB;
    float32 m_mass;
};

#endif


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值