クォータニオンを定義します。 More...
#include <Quaternion.h>
Public Member Functions | |
Quaternion () | |
単位クォータニオンを設定してインスタンスを初期化します。 | |
Quaternion (float x, float y, float z, float w) | |
指定した値を使用してインスタンスを初期化します。 | |
Quaternion (const Vector3 &axis, float r) | |
回転軸と回転角度を指定してインスタンスを初期化します。 | |
void | Set (float x, float y, float z, float w) |
各要素に値を設定します。 | |
float | GetLength () const |
このクォータニオンの長さを返します。 | |
float | GetLengthSquared () const |
このクォータニオンの長さの 2 乗を返します。 | |
void | Normalize () |
このクォータニオンを正規化します。 | |
bool | IsIdentity () const |
このクォータニオンが単位クォータニオンであるかを判定します。 | |
void | Multiply (const Quaternion &qua) |
このクォータニオンに指定されたクォータニオンを乗算します。 | |
void | RotateX (float angle) |
このクォータニオンを X 軸で回転します。 | |
void | RotateY (float angle) |
このクォータニオンを Y 軸で回転します。 | |
void | RotateZ (float angle) |
このクォータニオンを Z 軸で回転します。 | |
void | RotateAxis (const Vector3 &axis, float r) |
このクォータニオンを回転軸と角度を指定して回転します。 | |
Vector3 | ToEulerAngles (RotationOrder order=RotationOrder_ZXY, bool *locked=NULL) const |
このクォータニオンを XYZ 各軸のオイラー角度に変換します。 | |
void | ToAxisAngle (Vector3 *axis, float *angle) const |
このクォータニオンの回転軸と回転角度を取得します。 | |
bool | IsNaNOrInf () const |
要素のいずれかが NaN または Inf かを判別します。 | |
void | Print (const char *format=NULL, FILE *stream=NULL) const |
デバッグ用に文字列を標準出力します。 | |
Quaternion & | operator+= (const Quaternion &v) |
Quaternion & | operator+= (float v) |
Quaternion & | operator-= (const Quaternion &v) |
Quaternion & | operator-= (float v) |
Quaternion & | operator*= (const Quaternion &v) |
this->Multiply(v); と同じです。 | |
Quaternion & | operator*= (float v) |
Quaternion & | operator/= (float v) |
bool | operator== (const Quaternion &v) const |
bool | operator!= (const Quaternion &v) const |
Static Public Member Functions | |
static Quaternion | Normalize (const Quaternion &qua) |
指定クォータニオンを正規化したクォータニオンを返します。 | |
static Quaternion | Conjugate (const Quaternion &qua) |
指定クォータニオンの共役を返します。 | |
static float | Dot (const Quaternion &qua1, const Quaternion &qua2) |
2つのクォータニオンの内積を計算します。 | |
static Quaternion | Inverse (const Quaternion &qua) |
クォータニオンを共役し、再正規化します。 | |
static Quaternion | Multiply (const Quaternion &qua1, const Quaternion &qua2) |
2つのクォータニオンの積を計算します。 | |
static Quaternion | RotationAxis (const Vector3 &axis, float r) |
回転軸と角度を指定してクォータニオンを作成します。 | |
static Quaternion | RotationMatrix (const Matrix &mat) |
回転行列からクォータニオンを作成します。 | |
static Quaternion | RotationYawPitchRoll (float yaw, float pitch, float roll) |
ヨー、ピッチ、ロールを指定してクォータニオンを作成します。 | |
static Quaternion | RotationEulerAngles (const Vector3 &angles, RotationOrder order=RotationOrder_ZXY) |
XYZ 各軸のオイラー角からクォータニオンを作成します。 | |
static Quaternion | Slerp (const Quaternion &qua1, const Quaternion &qua2, float t) |
球面線形補間を使用して、2 つのクオータニオン間を補間します。 | |
Public Attributes | |
float | X |
X 要素 | |
float | Y |
Y 要素 | |
float | Z |
Z 要素 | |
float | W |
W 要素 | |
Static Public Attributes | |
static const Quaternion | Identity |
単位クォータニオン (0, 0, 0, 1) | |
Friends | |
Quaternion | operator+ (const Quaternion &v1, const Quaternion &v2) |
Quaternion | operator+ (const Quaternion &v1, float v2) |
Quaternion | operator+ (float v1, const Quaternion &v2) |
Quaternion | operator- (const Quaternion &v1, const Quaternion &v2) |
Quaternion | operator- (const Quaternion &v1, float v2) |
Quaternion | operator- (float v1, const Quaternion &v2) |
Quaternion | operator* (const Quaternion &v1, const Quaternion &v2) |
Quaternion::Multiply(v1, v2); と同じです。 | |
Quaternion | operator* (const Quaternion &v1, float v2) |
Quaternion | operator* (float v1, const Quaternion &v2) |
Quaternion | operator/ (const Quaternion &v1, float v2) |
Quaternion | operator- (const Quaternion &v1) |
クォータニオンを定義します。
このクォータニオンクラスの乗算の順番は左から右です。 つまり、q1 * q2 は、先に q1、次に q2 の回転を適用する事と同じです。
この乗算順序は標準的な四元数の定義からは逆行していますが、 ゲームプログラムをメインとした3Dグラフィックス向けの線形代数ライブラリとしては この動作がほぼ一般的なので、これに合わせています。
(DirectX(D3DX)、XNA、Unity、cocos2dx 等はこの動作)
Lumino::Quaternion::Quaternion | ( | const Vector3 & | axis, |
float | r | ||
) |
回転軸と回転角度を指定してインスタンスを初期化します。
[in] | axis | : 回転軸 |
[in] | r | : 回転角度 (ラジアン単位) |
axis が単位ベクトルでなければ正規化してから計算を行います。
static Quaternion Lumino::Quaternion::Conjugate | ( | const Quaternion & | qua | ) | [static] |
指定クォータニオンの共役を返します。
[in] | qua | : 処理の基になるクォータニオン |
static float Lumino::Quaternion::Dot | ( | const Quaternion & | qua1, |
const Quaternion & | qua2 | ||
) | [static] |
2つのクォータニオンの内積を計算します。
[in] | qua1 | : 処理の基になるクォータニオン |
[in] | qua2 | : 処理の基になるクォータニオン |
static Quaternion Lumino::Quaternion::Inverse | ( | const Quaternion & | qua | ) | [static] |
クォータニオンを共役し、再正規化します。
[in] | qua | : 処理の基になるクォータニオン |
bool Lumino::Quaternion::IsIdentity | ( | ) | const [inline] |
このクォータニオンが単位クォータニオンであるかを判定します。
void Lumino::Quaternion::Multiply | ( | const Quaternion & | qua | ) |
このクォータニオンに指定されたクォータニオンを乗算します。
[in] | qua | : 乗算するクォータニオン |
static Quaternion Lumino::Quaternion::Multiply | ( | const Quaternion & | qua1, |
const Quaternion & | qua2 | ||
) | [static] |
2つのクォータニオンの積を計算します。
[in] | qua1 | : 処理の基になるクォータニオン |
[in] | qua2 | : 処理の基になるクォータニオン |
Multiply(qua1, qua2) は、先に qua1、次に qua2 の回転を行うクォータニオンを作成します。
static Quaternion Lumino::Quaternion::Normalize | ( | const Quaternion & | qua | ) | [static] |
指定クォータニオンを正規化したクォータニオンを返します。
[in] | qua | : 処理の基になるクォータニオン |
void Lumino::Quaternion::Print | ( | const char * | format = NULL , |
FILE * | stream = NULL |
||
) | const |
デバッグ用に文字列を標準出力します。
[in] | format | : 書式指定文字列 |
[in] | stream | : 出力先ストリーム |
format が NULL の場合、書式は "(%f, %f, %f, %f)\n" を使用します。
void Lumino::Quaternion::RotateAxis | ( | const Vector3 & | axis, |
float | r | ||
) |
このクォータニオンを回転軸と角度を指定して回転します。
[in] | axis | : 回転軸 |
[in] | r | : 回転角度 (ラジアン単位) |
axis が単位ベクトルでなければ正規化してから計算を行います。
void Lumino::Quaternion::RotateX | ( | float | angle | ) |
このクォータニオンを X 軸で回転します。
[in] | angle | : 回転角度 (ラジアン単位) |
void Lumino::Quaternion::RotateY | ( | float | angle | ) |
このクォータニオンを Y 軸で回転します。
[in] | angle | : 回転角度 (ラジアン単位) |
void Lumino::Quaternion::RotateZ | ( | float | angle | ) |
このクォータニオンを Z 軸で回転します。
[in] | angle | : 回転角度 (ラジアン単位) |
static Quaternion Lumino::Quaternion::RotationAxis | ( | const Vector3 & | axis, |
float | r | ||
) | [static] |
回転軸と角度を指定してクォータニオンを作成します。
[in] | axis | : 回転軸 |
[in] | r | : 回転角度 (ラジアン単位) |
axis が単位ベクトルでなければ正規化してから計算を行います。
static Quaternion Lumino::Quaternion::RotationEulerAngles | ( | const Vector3 & | angles, |
RotationOrder | order = RotationOrder_ZXY |
||
) | [static] |
XYZ 各軸のオイラー角からクォータニオンを作成します。
[in] | angles | : XYZ 各軸の回転角度 (ラジアン単位) |
[in] | order | : 回転順序 |
static Quaternion Lumino::Quaternion::RotationMatrix | ( | const Matrix & | mat | ) | [static] |
回転行列からクォータニオンを作成します。
[in] | mat | : 処理の基になる行列 |
static Quaternion Lumino::Quaternion::RotationYawPitchRoll | ( | float | yaw, |
float | pitch, | ||
float | roll | ||
) | [static] |
ヨー、ピッチ、ロールを指定してクォータニオンを作成します。
[in] | yaw | : y 軸を中心とするヨー (ラジアン単位) |
[in] | pitch | : x 軸を中心とするピッチ (ラジアン単位) |
[in] | roll | : z 軸を中心とするロール (ラジアン単位) |
回転順序は Z → X → Y です。引数の並びとは逆順であることに注意してください。 これは D3DXQuaternionRotationYawPitchRoll の回転順序と同じで、 RotationEulerAngles に RotationOrder_ZXY を指定して計算した結果とも同じです。
static Quaternion Lumino::Quaternion::Slerp | ( | const Quaternion & | qua1, |
const Quaternion & | qua2, | ||
float | t | ||
) | [static] |
球面線形補間を使用して、2 つのクオータニオン間を補間します。
[in] | qua1 | : 処理の基になるクオータニオン (t = 0.0 のときの値) |
[in] | qua2 | : 処理の基になるクオータニオン (t = 1.0 のときの値) |
[in] | t | : 加重係数 |
t は通常、0.0~1.0 を指定します。
void Lumino::Quaternion::ToAxisAngle | ( | Vector3 * | axis, |
float * | angle | ||
) | const |
このクォータニオンの回転軸と回転角度を取得します。
[in] | axis | : 回転軸を格納するベクトルのポインタ |
[in] | angle | : 回転角度を格納する変数のポインタ |
axis には単位ベクトルを格納します。
Vector3 Lumino::Quaternion::ToEulerAngles | ( | RotationOrder | order = RotationOrder_ZXY , |
bool * | locked = NULL |
||
) | const |
このクォータニオンを XYZ 各軸のオイラー角度に変換します。
[in] | order | : 回転順序 |
[in] | locked | : ジンバルロックの発生有無を格納する変数へのポインタ (ジンバルロックが発生した場合 true) |
クォータニオンは order に指定された順序で乗算されたものでなければ本来の回転角度が取得できないことに注意してください。
例えば RotationYawPitchRoll() は、回転軸 Z → Y → X の順に回転を行いますが、 これから元の角度を取り出すには RotationOrder_ZXY を指定します。