我想定位我的矩阵,使Up向量面向与另一个向量相同的方向。前向和右向量的方向无关紧要。
例如:
matrix4 m; // m.Up = 0, 1, 0
vector3 v = V3(1,0,0);
// Then I think I have to get the rotation from m.Up and v
// And then rotate the matrix accordingly
但我不知道这是怎么回事,而我可能错了。
答案 0 :(得分:3)
这是matricies对
特别有用的轮换问题之一首先,将矩阵分成三个分量向量(向上,向前和向右)。
将您的向量设置为您想要的向量。然后,调整你的向前和向右矢量,使它们成直角,一个简单的方法是通过使用交叉产品。
例如:
//Gets a perpendicular vector
V3 V3::Perp() {
V3 perp = v.Cross(NewV3(-1, 0, 0));
if(perp.Length() == 0) {
// If v is too close to -x try -y
perp = v.Cross(NewV3(0, -1, 0));
}
return perp.Unit();
}
//up = Whatever you need
forward = up.Perp()
right = cross(up, forward);
之后,将矢量插回矩阵中,然后瞧:D。
答案 1 :(得分:1)
如果我理解正确,只需将矩阵中的向上轴设置为您选择的向量即可。正如您所说,向前和向右矢量无关紧要,只要它们与您的新轴向正交,就将它们设置为任何值。