SceneKit 的 SCNMatrix4 存储为列优先还是行优先?

Is SceneKit's SCNMatrix4 stored as column or row-major?

我的困惑来自 Apple 的 SCNMatrix4 文档:

SceneKit uses matrices to represent coordinate space transformations, which in turn can represent the combined position, rotation or orientation, and scale of an object in three-dimensional space. SceneKit matrix structures are in row-major order, so they are suitable for passing to shader programs or OpenGL APIs that accept matrix parameters.

这似乎是矛盾的,因为 OpenGL 使用列优先变换矩阵!

总体而言,Apple 关于此主题的文档很差:

来自simd/float.h

typedef struct { simd_float4 columns[4]; } simd_float4x4;

一些关于 SCNMatrix4 的在线讨论好像 SCNMatrix4 与 GLKMatrix4 不同,但查看 SCNMatrix4 的代码给出了一些提示,它可能只是预期的列顺序:

/* Returns a transform that translates by '(tx, ty, tz)':
 * m' =  [1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1]. */
NS_INLINE SCNMatrix4 SCNMatrix4MakeTranslation(float tx, float ty, float tz) {
    SCNMatrix4 m = SCNMatrix4Identity;
    m.m41 = tx;
    m.m42 = ty;
    m.m43 = tz;
    return m;
}

SCNMatrix4 行优先(在 m14m24m34 中存储翻译)或列优先(在 m41 中存储翻译) , m42, m43)?

SCNMatrix4 将翻译存储在 m41m42m43 中,GLKMatrix4 也是如此。这个小游乐场证实了这一点及其定义。

import SceneKit

let translation = SCNMatrix4MakeTranslation(1, 2, 3)

translation.m41
// 1
translation.m42
// 2
translation.m43
// 3

我不知道为什么文档中的这个是错误的,可能只是一个错误。