我在一个我无法完全理解的论坛上发现了这段C++代码。由于我没有执行矩阵/向量数学的库,我需要手动计算出来并复制这些功能。这段代码是如何工作的?
计算欧拉旋转角2之间的载体。我们用罗德里格斯公式
vector $V1 = << my first vector >>;
vector $V2 = << my second vector >>;
vector $axis;
float $angle;
$angle = acos($V1*$V2);
$axis = normalizeVector((cross($V1,$V2)));
matrix $axis_skewed[3][3] = <<
0, (-$axis.z), ($axis.y) ;
($axis.z), 0, (-$axis.x) ;
(-$axis.y), ($axis.x), 0 >>;
matrix $eye3[3][3] = <<
1, 0, 0;
0, 1, 0;
0, 0, 1 >>;
从这里开始事情就变得棘手:
// here's Rodrigues
$R = $eye3 + sin($angle)*$axis_skewed + (1-cos($angle))*$axis_skewed*$axis_skewed;
你添加eye3矩阵的所有属性?
你会乘以axis_skewed矩阵的所有属性吗?
什么是R?一个向量还是矩阵?或号码?
这很简单。
matrix $vectorMatr[3][1];
$vectorMatr[0][0] = ($V1.x);
$vectorMatr[1][0] = ($V1.y);
$vectorMatr[2][0] = ($V1.z);
再次,这是非常棘手:
// $result is the resulting vector
$result = ($R * $vectorMatr);
你乘以向量与矩阵使用标准矩阵相乘得到的合成矢量?
你是否乘以这两个矩阵,然后使用矩阵变换点?
您已将此C++标记为C++,并将其描述为C++代码,但它看起来完全不像C++。 – abelenky 2010-10-25 02:07:58
尝试猜测它然后 - http://www.gamedev.net/community/forums/topic.asp?topic_id=585682 – 2010-10-25 02:22:54
我猜测伪代码。 – 2010-10-25 02:32:02