问题描述
我正在开发我的第一个 libgdx 3D 游戏.到目前为止,我可以在类似迷宫(硬编码)的世界中移动,碰撞检测有效.我也有一些使用 A* Pathfinding 的敌人.我还使用 FBX-Conv
获得了一个 .g3db
文件.出于某种原因,模型躺在地板上而不是站立.当我将它导出为 .fbx
时,也许我有一些错误的设置.为此,我尝试通过调用将 rotate()
他围绕 z-Axis
旋转 90
度:modelInstance.transform.rotate(Vector3.Z, 90)
在我的 Screen
的 show()
方法中,加载 Model 后
并实例化我的 ModelInstance
(在给定位置).出于某种原因,它没有旋转.然后我将 rotate
方法放在 render(delta)
中,认为它现在每个渲染循环都会旋转 90 度.但相反,它原地不动,就像它应该的那样.好的,但现在我希望 modelInstance
rotate
到它实际看起来的位置,这意味着它应该旋转,具体取决于我的 enemie
的 Vector3 方向
.我已经准备好用 modelInstance.transform.setTotranslation(enemie.getPosition())
来设置他的位置,这很完美.所以我想我也可以使用 modelInstance.transform.setToRotation(Vector3 v1, Vector3 vs)
,v1 = enemie.getPosition()
和 v2 = enemie.getPosition().add(enemie.getDirection)
.请注意,position
向量不是直接使用的,因为它会在 add()
方法中更改其值.这样做,我再也看不到对象了,这也意味着它的位置是错误的.
I am developing my first libgdx 3D game. Until now i can move arround in a maze-like (hardcoded) world, collision detection works. Also i have some enemies with working A* Pathfinding.I also loded my first (pretty ugly) Blender model, using FBX-Conv
to get a .g3db
file. For some reason the model lise on the floor instead of standing. Maybe i had some wrong settings when i exported it as .fbx
.For that i tryed to rotate()
him arround the z-Axis
by 90
degrees by calling:modelInstance.transform.rotate(Vector3.Z, 90)
in the show()
method of my Screen
, after loading the Model
and instantiating my ModelInstance
(at a given position). For some reason it did not rotate. Then i put the rotate
method in the render(delta)
, thinking, that it would now rotate 90 degrees every render loop. But instead it was standing still, like it should.Okay, but now i want the modelInstance
to rotate
to where it actually looks, meaning it should rotate, depending on my enemie
s Vector3 direction
.I am allready setting his position with modelInstance.transform.setTotranslation(enemie.getPosition())
which works perfect. So i thought i can also use modelInstance.transform.setToRotation(Vector3 v1, Vector3 vs)
, with v1 = enemie.getPosition()
and v2 = enemie.getPosition().add(enemie.getDirection)
. Note, that the position
Vector is not used directly, as it would change its values inside the add()
method.Doing this, i don't see the object anymore, meaning also its position is wrong.
为什么会这样?以及如何使用 direction
向量旋转我的 modelInstance
?
Why is this happening?And how can i rotate my modelInstance
by using the direction
vector?
非常感谢.
推荐答案
我在 @Xoppas 的帮助下解决了这个问题.问题是:
I solved this with @Xoppas help. The problem was:
- 我使用
setToTranslation
将我的Model
移动到给定位置,但这也会重置rotation
- 我误解了
setToRotation(Vector3, Vector3)
方法.
- i used
setToTranslation
to move myModel
to a given position, but this als resets therotation
- I missunderstood the
setToRotation(Vector3, Vector3)
method.
所以解决办法是先setToTranslation
,然后使用setToRotation(Vector3 direction, Vector3 face)
,其中direction
是方向,我的 Model
正在看,face
是 face
,它应该朝这个方向看,在我的例子中是 Vector3.X
.
So the solution was to to the setToTranslation
first, and then use setToRotation(Vector3 direction, Vector3 face)
, where direction
is the direction, in which my Model
is looking and face
is the face
, which should look in this direction, in my case the Vector3.X
.
希望能帮到别人.
这篇关于Libgdx 旋转模型实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!