Libgdx旋转ModelInstance [英] Libgdx rotate ModelInstance
问题描述
我正在开发我的第一个libgdx 3D游戏。到目前为止,我可以在迷宫般的(硬编码)世界中移动,碰撞检测工作。我也有一些工作A *寻路的敌人。
我还使用 FBX-Conv
来填充我的第一个(相当难看的)Blender模型,以获得 .g3db
文件。由于某种原因,模特在地板上而不是站立。当我将它导出为 .fbx
时,我可能有一些错误的设置。
为此我尝试 rotate()
他围绕 z-Axis
90
度,在中调用:
我的
modelInstance.transform.rotate(Vector3.Z,90)
在加载模型
并实例化我的<$之后,show()屏幕
的方法c $ c> ModelInstance (在给定位置)。由于某种原因,它没有旋转。然后我把 rotate
方法放在渲染(delta)
中,以为它现在每次渲染都会旋转90度环。但它反而停滞不前,就像它应该的那样。
好的,但现在我希望 modelInstance
到旋转
到实际看起来的位置,这意味着它应该旋转,取决于我的 enemie
s Vector3方向
。
我已经用 modelInstance.transform.setTotranslation(enemie.getPosition())
设置了他的位置。所以我想我也可以使用 modelInstance.transform.setToRotation(Vector3 v1,Vector3 vs)
, v1 = enemie.getPosition()
和 v2 = enemie.getPosition()。add(enemie.getDirection)
。请注意,位置
Vector不会直接使用,因为它会在 add()
方法中更改其值。
这样做,我再也看不到对象,这意味着它的位置也是错误的。
为什么会发生这种情况?
如何使用方向
向我的 modelInstance
旋转?
非常感谢。
我用@Xoppas帮助解决了这个问题。问题是:
- 我使用
setToTranslation
来移动我的模型
到给定的位置,但是这会重置轮换
- 我很想念
setToRotation(Vector3,Vector3)
方法。
所以解决方案是去 setToTranslation
首先,然后使用 setToRotation(Vector3方向,Vector3 face)
,其中方向
是我的模型
正在查找的方向, face
是面对
,应该朝这个方向看,在我的情况下 Vector3.X
。
<希望它可以帮助别人。
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.
Why is this happening?
And how can i rotate my modelInstance
by using the direction
vector?
Thanks a lot.
I solved this with @Xoppas help. The problem was:
- i used
setToTranslation
to move myModel
to a given position, but this als resets therotation
- I missunderstood the
setToRotation(Vector3, Vector3)
method.
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
.
Hope it helps someone else.
这篇关于Libgdx旋转ModelInstance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!