我在一個我無法完全理解的論壇上發現了這段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