libGDX 设置旋转点 3D [英] libGDX set rotation point 3D
本文介绍了libGDX 设置旋转点 3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个对象基地和武器,我需要将武器的旋转点设置为基地的位置.
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
,例如translate(3, 0, 0)
- 围绕中心旋转(现在是
rotationPoint
),例如rotate(0,1,0, 45*delta)
- 平移回来(平移是相对于旋转的),例如
translate(-3, 0, 0);
- Translate to the
rotationPoint
, for exampletranslate(3, 0, 0)
- Rotate arround the center (which is now the
rotationPoint
), for examplerotate(0,1,0, 45*delta)
- Translate back (the translation is relative to the rotation), for example
translate(-3, 0, 0);
在这种情况下,代码如下所示:
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);
这篇关于libGDX 设置旋转点 3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文