我无法在 Unity 中使用与 PyOpenGL.glRotatef 一起使用的 Quanterion 值

I cannot use Quanterion values that i use with PyOpenGL.glRotatef in Unity

我有值 Quaternion(x,y,z,w)=(p0,p1,p2,p3) 在 pyOpenGl

 norm=math.sqrt(program_dict['q0']*program_dict['q0'] + program_dict['q1']*program_dict['q1'] + program_dict['q2']*program_dict['q2'] + program_dict['q3']*program_dict['q3'])
    glPushMatrix()
    if (norm == 0):
        pass
    else:
        program_dict['q0'] = program_dict['q0'] / norm
        program_dict['q1'] = program_dict['q1'] / norm
        program_dict['q2'] = program_dict['q2'] / norm
        program_dict['q3'] = program_dict['q3'] / norm
        theta = ( math.acos(program_dict['q3'])*2)
        aNorm =  math.sqrt(program_dict['q1'] * program_dict['q1'] + program_dict['q2'] * program_dict['q2'] + program_dict['q0'] * program_dict['q0'])
        if (aNorm != 0):
            glRotatef(theta*180.0/math.pi, program_dict['q2']/aNorm, -program_dict['q0']/aNorm, program_dict['q1']/aNorm)
        else:
            glRotatef(theta*180.0/math.pi, program_dict['q2'], -program_dict['q0'], program_dict['q1']) 

我先将数据归一化(顺便说一句,数据来自原型设备,因此必须对其进行归一化) 我如何在 c# Unity 中使用它并旋转对象?我不知道 Unity 单位是如何工作的...

这里的混淆是在轴角表示和四元数之间。你用的glRotatef用的是前者,而Unity的TransformrotationlocalRotation是后者。

但是您可以在两者之间进行转换。 Quaternion.AngleAxis(float angle, Vector3 axis) 正是这样做的。它采用轴角表示并将其转换为相应的四元数。例如,您可以将其输入 localRotation