cocos2d-x节点(b2Body.h)API

来源:互联网 发布:淘宝网帽子女士太阳帽 编辑:程序博客网 时间:2024/05/16 10:15

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

cocos2d-x节点(b2Body.h)API

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

//模拟现实世界中的静态物体,动态物体,匀速直线运动的物体,并返回它们的各种状态

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. ///cocos2d-x-3.0alpha0/external/Box2D/Dynamics  
  2. //模拟现实世界中的静态物体,动态物体,匀速直线运动的物体,并返回它们的各种状态  
  3.   
  4. #ifndef B2_BODY_H  
  5. #define B2_BODY_H  
  6.   
  7. #include <Box2D/Common/b2Math.h>  
  8. #include <Box2D/Collision/Shapes/b2Shape.h>  
  9. #include <memory>  
  10.   
  11. class b2Fixture;  
  12. class b2Joint;  
  13. class b2Contact;  
  14. class b2Controller;  
  15. class b2World;  
  16. struct b2FixtureDef;  
  17. struct b2JointEdge;  
  18. struct b2ContactEdge;  
  19.   
  20. ///  body 类型.  
  21. /// static: zero mass, zero velocity(速度), 可以手动移动            //速度一定,位置可以手动设置  
  22. /// kinematic(运动学): zero mass, 由用户设置 non-zero velocity(速度), moved by solver(运算器)        //用户可以设置速度位置由系统计算  
  23. /// dynamic(动态): positive(真实的) mass,由力决定 non-zero velocity(速度), moved by solver(运算器)    //类似与现实世界中的物体,mass 是时时的,因为物体的速度,状态会影响 mass ,速度由力来决定  
  24. //  
  25. enum b2BodyType  
  26. {  
  27.     b2_staticBody = 0,  
  28.     b2_kinematicBody,  
  29.     b2_dynamicBody  
  30.   
  31.     // TODO_ERIN  
  32.     //b2_bulletBody,  
  33. };  
  34.   
  35. /// 定义 body 所需要的所有数据构建一个正确的 body  
  36. //您可以安全地 re-use 定义的 body  
  37. //构建后把 shapes 添加到 body  
  38. struct b2BodyDef  
  39. {  
  40.     ///此构造函数设置定义的 body (使用默认值).  
  41.     b2BodyDef()  
  42.     {  
  43.         userData = NULL;  
  44.         position.Set(0.0f, 0.0f);  
  45.         angle = 0.0f;  
  46.         linearVelocity.Set(0.0f, 0.0f);  
  47.         angularVelocity = 0.0f;  
  48.         linearDamping = 0.0f;  
  49.         angularDamping = 0.0f;  
  50.         allowSleep = true;  
  51.         awake = true;  
  52.         fixedRotation = false;  
  53.         bullet = false;  
  54.         type = b2_staticBody;  
  55.         active = true;  
  56.         gravityScale = 1.0f;  
  57.     }  
  58.   
  59.     /// The body type: static, kinematic(动力学), or dynamic(动态).  
  60.     /// Note: 如果动态的 body 质量是 0, 质量将被设置成 1.  
  61.     b2BodyType type;  
  62.   
  63.     /// body 在世界坐标中的位置. 避免在 origin(原点) 处创建 body  
  64.     /// 因为这可能会导致许多重叠的 shapes  
  65.     b2Vec2 position;  
  66.   
  67.     /// body 在 world 中的角度 ,以弧度为单位  
  68.     float32 angle;  
  69.   
  70.     /// body's origin(原点)在世界坐标系中的线速度  
  71.     b2Vec2 linearVelocity;  
  72.   
  73.     /// body 的角速度.  
  74.     float32 angularVelocity;  
  75.   
  76. //    使用线性阻尼,以降低线速度。阻尼参数  
  77. //    可以大于1.0F ,但阻尼作用会变得非常敏感  
  78. //      阻尼参数越大同步时间越长  
  79.     float32 linearDamping;  
  80.   
  81.     /// 使用阻尼角,以减少角速度。阻尼参数  
  82.     //    可以大于1.0F ,但阻尼作用会变得非常敏感  
  83.     //      阻尼参数越大同步时间越长  
  84.     float32 angularDamping;  
  85.   
  86.     /// 把这个标志设置为 false 如果这个 body 不应该进入睡眠. 需要注意的是  
  87.     //这会增加CPU的使用率。  
  88.     bool allowSleep;  
  89.   
  90.     /// 这个 body 初始化时是 awake / sleeping?  
  91.     bool awake;  
  92.   
  93.     ///如果这个 body 不应该旋转,这个字符串就非常有用了  
  94.     bool fixedRotation;  
  95.   
  96.     ///这是一个快速移动的 body,应该防止它快速穿过其它 body  
  97. //    请注意所有的 body 都无法从  kinematic/static body 之内穿过  
  98.     /// @warning 你应该尽量减少使用这个 flag,因为它会增加处理时间  
  99.     bool bullet;  
  100.   
  101.     ///  body 是否开始激活?  
  102.     bool active;  
  103.   
  104.     /// 使用这个存储应用程序特定的 body 数据  
  105.     void* userData;  
  106.   
  107.     ///应用到这个 body 的中立比例.  
  108.     float32 gravityScale;  
  109. };  
  110.   
  111. /// A rigid(精密) body. 这些是通过 b2World::CreateBody 创建的.  
  112. class b2Body  
  113. {  
  114. public:  
  115.     /// 创建一个 fixture(定制器) 把它附加到这个 body. 使用此功能,如果你需要的  
  116.     ///设置一些固定参数,如摩擦。其它情况,你可以使用shape 创建 fixture(定制器)  
  117. //    如果密度不为零时,此功能会自动更新物体的质量。  
  118.     /// 联系一直存在,不会创建直到下一个步骤  
  119.     /// @param def 定义的 fixture(定制器)  
  120.     /// @warning 这个功能锁定在 回调函数里面  
  121.     b2Fixture* CreateFixture(const b2FixtureDef* def);  
  122.   
  123.     /// 创建一个固定形状,将它附加到这个身体  
  124.     /// 这是一个方便的功能.  如果你需要使用 b2FixtureDef 设置参数  
  125.     /// 如 friction(摩擦), restitution(恢复), user data, or filtering(过滤).  
  126.     /// 如果密度不为零时,此功能会自动更新物体的质量  
  127.     /// @param shape 要克隆的形状.  
  128.     /// @param density  shape 的密度 (静态物体设置为零).  
  129.     /// @warning 这个功能锁定在 回调函数里面  
  130.     b2Fixture* CreateFixture(const b2Shape* shape, float32 density);  
  131.   
  132.     /// 销毁一个 fixture. 从 broad-phase 里面移除这个 fixture,破坏与这个 fixture 关联的所有联系这将  
  133.     // /如果身体是动态的,这个 fixture 具有一定的密度,它会自动调整物体的质量,  
  134.     /// 当 body 被销毁时,关联到 body 的所有 fixtures 都会直接被删除  
  135.     /// @param fixture the fixture to be removed.  
  136.     /// @warning 这个功能锁定在 回调函数里面.  
  137.     void DestroyFixture(b2Fixture* fixture);  
  138.   
  139.     /// 为这个 body 设置位置和旋转角  
  140.     /// 这打破了任何联系,唤醒其它 body  
  141.     /// 操作一个 body 转换,可能会 导致其它 non-physical 行为.  
  142.     /// @param position body 在世界坐标系的位置  
  143.     /// @param angle 世界坐标系的角度以弧度为单位  
  144.     void SetTransform(const b2Vec2& position, float32 angle);  
  145.   
  146.     /// 获取这个 body 的转换.  
  147.     /// @return 这个 body 在世界坐标系中的转换.  
  148.     const b2Transform& GetTransform() const;  
  149.   
  150.     /// 获取 body 在世界坐标系中的位置.  
  151.     /// @return body 在世界坐标系中的位置..  
  152.     const b2Vec2& GetPosition() const;  
  153.   
  154.     /// 获取角度以弧度为单位.  
  155.     /// @return 当前世界坐标系的角度以弧度为单位  
  156.     float32 GetAngle() const;  
  157.   
  158.     /// 获取的质量中心 在世界坐标系中的位置.  
  159.     const b2Vec2& GetWorldCenter() const;  
  160.   
  161.     /// 获取本地的质量中心的位置。.  
  162.     const b2Vec2& GetLocalCenter() const;  
  163.   
  164.     /// 设定的质心的线速度.  
  165.     /// @param v 新的质心的线速度。.  
  166.     void SetLinearVelocity(const b2Vec2& v);  
  167.   
  168.     /// Get 质心的线速度..  
  169.     /// @return 质心的线速度.  
  170.     b2Vec2 GetLinearVelocity() const;  
  171.   
  172.     /// Set 角速度.  
  173.     /// @param omega 新的角速度 radians/second.  
  174.     void SetAngularVelocity(float32 omega);  
  175.   
  176.     /// Get 角速度.  
  177.     /// @return 新的角速度 radians/second.  
  178.     float32 GetAngularVelocity() const;  
  179.   
  180.     /// 这世界坐标点应用力,如果力不作用在质量中心,他会发生旋转,影响角速度,唤醒这个 body  
  181.     /// @param force  world 力矢量,通常以牛顿(N)为单位  
  182.     /// @param point 应用里面的某个点的 world 位置  
  183.     void ApplyForce(const b2Vec2& force, const b2Vec2& point);  
  184.   
  185.     /// 在质量中心施加一个力,这将唤醒这个 body  
  186.     /// @param force  world 力矢量,通常以牛顿(N)为单位  
  187.     void ApplyForceToCenter(const b2Vec2& force);  
  188.   
  189.     /// 应用力矩,这会影响到角速度  
  190.     /// 不影响质量的中心的线速度,唤醒 body  
  191.     /// @param torque 围绕z轴(移出屏幕), 通常 N-m(N/米).  
  192.     void ApplyTorque(float32 torque);  
  193.   
  194.     /// 应用一个冲量到一个点上,这将立即改变速度。(这句话的意思是突然在一个点上作用一个力)  
  195.     /// 如果这个点不再应用程序的质心上,它还会修改角速度. 唤醒 body.  
  196.     /// @param impulse  world 的矢量冲量, 通常 N-seconds or kg-m/s.  
  197.     /// @param point 应用里面的某个点的 world 位置  
  198.     void ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point);  
  199.   
  200.     /// 应用一个有角度的冲量  
  201.     /// @param impulse 角度冲量的单位是 kg*m*m/s  
  202.     void ApplyAngularImpulse(float32 impulse);  
  203.   
  204.     /// 获取 body 的总质量  
  205.     /// @return the mass, 通常是以 kilograms (kg) 为单位.  
  206.     float32 GetMass() const;  
  207.   
  208.     /// 获取 body 的转动惯量,(本地点)  
  209.     /// @return 旋转惯性, 通常是以 kg-m^2.为单位  
  210.     float32 GetInertia() const;  
  211.   
  212.     /// 获取这个身体的质量数据  
  213.     /// @return 一个包含 质量,惯性和body的中心  
  214.     void GetMassData(b2MassData* data) const;  
  215.   
  216.     ///设置质量属性,覆盖 fixtures 的质量属性  
  217.     /// Note 这改变了质心的位置.  
  218.     /// Note t创建或销毁 fixtures 可以改变质量.  
  219.     /// 如果 body 不是动态的这个函数没有效果.  
  220.     /// @param massData  mass 属性.  
  221.     void SetMassData(const b2MassData* data);  
  222.   
  223. // 计算 fixtures 的质量,这将重置质量属性  
  224.     /// 通常不需要调用这个,除非你调用了 SetMassData 覆盖了质量随后你需要复位质量.  
  225.     void ResetMassData();  
  226.   
  227.     /// 获取给定坐标点,在世界坐标系中的位置  
  228.     /// @param localPoint 相对于 body's 原点的测量点.  
  229.     /// @return 相同的点用 world 坐标系表示.  
  230.     b2Vec2 GetWorldPoint(const b2Vec2& localPoint) const;  
  231.   
  232.     ///用世界坐标系表示给定的本地坐标  
  233.     /// @param localVector 固定在 body 上的矢量.  
  234.     /// @return 相同的向量用 world 坐标系表示  
  235.     b2Vec2 GetWorldVector(const b2Vec2& localVector) const;  
  236.   
  237.     /// 使用给定世界坐标系的点获取一个相对于 body 原点的本地点  
  238.     /// @param 一个 world 坐标系中的点.  
  239.     /// @return 相对于 body 原点的本地坐标点  
  240.     b2Vec2 GetLocalPoint(const b2Vec2& worldPoint) const;  
  241.   
  242.     /// 把指定的世界坐标系中的向量转换为一个本地向量  
  243.     /// @param world 坐标系中的向量.  
  244.     /// @return 对应的本地向量  
  245.     b2Vec2 GetLocalVector(const b2Vec2& worldVector) const;  
  246.   
  247.     ///获取关联到这个 body 的 world point 在 world 中的线性速度  
  248.     /// @param 一个 world 坐标系中的点  
  249.     /// @return 一个点的 world 速度  
  250.     b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2& worldPoint) const;  
  251.   
  252.     /// 获取 local 点的 world 速度  
  253.     /// @param 一个本地坐标系中的点  
  254.     /// @return 一个点的 world 速度  
  255.     b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2& localPoint) const;  
  256.   
  257.     ///获取这个 body 的线性阻尼  
  258.     float32 GetLinearDamping() const;  
  259.   
  260.     /// Set 这个 body 的线性阻尼  
  261.     void SetLinearDamping(float32 linearDamping);  
  262.   
  263.     /// Get body 的阻尼角度  
  264.     float32 GetAngularDamping() const;  
  265.   
  266.     /// Set body 的阻尼角度  
  267.     void SetAngularDamping(float32 angularDamping);  
  268.   
  269.     /// Get 这个 body 的重力比例  
  270.     float32 GetGravityScale() const;  
  271.   
  272.     /// Set 这个 body 的重力比例  
  273.     void SetGravityScale(float32 scale);  
  274.   
  275.     /// Set body 的类型。这可能会改变的质量和速度。  
  276.     void SetType(b2BodyType type);  
  277.   
  278.     /// Get 这个 body 的类型  
  279.     b2BodyType GetType() const;  
  280.   
  281. //    这个 body 是否应该像子弹那样有连续碰撞检测  
  282.     void SetBullet(bool flag);  
  283.   
  284. //   这个 body 是否像子弹那样有连续碰撞检测  
  285.     bool IsBullet() const;  
  286.   
  287.     /// 你可以禁止这个 body 睡眠,如果你禁止睡眠,这个 body 将一直醒着  
  288.     void SetSleepingAllowed(bool flag);  
  289.   
  290.     ///是否允许这个 body 睡眠  
  291.     bool IsSleepingAllowed() const;  
  292.   
  293.     /// 设置这个 body 的睡眠状态,一个睡眠的 body 有一个较低的 CPU 占用  
  294.     /// @param flag set to true to put body to sleep, false to wake it.  
  295.     void SetAwake(bool flag);  
  296.   
  297.     /// 获取这个 body 的睡眠状态  
  298.     /// @return true if the body is sleeping.  
  299.     bool IsAwake() const;  
  300.   
  301.     /// 设置 body 的 active 状态,一个无效的body 不可以被 模拟、碰撞、唤醒  
  302.     /// 如果这个 flag 的值是 true,所有的 fixtures 都会添加到 broad-phase.  
  303.     /// 如果这个 flag 的值是 false,所有的 fixtures 都会从到 broad-phase 里面移除,所有的联系都会被销毁  
  304.     /// Fixtures 必须被添加了,其它情况不受影响。你可以继续 添加/消除 fixtures 到一个不活跃的 body  
  305.     /// fixtures 在一个不活跃的 body 上,他就不会参与 碰撞,射线投射,或查询。  
  306.     /// 添加 fixtures 到一个不活跃的 body 上,它也会不活跃  
  307.     /// 不活跃的 body 仍然保持它的 b2Word 对象  
  308.     void SetActive(bool flag);  
  309.   
  310.     /// 获取 body 的 active 状态  
  311.     bool IsActive() const;  
  312.   
  313.     /// 设置 body 有固定的旋转。这会导致质量被重置。  
  314.     void SetFixedRotation(bool flag);  
  315.   
  316.     /// body 是否有固定的旋转  
  317.     bool IsFixedRotation() const;  
  318.   
  319.     /// 获取联系到这个 body 的所有 fixtures 列表  
  320.     b2Fixture* GetFixtureList();  
  321.     const b2Fixture* GetFixtureList() const;  
  322.   
  323.     /// Get the list of all joints attached to this body.  
  324.     b2JointEdge* GetJointList();  
  325.     const b2JointEdge* GetJointList() const;  
  326.   
  327.     ///获取添加到这个 body 的所有联系  
  328.     /// @warning this list changes during the time step and you may  
  329.     /// miss some collisions if you don't use b2ContactListener.  
  330.     b2ContactEdge* GetContactList();  
  331.     const b2ContactEdge* GetContactList() const;  
  332.   
  333.     /// 获取 world's body 列表里面的下一个 body.  
  334.     b2Body* GetNext();  
  335.     const b2Body* GetNext() const;  
  336.   
  337.     /// 获取 body 里面提供的用户指针数据  
  338.     void* GetUserData() const;  
  339.   
  340.     /// Set  body 里面提供的用户指针数据  
  341.     void SetUserData(void* data);  
  342.   
  343.     /// Get the parent world of this body.  
  344.     b2World* GetWorld();  
  345.     const b2World* GetWorld() const;  
  346.   
  347. //    把 body 的阻尼输出到一个日志文件  
  348.     void Dump();  
  349.   
  350. private:  
  351.   
  352.     friend class b2World;  
  353.     friend class b2Island;  
  354.     friend class b2ContactManager;  
  355.     friend class b2ContactSolver;  
  356.     friend class b2Contact;  
  357.       
  358.     friend class b2DistanceJoint;  
  359.     friend class b2GearJoint;  
  360.     friend class b2WheelJoint;  
  361.     friend class b2MouseJoint;  
  362.     friend class b2PrismaticJoint;  
  363.     friend class b2PulleyJoint;  
  364.     friend class b2RevoluteJoint;  
  365.     friend class b2WeldJoint;  
  366.     friend class b2FrictionJoint;  
  367.     friend class b2RopeJoint;  
  368.   
  369.     // m_flags  
  370.     enum  
  371.     {  
  372.         e_islandFlag        = 0x0001,  
  373.         e_awakeFlag            = 0x0002,  
  374.         e_autoSleepFlag        = 0x0004,  
  375.         e_bulletFlag        = 0x0008,  
  376.         e_fixedRotationFlag    = 0x0010,  
  377.         e_activeFlag        = 0x0020,  
  378.         e_toiFlag            = 0x0040  
  379.     };  
  380.   
  381.     b2Body(const b2BodyDef* bd, b2World* world);  
  382.     ~b2Body();  
  383.   
  384.     void SynchronizeFixtures();  
  385.     void SynchronizeTransform();  
  386.   
  387.     // 这个用来防止连接机构碰撞  
  388.     // 它可能 lie(不一样),这取决于collideConnected标志  
  389.     bool ShouldCollide(const b2Body* other) const;  
  390.   
  391.     void Advance(float32 t);  
  392.   
  393.     b2BodyType m_type;  
  394.   
  395.     uint16 m_flags;  
  396.   
  397.     int32 m_islandIndex;  
  398.   
  399.     b2Transform m_xf;        //  body 的转换原点  
  400.     b2Sweep m_sweep;        // the swept motion for CCD //CCD 的打扫运动  
  401.   
  402.     b2Vec2 m_linearVelocity;  
  403.     float32 m_angularVelocity;  
  404.   
  405.     b2Vec2 m_force;  
  406.     float32 m_torque;  
  407.   
  408.     b2World* m_world;  
  409.     b2Body* m_prev;  
  410.     b2Body* m_next;  
  411.   
  412.     b2Fixture* m_fixtureList;  
  413.     int32 m_fixtureCount;  
  414.   
  415.     b2JointEdge* m_jointList;  
  416.     b2ContactEdge* m_contactList;  
  417.   
  418.     float32 m_mass, m_invMass;  
  419.   
  420.     // 质心的转动惯量  
  421.     float32 m_I, m_invI;  
  422.   
  423.     float32 m_linearDamping;  
  424.     float32 m_angularDamping;  
  425.     float32 m_gravityScale;  
  426.   
  427.     float32 m_sleepTime;  
  428.   
  429.     void* m_userData;  
  430. };  
  431.   
  432. inline b2BodyType b2Body::GetType() const  
  433. {  
  434.     return m_type;  
  435. }  
  436.   
  437. inline const b2Transform& b2Body::GetTransform() const  
  438. {  
  439.     return m_xf;  
  440. }  
  441.   
  442. inline const b2Vec2& b2Body::GetPosition() const  
  443. {  
  444.     return m_xf.p;  
  445. }  
  446.   
  447. inline float32 b2Body::GetAngle() const  
  448. {  
  449.     return m_sweep.a;  
  450. }  
  451.   
  452. inline const b2Vec2& b2Body::GetWorldCenter() const  
  453. {  
  454.     return m_sweep.c;  
  455. }  
  456.   
  457. inline const b2Vec2& b2Body::GetLocalCenter() const  
  458. {  
  459.     return m_sweep.localCenter;  
  460. }  
  461.   
  462. inline void b2Body::SetLinearVelocity(const b2Vec2& v)  
  463. {  
  464.     if (m_type == b2_staticBody)  
  465.     {  
  466.         return;  
  467.     }  
  468.   
  469.     if (b2Dot(v,v) > 0.0f)  
  470.     {  
  471.         SetAwake(true);  
  472.     }  
  473.   
  474.     m_linearVelocity = v;  
  475. }  
  476.   
  477. inline b2Vec2 b2Body::GetLinearVelocity() const  
  478. {  
  479.     return m_linearVelocity;  
  480. }  
  481.   
  482. inline void b2Body::SetAngularVelocity(float32 w)  
  483. {  
  484.     if (m_type == b2_staticBody)  
  485.     {  
  486.         return;  
  487.     }  
  488.   
  489.     if (w * w > 0.0f)  
  490.     {  
  491.         SetAwake(true);  
  492.     }  
  493.   
  494.     m_angularVelocity = w;  
  495. }  
  496.   
  497. inline float32 b2Body::GetAngularVelocity() const  
  498. {  
  499.     return m_angularVelocity;  
  500. }  
  501.   
  502. inline float32 b2Body::GetMass() const  
  503. {  
  504.     return m_mass;  
  505. }  
  506.   
  507. inline float32 b2Body::GetInertia() const  
  508. {  
  509.     return m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);  
  510. }  
  511.   
  512. inline void b2Body::GetMassData(b2MassData* data) const  
  513. {  
  514.     data->mass = m_mass;  
  515.     data->I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);  
  516.     data->center = m_sweep.localCenter;  
  517. }  
  518.   
  519. inline b2Vec2 b2Body::GetWorldPoint(const b2Vec2& localPoint) const  
  520. {  
  521.     return b2Mul(m_xf, localPoint);  
  522. }  
  523.   
  524. inline b2Vec2 b2Body::GetWorldVector(const b2Vec2& localVector) const  
  525. {  
  526.     return b2Mul(m_xf.q, localVector);  
  527. }  
  528.   
  529. inline b2Vec2 b2Body::GetLocalPoint(const b2Vec2& worldPoint) const  
  530. {  
  531.     return b2MulT(m_xf, worldPoint);  
  532. }  
  533.   
  534. inline b2Vec2 b2Body::GetLocalVector(const b2Vec2& worldVector) const  
  535. {  
  536.     return b2MulT(m_xf.q, worldVector);  
  537. }  
  538.   
  539. inline b2Vec2 b2Body::GetLinearVelocityFromWorldPoint(const b2Vec2& worldPoint) const  
  540. {  
  541.     return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.c);  
  542. }  
  543.   
  544. inline b2Vec2 b2Body::GetLinearVelocityFromLocalPoint(const b2Vec2& localPoint) const  
  545. {  
  546.     return GetLinearVelocityFromWorldPoint(GetWorldPoint(localPoint));  
  547. }  
  548.   
  549. inline float32 b2Body::GetLinearDamping() const  
  550. {  
  551.     return m_linearDamping;  
  552. }  
  553.   
  554. inline void b2Body::SetLinearDamping(float32 linearDamping)  
  555. {  
  556.     m_linearDamping = linearDamping;  
  557. }  
  558.   
  559. inline float32 b2Body::GetAngularDamping() const  
  560. {  
  561.     return m_angularDamping;  
  562. }  
  563.   
  564. inline void b2Body::SetAngularDamping(float32 angularDamping)  
  565. {  
  566.     m_angularDamping = angularDamping;  
  567. }  
  568.   
  569. inline float32 b2Body::GetGravityScale() const  
  570. {  
  571.     return m_gravityScale;  
  572. }  
  573.   
  574. inline void b2Body::SetGravityScale(float32 scale)  
  575. {  
  576.     m_gravityScale = scale;  
  577. }  
  578.   
  579. inline void b2Body::SetBullet(bool flag)  
  580. {  
  581.     if (flag)  
  582.     {  
  583.         m_flags |= e_bulletFlag;  
  584.     }  
  585.     else  
  586.     {  
  587.         m_flags &= ~e_bulletFlag;  
  588.     }  
  589. }  
  590.   
  591. inline bool b2Body::IsBullet() const  
  592. {  
  593.     return (m_flags & e_bulletFlag) == e_bulletFlag;  
  594. }  
  595.   
  596. inline void b2Body::SetAwake(bool flag)  
  597. {  
  598.     if (flag)  
  599.     {  
  600.         if ((m_flags & e_awakeFlag) == 0)  
  601.         {  
  602.             m_flags |= e_awakeFlag;  
  603.             m_sleepTime = 0.0f;  
  604.         }  
  605.     }  
  606.     else  
  607.     {  
  608.         m_flags &= ~e_awakeFlag;  
  609.         m_sleepTime = 0.0f;  
  610.         m_linearVelocity.SetZero();  
  611.         m_angularVelocity = 0.0f;  
  612.         m_force.SetZero();  
  613.         m_torque = 0.0f;  
  614.     }  
  615. }  
  616.   
  617. inline bool b2Body::IsAwake() const  
  618. {  
  619.     return (m_flags & e_awakeFlag) == e_awakeFlag;  
  620. }  
  621.   
  622. inline bool b2Body::IsActive() const  
  623. {  
  624.     return (m_flags & e_activeFlag) == e_activeFlag;  
  625. }  
  626.   
  627. inline void b2Body::SetFixedRotation(bool flag)  
  628. {  
  629.     if (flag)  
  630.     {  
  631.         m_flags |= e_fixedRotationFlag;  
  632.     }  
  633.     else  
  634.     {  
  635.         m_flags &= ~e_fixedRotationFlag;  
  636.     }  
  637.   
  638.     ResetMassData();  
  639. }  
  640.   
  641. inline bool b2Body::IsFixedRotation() const  
  642. {  
  643.     return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;  
  644. }  
  645.   
  646. inline void b2Body::SetSleepingAllowed(bool flag)  
  647. {  
  648.     if (flag)  
  649.     {  
  650.         m_flags |= e_autoSleepFlag;  
  651.     }  
  652.     else  
  653.     {  
  654.         m_flags &= ~e_autoSleepFlag;  
  655.         SetAwake(true);  
  656.     }  
  657. }  
  658.   
  659. inline bool b2Body::IsSleepingAllowed() const  
  660. {  
  661.     return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;  
  662. }  
  663.   
  664. inline b2Fixture* b2Body::GetFixtureList()  
  665. {  
  666.     return m_fixtureList;  
  667. }  
  668.   
  669. inline const b2Fixture* b2Body::GetFixtureList() const  
  670. {  
  671.     return m_fixtureList;  
  672. }  
  673.   
  674. inline b2JointEdge* b2Body::GetJointList()  
  675. {  
  676.     return m_jointList;  
  677. }  
  678.   
  679. inline const b2JointEdge* b2Body::GetJointList() const  
  680. {  
  681.     return m_jointList;  
  682. }  
  683.   
  684. inline b2ContactEdge* b2Body::GetContactList()  
  685. {  
  686.     return m_contactList;  
  687. }  
  688.   
  689. inline const b2ContactEdge* b2Body::GetContactList() const  
  690. {  
  691.     return m_contactList;  
  692. }  
  693.   
  694. inline b2Body* b2Body::GetNext()  
  695. {  
  696.     return m_next;  
  697. }  
  698.   
  699. inline const b2Body* b2Body::GetNext() const  
  700. {  
  701.     return m_next;  
  702. }  
  703.   
  704. inline void b2Body::SetUserData(void* data)  
  705. {  
  706.     m_userData = data;  
  707. }  
  708.   
  709. inline void* b2Body::GetUserData() const  
  710. {  
  711.     return m_userData;  
  712. }  
  713.   
  714. inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point)  
  715. {  
  716.     if (m_type != b2_dynamicBody)  
  717.     {  
  718.         return;  
  719.     }  
  720.   
  721.     if (IsAwake() == false)  
  722.     {  
  723.         SetAwake(true);  
  724.     }  
  725.   
  726.     m_force += force;  
  727.     m_torque += b2Cross(point - m_sweep.c, force);  
  728. }  
  729.   
  730. inline void b2Body::ApplyForceToCenter(const b2Vec2& force)  
  731. {  
  732.     if (m_type != b2_dynamicBody)  
  733.     {  
  734.         return;  
  735.     }  
  736.   
  737.     if (IsAwake() == false)  
  738.     {  
  739.         SetAwake(true);  
  740.     }  
  741.   
  742.     m_force += force;  
  743. }  
  744.   
  745. inline void b2Body::ApplyTorque(float32 torque)  
  746. {  
  747.     if (m_type != b2_dynamicBody)  
  748.     {  
  749.         return;  
  750.     }  
  751.   
  752.     if (IsAwake() == false)  
  753.     {  
  754.         SetAwake(true);  
  755.     }  
  756.   
  757.     m_torque += torque;  
  758. }  
  759.   
  760. inline void b2Body::ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point)  
  761. {  
  762.     if (m_type != b2_dynamicBody)  
  763.     {  
  764.         return;  
  765.     }  
  766.   
  767.     if (IsAwake() == false)  
  768.     {  
  769.         SetAwake(true);  
  770.     }  
  771.     m_linearVelocity += m_invMass * impulse;  
  772.     m_angularVelocity += m_invI * b2Cross(point - m_sweep.c, impulse);  
  773. }  
  774.   
  775. inline void b2Body::ApplyAngularImpulse(float32 impulse)  
  776. {  
  777.     if (m_type != b2_dynamicBody)  
  778.     {  
  779.         return;  
  780.     }  
  781.   
  782.     if (IsAwake() == false)  
  783.     {  
  784.         SetAwake(true);  
  785.     }  
  786.     m_angularVelocity += m_invI * impulse;  
  787. }  
  788.   
  789. inline void b2Body::SynchronizeTransform()  
  790. {  
  791.     m_xf.q.Set(m_sweep.a);  
  792.     m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter);  
  793. }  
  794.   
  795. inline void b2Body::Advance(float32 alpha)  
  796. {  
  797.     // 提前新的安全时间. 这个不同步 broad-phase.  
  798.     m_sweep.Advance(alpha);  
  799.     m_sweep.c = m_sweep.c0;  
  800.     m_sweep.a = m_sweep.a0;  
  801.     m_xf.q.Set(m_sweep.a);  
  802.     m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter);  
  803. }  
  804.   
  805. inline b2World* b2Body::GetWorld()  
  806. {  
  807.     return m_world;  
  808. }  
  809.   
  810. inline const b2World* b2Body::GetWorld() const  
  811. {  
  812.     return m_world;  
  813. }  
  814.   
  815. #endif  
0 0