// A = B
void copymatrix(float a[4][4], float b[4][4])
{
int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
a[i][j] = b[i][j];
}
// A = A * B
// (ale nejsem si 100% jisty, mozna to je A = B * A)
// (kdyby tedy rotace fungovali spatne, prohodte pri nasobeni A a B :-)
void matmult(float a[4][4], float b[4][4])
{
float temp[4][4];
int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
temp[i][j] = a[0][j] * b[i][0] + a[1][j] * b[i][1] +
a[2][j] * b[i][2] + a[3][j] * b[i][3];
copymatrix (a, temp);
}
// nastavi matici na jednotkovou matici
void initmatrix(float a[4][4])
{
int i, j;
for (j = 0; j < 4; j++)
{
for (i = 0; i < 4; i++) a[i][j] = 0;
a[j][j] = 1;
}
}
// vrati matici pro posun objektu
void translatematrix(float matrix[4][4], float dx, float dy, float dz)
{
initmatrix (matrix);
matrix[0][3]=dx;
matrix[1][3]=dy;
matrix[2][3]=dz;
}
//vrati matici pro rotaci objektu kolem osy x
void rotatematrixx(float matrix[4][4], float xangle)
{
initmatrix(matrix);
matrix[2][1] = sin(xangle);
matrix[2][2] = cos(xangle);
matrix[1][1] = cos(xangle);
matrix[1][2] =-sin(xangle);
}
//vrati matici pro rotaci objektu kolem osy y
void rotatematrixy(float matrix[4][4], float yangle)
{
initmatrix(matrix);
matrix[2][0] =-sin(yangle);
matrix[2][2] = cos(yangle);
matrix[0][0] = cos(yangle);
matrix[0][2] = sin(yangle);
}
//vrati matici pro rotaci objektu kolem osy z
void rotatematrixz(float matrix[4][4], float zangle)
{
initmatrix(matrix);
matrix[1][0] = sin(zangle);
matrix[1][1] = cos(zangle);
matrix[0][0] = cos(zangle);
matrix[0][1] =-sin(zangle);
}
výheň