您的位置:首页 > 其它

Matrix结构体(Leap::Matrix)

2015-09-25 09:48 281 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leap-motion