本文整理汇总了C++中matrix_t::Identity方法的典型用法代码示例。如果您正苦于以下问题:C++ matrix_t::Identity方法的具体用法?C++ matrix_t::Identity怎么用?C++ matrix_t::Identity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix_t
的用法示例。
在下文中一共展示了matrix_t::Identity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Inverse
// taken from SGI's sample GL implementation, should work
bool matrix_t::Inverse(matrix_t &inv)
{
int i, j, k, swap;
float t;
float temp[4][4];
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
temp[i][j] = m[(i * 4) + j];
inv.Identity();
for (i = 0; i < 4; i++)
{
/*
** Look for largest element in column
*/
swap = i;
for (j = i + 1; j < 4; j++)
if (fabs(temp[j][i]) > fabs(temp[i][i]))
swap = j;
if (swap != i)
{
/*
** Swap rows.
*/
for (k = 0; k < 4; k++)
{
t = temp[i][k];
temp[i][k] = temp[swap][k];
temp[swap][k] = t;
t = inv.m[(i * 4) + k];
inv.m[(i * 4) + k] = inv.m[(swap * 4) + k];
inv.m[(swap * 4) + k] = t;
}
}
/*
** No non-zero pivot. The matrix is singular, which shouldn't
** happen. This means the user gave us a bad matrix.
*/
if (temp[i][i] == 0)
return 0;
t = temp[i][i];
for (k = 0; k < 4; k++)
{
temp[i][k] /= t;
inv.m[(i * 4) + k] /= t;
}
for (j = 0; j < 4; j++)
{
if (j != i)
{
t = temp[j][i];
for (k = 0; k < 4; k++)
{
temp[j][k] -= temp[i][k] * t;
inv.m[(j * 4) + k] -= inv.m[(i * 4) + k] * t;
}
}
}
}
return 1;
}