简体   繁体   English

libGDX 3D使用转速系数将ModelInstance旋转到第二个

[英]libGDX 3D rotate ModelInstance to the second one with a coefficient of rotation speed

I'm working on 3D tower defence and I need some help with rotation of a ModelInstance. 我正在研究3D塔防,我需要一些有关ModelInstance旋转的帮助。 How to rotate the ModelInstance to the second one with a coefficient of rotation speed. 如何使用转速系数将ModelInstance旋转到第二个。

For example: rotate base(or weapon) to enemy 例如:旋转基地(或武器)到敌人

Thanks for help. 感谢帮助。

Actually you should never rotate a ModelInstance to face another ModelInstance , but you should rotate it to an angle given by the gamelogic. 实际上,您永远不应旋转ModelInstance使其面对另一个ModelInstance ,而应将其旋转到gamelogic给定的角度。
That means, that you should sepperate the logic and the view. 这意味着,您应该将逻辑和视图分开。
In this case the logic needs to store the currentAngle and the desiredAngle , as well as a rotationSpeed . 在这种情况下所述逻辑需要存储currentAngledesiredAngle ,以及一个rotationSpeed
The desiredAngle can be calculated out of the position s of the Tower and the Enemy . desiredAngle可以计算出的position的第TowerEnemy
In the update(delta) you can then say: 然后可以在update(delta)说:

if (desiredAngle > currentAngle)
    currentAngle+=rotationSpeed*delta;

The same for the negative rotation and ensure to keep rotation between 0 and 360°. 负向旋转相同,并确保将旋转保持在0到360°之间。

You can then rotate the ModelInstance to the given currentAngle by rotating its Matrix4 transform , i gues the rotate(float axisX, float axisY, float axisZ, float degrees) should be the rigth one. 然后,您可以旋转ModelInstance给定currentAngle通过旋转其Matrix4 transform ,我客串的rotate(float axisX, float axisY, float axisZ, float degrees)应该是一个分辩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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