大佬教程收集整理的这篇文章主要介绍了c – 计算两个3D矢量与恒定加速度对齐所需的转矩?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这很难,因为在我的情况下,扭矩的强度不能改变,它可以打开或关闭.这是完全的力量或没有力量.计算扭矩需要施加的方向相对容易,但是我无法使其完全对齐而不会失去控制并陷入逻辑循环.它需要在恰当的“时间”施加相反的力,以零角速度着陆在目标方向上.
到目前为止我所确定的是,我需要根据当前的角速度和两个矢量之间的角度计算达到零速度所需的“时间”.如果超过我达到零角度的时间,则需要施加相反的扭矩.从理论上讲,这也可以防止它在轴周围“弹跳”太多.我几乎让它工作,但在某些情况下似乎卡在一个方向施加力,所以我希望有人可以检查逻辑.我的模拟目前不考虑质量,因此您可以忽略惯性张量(除非它使计算更容易!)
对于一个轴,我目前正在这样做,但我认为有人会有一个更优雅的解决方案,实际上可以同时计算Yaw和Pitch轴(Roll无效).
Omega = Angular VeLocity in Local-Space (degrees Per Second) Force = Strength of the Thrusters // Calculate Time Variables float Angle = AcosD(DotProduct(ForWARDVector,DirectionVector)); float Time1 = Abs(Angle / Omega.z); // Time taken to reach angle 0 at current veLocity float Time2 = Abs(DeltaTime * (Omega.Z / ForcE); // Time it will take to reach Zero veLocity based on force strength. // Calculate Direction we need to apply the force to rotate toWARD the target direction. Note that if we are at perfect opposites,this will be zero! float AngleSign = Sign(DotProduct(RightVector,DirectionVector)); float Torque.Z = 0; if (Time1 < Time2) { Torque.Z = AngleSign * Force; } else { Torque.Z = AngleSign * Force * -1.0f } // Torque is applied to object as a change in acceleration (no mass) and modified by DeltaSeconds for frame-rate independent force.
这远非优雅,肯定有一些标志问题.你们有没有人知道更好的方法来达到这个目的?
编辑:
如果有人理解虚幻引擎的蓝图系统,这就是我在将其移动到C之前的原型.
// Calculate Direction we need to apply the force to rotate toWARD the target direction Torque = CrossProduct(DirectionVector,ForWARDVector) Torque = Normalize(TorquE) * Force if (Time2 < Time1) { Torque = -Torque }
但你应该处理有问题的案件:
// Calculate Direction we need to apply the force to rotate toWARD the target direction Torque = CrossProduct(DirectionVector,ForWARDVector) if (Angle < 0.1 degrees) { // Avoid divide by zero in Normalize Torque = {0,0} } else { // Handle case of exactly opposite direction (where CrossProduct is zero) if (Angle > 179.9 degrees) { Torque = {0,1} } Torque = Normalize(TorquE) * Force if (Time2 < Time1) { Torque = -Torque } }
以上是大佬教程为你收集整理的c – 计算两个3D矢量与恒定加速度对齐所需的转矩?全部内容,希望文章能够帮你解决c – 计算两个3D矢量与恒定加速度对齐所需的转矩?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。