我困惑的根源是关于 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 关于此主题的文档很差:
- GLKMatrix4根本不谈论列与行专业,但是 我从所有在线讨论中确信 GLKMatrix 是简单且 简单的专栏专业。
- simd_float4x4 不谈 主题,但至少变量名称清楚地表明它是 存储为列:
来自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
行优先(将翻译存储在 m14
、m24
、m34
中)或列优先也是如此主要(将翻译存储在 m41
、m42
、m43
中)?
最佳答案
SCNMatrix4
将翻译存储在 m41
、m42
和 m43
中,GLKMatrix4也是如此
。这个小 Playground 证实了这一点及其定义。
import SceneKit
let translation = SCNMatrix4MakeTranslation(1, 2, 3)
translation.m41
// 1
translation.m42
// 2
translation.m43
// 3
我不知道为什么这在文档中是错误的,可能只是一个错误。
关于ios - SceneKit 的 SCNMatrix4 存储为列优先还是行优先?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44897619/