方向向量到旋转矩阵

UfnCod3r

如何从方向创建旋转矩阵(单位矢量)

我的矩阵是3x3,专栏专业和右手

我知道'column1'是正确的,'column2'是向上的,'column3'是向前的

但是我做不到。

//3x3, Right Hand
struct Mat3x3
{
    Vec3 column1;
    Vec3 column2;
    Vec3 column3;

    void makeRotationDir(const Vec3& direction)
    {
        //:((
    }
}
UfnCod3r
struct Mat3x3
{
    Vec3 column1;
    Vec3 column2;
    Vec3 column3;

    void makeRotationDir(const Vec3& direction, const Vec3& up = Vec3(0,1,0))
    {
        Vec3 xaxis = Vec3::Cross(up, direction);
        xaxis.normalizeFast();

        Vec3 yaxis = Vec3::Cross(direction, xaxis);
        yaxis.normalizeFast();

        column1.x = xaxis.x;
        column1.y = yaxis.x;
        column1.z = direction.x;

        column2.x = xaxis.y;
        column2.y = yaxis.y;
        column2.z = direction.y;

        column3.x = xaxis.z;
        column3.y = yaxis.z;
        column3.z = direction.z;
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章