# 我是小陈

@JJAYCHEN

2020-04-27

## 概览#

GLKMatrix4是从 OpenGL 框架 GLKit 中带过来的，各种函数很全面。

SCNMatrix4 最初是给 SceneKit 使用的，后来扩展到 ARKit 中，矩阵操作函数不够全面，比如没有转置函数 transpose。

simd_float4x4 看名字就知道是 simd 类型的，是后来为了取代 SCNMatrix4 来推出的，各种函数也很全面。

## 探究#

### Column Major#

import SceneKit

let translation = SCNMatrix4MakeTranslation(1, 2, 3)

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


Note: Transform is an SCNMatrix4 which is a 4x4 mathematical matrix. When you see a reference, like m41, for example, it’s referring to row 4, column 1 of the matrix. Each row in the matrix relates to a speciﬁc transform value, like its translation, rotation and scale.

### Matrix Content#

$$\left[\begin{array}{llll}x_x & y_x & z_x & t_x \\ x_y & y_y & z_y & t_y \\ x_z & y_z & z_z & t_z \\ 0 & 0 & 0 & 1\end{array}\right]$$

let distance = simd_distance(focusNode.simdPosition,
simd_make_float3(transform.m41,
transform.m42,
transform.m43))
let direction = SCNVector3(-(distance * 2.5) * transform.m31,
-(distance * 2.5) * (transform.m32 - Float.pi / 4),
-(distance * 2.5) * transform.m33)


This transform creates a local coordinate space for the camera that is constant with respect to device orientation. In camera space, the x-axis points to the right when the device is in UIDeviceOrientation.landscapeRight orientation—that is, the x-axis always points along the long axis of the device, from the front-facing camera toward the Home button. The y-axis points upward (with respect to UIDeviceOrientation.landscapeRight orientation), and the z-axis points away from the device on the screen side.