【问题标题】:Is SceneKit's SCNMatrix4 stored as column or row-major?SceneKit 的 SCNMatrix4 是以列为主还是行为主?
【发布时间】:2017-12-07 10:24:25
【问题描述】:

我困惑的根源是来自 Apple 的 SCNMatrix4 上的文档:

SceneKit 使用矩阵来表示坐标空间变换, 这反过来又可以代表组合的位置、旋转或 三维空间中物体的方向和尺度。 SceneKit 矩阵结构是行主要顺序,所以它们是 适合传递给接受矩阵参数的着色器程序或 OpenGL API

这似乎是矛盾的,因为 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 也是行优先(将翻译存储在 m14m24m34)或列优先(将翻译存储在 m41m42m43)?

【问题讨论】:

标签: ios swift macos opengl-es scenekit


【解决方案1】:

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

import SceneKit

let translation = SCNMatrix4MakeTranslation(1, 2, 3)

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-10
    • 2014-02-20
    • 2019-02-17
    • 2019-11-11
    • 1970-01-01
    • 2010-09-15
    • 2010-10-24
    • 1970-01-01
    相关资源
    最近更新 更多