c++ 找到两点之间的“注视旋转”的算法步骤是什么?

ddrv8njm  于 2023-04-08  发布在  其他
关注(0)|答案(1)|浏览(80)

我想在一段时间内将ObjectA的旋转方向向ObjectB的位置进行SERP。我正在进行的插值,我无法弄清楚的是如何产生DestinationRotation(旋转方向,或ObjectA最终需要达到的旋转)
实现这一目标的步骤是什么?
我有什么可用:
1.两个对象的vector3旋转

  1. vector3两个对象的位置
    1.两个对象的vector3轴
    1.每个对象的Angular
    1.两个对象之间位置X、Y的点积
    1.两向量间的欧氏距离
    1.每个对象的局部上方向向量
    1.每个对象的局部前向向量
    如何计算旋转外观?
    注意:这是使用虚幻引擎空间数学库的Verse编程语言,但我的问题不是代码,而是知道以何种顺序使用哪些工具(数学)。
loop:
        Sleep(0.0)
        CurrentTime := GetSimulationElapsedTime()
        DeltaTime := CurrentTime - PreviousTime
        set PreviousTime = CurrentTime
        var MoveToPosition : vector2 = vector2{X := 0.0, Y := 0.0}

        # Player Current Position
        if (Agent := agent[Player], FortChar := Agent.GetFortCharacter[], Trans := FortChar.GetTransform(), Position := Trans.Translation):
                set MoveToPosition = vector2{X := Position.X, Y := Position.Y}
        
        SpiderTrans := Spider.GetTransform()
        SpiderVec := SpiderTrans.Translation
        CurrentSpiderRotation := SpiderTrans.Rotation
        CurrentSpiderPos := vector2{X := SpiderVec.X, Y := SpiderVec.Y}
        DeltaSpeed := SpiderSpeed * DeltaTime
        NewPos := Lerp(CurrentSpiderPos, MoveToPosition, DeltaSpeed)
        
        FinalMoveVector := vector3{X := NewPos.X, Y := NewPos.Y, Z := SpiderVec.Z}
       
        # This is where my rotation gets wonky
        DP := DotProduct(CurrentSpiderPos, MoveToPosition)
        var NewRotation : rotation = CurrentSpiderRotation.ApplyLocalRotationZ(DP)
        if (set NewRotation = Slerp[CurrentSpiderRotation,NewRotation, SpiderSpeed]) {}

        # Movement works fine, but rotation is all over the place
        if (Spider.TeleportTo[FinalMoveVector, NewRotation]) {}
iq3niunx

iq3niunx1#

得到位置矢量并减去它们。

你将得到一个从B指向A的矢量,将其归一化并将其用作旋转目标。
编辑:注意,归一化之前的矢量幅度将表示距离,所以如果出于某种原因需要,请不要将其归一化。

相关问题