0

我想知道什么(如果有的话)相当于 GLKit 的 CreateFromVectors() 。我看不出这个想法被遗漏了,因为它在 3D 图形编程中发挥了如此重要的功能。我正在尝试将以下内容从 C++ 转换为 Objective-C,并且无法为此触及 C++。有没有人有什么建议?

m_animation.End = Quaternion::CreateFromVectors(vec3(0, 1, 0), direction);

又名:

inline QuaternionT<T> QuaternionT<T>::CreateFromVectors(const Vector3<T>& v0, const Vector3<T>& v1)
{
    if (v0 == -v1)
        return QuaternionT<T>::CreateFromAxisAngle(vec3(1, 0, 0), Pi);

    Vector3<T> c = v0.Cross(v1);
    T d = v0.Dot(v1);
    T s = std::sqrt((1 + d) * 2);

    QuaternionT<T> q;
    q.x = c.x / s;
    q.y = c.y / s;
    q.z = c.z / s;
    q.w = s / 2.0f;
    return q;
}

我也想知道怎么翻译:

mat4 rotation(m_animation.Current.ToMatrix());
glMultMatrixf(rotation.Pointer());

ToMatrix() 是:

inline Matrix3<T> QuaternionT<T>::ToMatrix() const
{
    const T s = 2;
    T xs, ys, zs;
    T wx, wy, wz;
    T xx, xy, xz;
    T yy, yz, zz;
    xs = x * s;  ys = y * s;  zs = z * s;
    wx = w * xs; wy = w * ys; wz = w * zs;
    xx = x * xs; xy = x * ys; xz = x * zs;
    yy = y * ys; yz = y * zs; zz = z * zs;
    Matrix3<T> m;
    m.x.x = 1 - (yy + zz); m.y.x = xy - wz;  m.z.x = xz + wy;
    m.x.y = xy + wz; m.y.y = 1 - (xx + zz); m.z.y = yz - wx;
    m.x.z = xz - wy; m.y.z = yz + wx;  m.z.z = 1 - (xx + yy);
    return m;
}

不幸的是,我对后端的 C++ 类不熟悉,并且不确定它们将如何翻译。

4

0 回答 0