1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

glm で quaternion を使うときはコンポーネントの順番に気を付ける

Posted at

glm

コンポーネントの順番に気をつかないと, 4 要素配列から glm::quat を作ったり, その逆でハマります.

glm は以前までは wxyz 順でコンポーネントを扱っていたような気がしますが, 最近(少なくとも 0.9.9.6 から?) では xyzw になりました.

とりあえず 0.9.9.7 を使い, xyzw 順で扱うようにすればよいです.

既存コードとの互換性用などには,

GLM_FORCE_QUAT_DATA_WXYZ が導入されています.

Quaternion order DOES matter, can we please have a macro for the order? #983
https://github.com/g-truc/glm/issues/983

Quaternion storage order inconsistent #916
https://github.com/g-truc/glm/issues/916

Quaternion element order #942
https://github.com/g-truc/glm/issues/942

glTF

glTF では [x, y, z, w] の配列で定義されています.

したがって glm 0.9.9.7 を使う場合は特にデータ変換は不要です.

おまけ

glm, feature rich で便利な気はしますが(e.g. fmtlib と組み合わせて glm::to_string(x) で行列やらの表示とか), ドキュメントわかりずらい, API わかりずらい, 以外とバグ多めでなかなか困った子です.

代替案として, linalg

や HandmadeMath

が挙げられます. ちょっとしたベクトル, quaternion と 4x4 行列まででよければこれらの利用も検討してみましょう.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?