Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
// 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
Title | # Comments | Views | Activity |
---|---|---|---|
error when checking java version | 4 | 4,391 | |
Two list de-cypher | 6 | 95 | |
The line on IDE | 4 | 84 | |
How do I return the Android Studio to its default project window settings? | 6 | 69 |
Join the community of 500,000 technology professionals and ask your questions.