方向向量旋转矩阵 [英] Direction Vector To Rotation Matrix

查看:1159
本文介绍了方向向量旋转矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我的矩阵是3×3,列为主,而右手

我知道'列1'是正确的,列2是和栏3是向前迈进

但我不能老是这样做。

  // 3×3,右手
结构Mat3x3
{
    VEC3列1;
    VEC3列2;
    VEC3栏3;    无效makeRotationDir(常量VEC3&放方向)
    {
        //:((
    }
}


解决方案

感谢所有。
解决了。​​

 结构Mat3x3
{
    VEC3列1;
    VEC3列2;
    VEC3栏3;    无效makeRotationDir(常量VEC3&放大器;方向,常量VEC3&安培;最多= VEC3(0,1,0))
    {
        VEC3 x轴= VEC3 ::十字(上,方向);
        xaxis.normalizeFast();        VEC3 Y轴= VEC3 ::十字(方向,X轴);
        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;
    }
}

How To Create Rotation matrix From Direction (unit vector)

My Matrix Is 3x3, Column Major, And Right Hand

I Know 'column1' is right, 'column2' is up and 'column3' is forward

But I Can`t Do This.

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

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

解决方案

Thanks To All. Solved.

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

这篇关于方向向量旋转矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆