Matrix結構體(Leap::Matrix)

Matrix結構體(Leap::Matrix)

這個結構體表示轉換矩陣。爲了用這個結構體轉換一個Vector結構體,要創建一個包含所需要轉換的矩陣,然後用Matrix::transformPoint()或者Matrix::transformDirection()函數來應用轉換。用 * 操作把兩個或多個轉換矩陣相乘可以把幾個轉換過程結合起來。在LeapMath.h中提供了矩陣運算函數的函數體
Vector origin: 表示所有三根軸的平移因子。
用法:Vector thisTranslation=thisMatrix.origin;
Vector xBasis: 表示x軸的基向量。
用法:Vector xTransform=thisMatrix.xBasis;
Vector yBasis: 表示y軸的基向量。
用法:Vector yTransform=thisMatrix.yBasis;
Vector zBasis: 表示z軸的基向量。
用法:Vector zTransform=thisMatrix.zBasis;
Matrix(): 表示創建一個相同的轉換矩陣。
用法:Matrix identity= Matrix();
Matrix(const Matrix & other): 表示創建一個指定的Matrix的複製。
用法:Matrix thisMatrix= Matrix(thatMatrix);
Matrix(const Vector & _xBasis, const Vector & _yBasis, const Vector & _zBasis): 表示根據指定的基向量來創建一個轉換矩陣。參數_xBasis是指定x軸上旋轉和縮放因子的Vector;參數_yBasis是指定y軸上旋轉和縮放因子的Vector;參數_zBasis是指定z軸上旋轉和縮放因子的Vector.
用法:Vector xBasis = Vector(23, 0, 0);
Vector yBasis = Vector(0, 12, 0);
Vector zBasis = Vector(0, 0, 45);
Matrix transformMatrix = Matrix(xBasis, yBasis, zBasis);
Matrix(const Vector & _xBasis, const Vector & _yBasis, const Vector & _zBasis, const Vector & _origin): 表示根據指定的基向量和平移向量來創建一個轉換矩陣。參數_xBasis是指定x軸上旋轉和縮放因子的Vector;參數_yBasis是指定y軸上旋轉和縮放因子的Vector;參數_zBasis是指定z軸上旋轉和縮放因子的Vector;參數_origin是指定三根軸上平移因子的Vector;
用法:Hand leapHand = frame.hand(handID);
Vector handXBasis = leapHand.basis().xBasis;
Vector handYBasis = leapHand.basis().yBasis;
Vector handZBasis = leapHand.basis().zBasis;
Vector handOrigin = leapHand.palmPosition();
Matrix handTransform = Matrix(handXBasis, handYBasis, handZBasis, handOrigin);
Matrix(const Vector & axis, float angleRadians): 指定一個環繞指定向量的旋轉,據此構建一個轉換矩陣。參數axis表示指定旋轉軸的Vector;angleRadians表示旋轉的弧度。
用法:Vector axisOfRotation = leapHand.diretion();
float angleOfRotation = 1.27;
Matrix rotator = Matrix(axisOfRotation, angle, angleOfRotation);
Matrix(const Vector & axis, float angleRadians, const Vector & translation): 指定一個平移向量和環繞這個指定向量的旋轉,據此構建一個轉換矩陣。參數axis表示指定旋轉軸的Vector;angleRadians表示旋轉的弧度;translation表示一個代表轉換的平移部分的Vector。
用法:Vector rotationAxis = Vector::yAxis();
float angle = .733;
Vector translation = Vector(10, 220, 103);
Matrix transform = Matrix(rotationAxis, angle, translation);
bool operator!=(const Matrix & other): 比較Matrix結構體中的元素是否不相等。
Matrix operator*(const Matrix & other): 表示轉換矩陣的相乘。把兩個變換結合爲一個等效變換。參數other表示乘在右手端的Matrix。
用法:thisMatrix* thatMatrix;
Matrix & operator*=(const Matrix & other): 表示轉換矩陣的相乘,把結果賦給乘積。
用法:thisMatrix* =thatMatrix;
bool operator==(const Matrix & other): 比較Matrix結構體中的元素是否相等。
Matrix rigidInverse(): 如果完全是剛性變換,這個函數表示矩陣的逆。如果不是剛性的,這個操作不表示逆。所有由API直接返回的矩陣都是剛性的。
用法:thisMatrix=tharMatrix. rigidInverse();
void setRotation(const Vector & axis, float angleRadians): 設置這個變換矩陣來代表繞指定向量的旋轉。這個函數會消除之前所有應用到這個矩陣中的旋轉和尺度變換,但是不影響平移。參數axis表示指定旋轉軸的Vector;angleRadians表示旋轉的弧度。
用法:thisMatrix.setRotation(Vector::zAxis(), 1.46);
template T * toArray3×3(T * output): 表示把3×3的Matrix對象寫成9元素的浮點或雙精度數組(行優先)。平移因子被捨棄。返回一個指向同一個數據的指針。
FloatArray toArray3×3(): 表示把3×3的Matrix對象寫成9元素的浮點型數組(行優先)。平移因子被捨棄。返回一個FloatArray結構體,防止動態內存分配。
用法:FloatArray rotations=thisMatrix.toArray3×3();
template
T * toArray4×4(T * output): 表示把4×4的Matrix對象寫成16元素的浮點或雙精度數組(行優先)。平移因子被捨棄。返回一個指向同一個數據的指針。
FloatArray toArray4×4(): 表示把4×4的Matrix對象寫成16元素的浮點型數組(行優先)。平移因子被捨棄。返回一個FloatArray結構體,防止動態內存分配。
用法:FloatArray transforms=thisMatrix.toArray4×4();
template
const Matrix3×3Type toMatrix3×3(): 表示把一個Leap::Matrix對象轉換成另一個3×3的Matrix類型。新的類型必須定義一個構造函數,把每個矩陣元素當作行優先的參數。平移因子被捨棄。
template
const Matrix4×4Type toMatrix4×4(): 表示把一個Leap::Matrix對象轉換成另一個4×4的Matrix類型。新的類型必須定義一個構造函數,把每個矩陣元素當作行優先的參數。
std::string toString(): 把矩陣寫成字符串的格式。
Vector transformDirection(const Vector & in): 只通過轉換這個矩陣的旋轉和縮放來轉換向量。參數in表示要轉換的Vector。
用法:Vector newDirection = thisMatrix.transformDirection(oldDirection);
Vector transformPoint(const Vector & in): 通過轉換這個矩陣的旋轉、縮放和平移來轉換向量,平移用在旋轉和縮放之後。參數in表示要轉換的Vector。
用法:Vector newPosition= thisMatrix.transformPoint(oldPosition);
const Matrix & identity(): 返回沒有平移、旋轉和縮放的相等的矩陣。
用法:Matrix identity=Matrix::identity();

譯自:https://developer.leapmotion.com/documentation/cpp/api/Leap.Matrix.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章