c++ - 旋转矩阵的方向 vector

标签 c++ c opengl matrix

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

我的矩阵是 3x3,主列,右手

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

但我不能这样做。

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

    void makeRotationDir(const Vec3& direction)
    {
        //:((
    }
}

最佳答案

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;
    }
}

关于c++ - 旋转矩阵的方向 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18558910/

相关文章:

c++ - Clang LLVM 禁用 va_arg 扩展

c - fix_screeninfo的line_length变量是怎么统计的?

opengl - 使用着色器在 2D 环境中实现视野

c++ - 显示3D点

performance - Opengl glScalef 重置性能

c++ - 在 C++ 中从二叉搜索树(递归)复制叶子

c++ - 使用 C++ 的巴贝奇数未显示正确的结果

c++ - 隐式转换以匹配运算符参数

c++ - 使用 IShellDispatch 界面更改文件的详细信息选项卡(右键单击时)?

c - 保存日期格式为 yyyy_mm_dd hh_mm_ss 的文件名