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

标签 ios swift macos opengl-es scenekit

我困惑的根源是关于 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 行优先(将翻译存储在 m14m24m34 中)或列优先也是如此主要(将翻译存储在 m41m42m43 中)?

最佳答案

SCNMatrix4 将翻译存储在 m41m42m43 中,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/

相关文章:

android - 有什么办法可以捕捉电话接听事件吗?

ios - 核心数据撤消/重做 - 操作取决于撤消的内容

ios - 在选定的时间范围内修剪视频

ios - 将文本从 tableview 单元格 swift 传递到 TextField

swift - 我们可以在 SWIFT 中使用关键字作为参数名称吗?

c++ - 是否有 Mac OS X 相当于 Windows 的命名管道

java - Canvas3D 和 Swing

ios - Swift iOS 应用程序中 Nest SDK 的身份验证延迟

iOS9 多行 UITextView 显示不正确

macos - 在 OSX 上将 P4merge 配置为我的 SVN 差异工具