【讨论】 quaternionFromAxis 与 Quat.fromMat3 源码设计

先贴代码

https://github.com/cocos-creator/engine/blob/v3.4.0/editor/assets/chunks/transform.chunk#L11#L52

https://github.com/cocos-creator/engine/blob/v3.4.0/cocos/core/math/quat.ts#L424#L430
https://github.com/cocos-creator/engine/blob/b11686b4dcb7754cfad8e0a1d71d7649eff62fa4/cocos/core/math/quat.ts#L461#L501

image

根据 Maths - Conversion Matrix to Quaternion - Martin Baker 中的推导公式
image

quat.ts 是正确的,而 transform.chunk 中的 quaternionFromAxis 计算的是转置矩阵的quaternion (因为GLSL中是列主序)

再看一眼调用的地方,https://github.com/cocos-creator/engine/blob/v3.4.0/editor/assets/chunks/particle-common.chunk#L35#L39

axi 又刚好传的是转置,所以转置了两次,刚好结果又对上了。

所以,为什么要写的这么绕呢? :face_with_monocle:

1赞

Q2: fromRTS 为啥不写成 fromSRTfromTRS