这很难,因为在我的情况下,扭矩的强度不能改变,它可以打开或关闭.这是完全的力量或没有力量.计算扭矩需要施加的方向相对容易,但是我无法使其完全对齐而不会失去控制并陷入逻辑循环.它需要在恰当的“时间”施加相反的力,以零角速度着陆在目标方向上.
到目前为止我所确定的是,我需要根据当前的角速度和两个矢量之间的角度计算达到零速度所需的“时间”.如果超过我达到零角度的时间,则需要施加相反的扭矩.从理论上讲,这也可以防止它在轴周围“d跳”太多.我几乎让它工作,但在某些情况下似乎卡在一个方向施加力,所以我希望有人可以检查逻辑.我的模拟目前不考虑质量,因此您可以忽略惯性张量(除非它使计算更容易!)
对于一个轴,我目前正在这样做,但我认为有人会有一个更优雅的解决方案,实际上可以同时计算Yaw和Pitch轴(Roll无效).
Omega = Angular VeLocity in Local-Space (degrees Per Second)Force = Strength of the Thrusters// Calculate Time Variablesfloat Angle = AcosD(DotProduct(ForwardVector,DirectionVector));float Time1 = Abs(Angle / Omega.Z); // Time taken to reach angle 0 at current veLocityfloat 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 directionTorque = Crossproduct(DirectionVector,ForwardVector)Torque = normalize(Torque) * Forceif (Time2 < Time1){ Torque = -Torque}
但你应该处理有问题的案件:
// Calculate Direction we need to apply the force to rotate toward the target directionTorque = 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矢量与恒定加速度对齐所需的转矩?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)