简体   繁体   中英

Libgdx rotate ModelInstance

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:

  1. i used setToTranslation to move my Model to a given position, but this als resets the rotation
  2. 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.

更糟糕的情况是,您可以使用以下方法修改转换矩阵:

ModelInstance.transform.rotate()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM