执行此操作的正确方法是确定 hmd 方向与所需点的所需视图方向之间的转换。我把这个时间称为零,尽管时间与它无关,实际上它是“家”的方向。一旦知道变换,就可以使用来自 hmd 的数据来确定视图方向,因为可以认为 hmd 和视图的坐标系安装在同一个刚体上(这意味着它们的相对变换不会改变随着时间的推移)。
这是数学:

这是我的编码方式(它有效!):
import numpy as np
import math
#setup the desired calibration transformation (hmd orientation that will result in looking straight ahead
#Euler angles for the hmd at desired "zero" orientation
a0 = -177.9*math.pi/180
b0 = 31.2*math.pi/180
g0 = 90.4*math.pi/180
#make the matrices
Ra0 = np.matrix([[1,0,0],[0, float(math.cos(a0)),float(-1*math.sin(a0))],[0,float(math.sin(a0)),float(math.cos(a0))]],dtype=np.float)
Rb0 = np.matrix([[math.cos(b0),0,math.sin(b0)],[0,1,0],[-1*math.sin(b0),0,math.cos(b0)]],dtype=np.float)
Rg0 = np.matrix([[math.cos(g0),-1*math.sin(g0),0],[math.sin(g0),math.cos(g0),0],[0,0,1]],dtype=np.float)
#the hmd rotation matrix in the "zero" orientation
global RhmdU0
RhmdU0 = Ra0*Rb0*Rg0
#the view orientation when the hmd is in the "zero" orientation (basically a zero degree turn about the Z axis)
global RdU0
RdU0 = np.matrix([[1,0,0],[0,1,0],[0,0,1]],dtype=np.float)
#this can be called in a loop, inputs are Euler angles of the hmd
def InverseK(at,bt,gt):
global RdU0
global RhmdU0
#given 3 Euler sequence of the hmd in universal space, determine the viewpoint
Rat = np.matrix([[1,0,0],[0, float(math.cos(at)), float(-1*math.sin(at))],[0,float(math.sin(at)),float(math.cos(at))]],dtype=np.float)
Rbt = np.matrix([[math.cos(bt),0,math.sin(bt)],[0,1,0],[-1*math.sin(bt),0,math.cos(bt)]],dtype=np.float)
Rgt = np.matrix([[math.cos(gt),-1*math.sin(gt),0],[math.sin(gt),math.cos(gt),0],[0,0,1]],dtype=np.float)
RhmdUt = Rat*Rbt*Rgt
RdUt = RhmdUt*RhmdU0.transpose()*RdU0
#do inverse K to get euler sequence out:
beta = math.atan2(RdUt[0,2],math.sqrt(RdUt[1,2]**2+RdUt[2,2]**2))
alpha = math.atan2(-1*RdUt[1,2]/math.cos(beta),RdUt[2,2]/math.cos(beta))
gamma = math.atan2(-1*RdUt[0,1]/math.cos(beta),RdUt[0,0]/math.cos(beta))
return(alpha,beta,gamma)