[英]How to calculate pitch angle between two 3d vectors
我正在我的 spacesim 游戲中制作一個 AI,並試圖在敵人的方向矢量和指向某個目標的方向之間進行俯仰和偏航。 以下是向目標移動的方法:
private void moveTo(Vecf target) {
if (target == null)
return;
Vecf dir = getForward();
Vecf dirToTarget = Vecf.sub(target, pos).normalize();
float dYaw = getYaw(dir, dirToTarget);
float dPitch = getPitch(dir, dirToTarget);
rotate(dPitch, dYaw);
moveForward();
}
我已經編寫了getYaw(Vecf v1, Vecf v2)
方法,但我不知道如何處理音高。 有人可以幫我弄這個嗎? 順便說一句,角度以弧度為單位。
你需要前向和向上向量來計算俯仰和偏航
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.