旋转矩阵的方向向量

Ufn*_*d3r 11 c c++ opengl matrix

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

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

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

但我不能这样做.

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

    void makeRotationDir(const Vec3& direction)
    {
        //:((
    }
}
Run Code Online (Sandbox Code Playgroud)

Ufn*_*d3r 14

谢谢大家.解决了.

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

  • “感谢所有人,解决了”不是一种解释或解决方案。 (3认同)