Box2d c++ what is the similar to ActionScript b2Body SetPosi

Box2d c++ what is the similar to ActionScript b2Body SetPosition?

本文关键字:to ActionScript b2Body SetPosi similar the c++ what is Box2d      更新时间:2023-10-16

i 尝试将一些代码从 ActionScript 移植到 c++ box2d
来自 ActionScript 的代码来自 2011 年,所以我不确定它使用的是哪个版本的 box2d。
我使用最新的.
无论如何,这就是我在操作脚本中所拥有的:

    var leftAxle:b2Body=world.CreateBody(leftAxleBodyDef);
    leftAxle.CreateFixture(leftAxleFixture);
// this is the part i need to port , there is no SetPosition in the box2d 2.2+ version 
    leftAxle.SetPosition(new b2Vec2(carPosX/worldScale-axleContainerDistance/worldScale-axleContainerHeight/worldScale*Math.cos((90-axleAngle)*degreesToRadians),carPosY/worldScale+axleContainerDepth/worldScale+axleContainerHeight/worldScale*Math.sin((90-axleAngle)*degreesToRadians)));

用斜边角的盒子

抱歉,以为你正在从C++转换为AS3

快速浏览代码:https://github.com/cocos2d/cocos2d-x/blob/ac2c0469c71eaabff38f545ce956859627f2b7fc/external/Box2D/Dynamics/b2Body.cpp

看来SetPosition()现在SetTransform(const b2Vec2& position, float32 angle).这是因为他们在幕后将位置和轮换作为b2Transform。即使是GetPosition()也只是返回b2Transformposition属性