Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
// code to multiply matrices (concatenation)
void multiply_matrices(float a[4][4], float b[4][4])
{
float tmp[4][4];
int i, j;
for (j = 0; j < 4; j++)
for (i = 0; i < 4; i++)
tmp[i][j] = a[i][0] * b[0][j]
+a[i][1] * b[1][j]
+a[i][2] * b[2][j]
+a[i][3] * b[3][j];
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
a[i][j] = tmp[i][j];
}
// multiply with:
// x-rotation
// 1 0 0 0
// 0 cos(x) sin(x) 0
// 0 -sin(x) cos(x) 0
// 0 0 0 1
// y-rotation
// cos(y) 0 -sin(y) 0
// 0 1 0 0
// sin(y) 0 cos(y) 0
// 0 0 0 1
// z-rotation
// cos(z) sin(z) 0 0
// -sin(z) cos(z) 0 0
// 0 0 1 0
// 0 0 0 1
// Maths required to transform a vector using a matrix
// x0 etc are the original object space coords for the vector
x = x0 * a[0][0] + y0 * a[1][0] + z0 * a[2][0] + a[3][0];
y = x0 * a[0][1] + y0 * a[1][1] + z0 * a[2][1] + a[3][1];
z = x0 * a[0][2] + y0 * a[1][2] + z0 * a[2][2] + a[3][2];
// You may need to look into homogenous coordinate systems...
void multiply_matrices(float a[4][4], float b[4][4])
{
float tmp[4][4];
int i, j;
for (j = 0; j < 4; j++)
for (i = 0; i < 4; i++)
tmp[i][j] = a[i][0] * b[0][j]
+ a[i][1] * b[1][j]
+ a[i][2] * b[2][j]
+ a[i][3] * b[3][j];
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
a[i][j] = tmp[i][j];
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.