我有两个对象,基地和武器,我需要的武器旋转点设置为基地的地位。
I have two objects base and weapon and I need to set rotate point of weapon to position of base.
public Test(){
position1 = new Vector3(0,0,0);
baseModel = modelLoader.loadModel(Gdx.files.getFileHandle("data/models/tower/bases/base1.g3db", FileType.Internal));
base = new Base(baseModel, position1);
position2 = new Vector3(3,10,5);
weaponModel = modelLoader.loadModel(Gdx.files.getFileHandle("data/models/tower/weapons/weapon2.g3db", FileType.Internal));
weapon = new Weapon(weaponModel, position2);
}
下面是更新方法
public void update(float delta){
weapon.transform.rotate(0, 1, 0, 45*(delta/2));
base.transform.rotate(0, 1, 0, 45*(delta/2));
}
感谢您的答案
点周围的旋转是相同的翻译到该点,旋转和平移然后回来。 所以这个过程包括3个步骤:
A rotation around a point is the same as translating to that point, rotating and then translating back. So this process consists of 3 steps:
转换到 rotationPoint
,例如翻译(3,0,0)
旋转约于中心(也就是现在的 rotationPoint
),例如旋转(0,1,0,45 *三角洲)
在转换回(翻译是相对于旋转),例如翻译(-3,0,0)
Translate to the rotationPoint
, for example translate(3, 0, 0)
Rotate arround the center (which is now the rotationPoint
), for example rotate(0,1,0, 45*delta)
Translate back (the translation is relative to the rotation), for example translate(-3, 0, 0);
在这种情况下,code,那么看起来是这样的:
In this case the code then looks like this:
weapon.transform.translate(3, 0, 0).rotate(0,1,0, 45*delta).translate(-3, 0, 0);