如何从方向(单位 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/