- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 245字
- 2021-06-30 14:45:58
Transpose
To transpose a matrix, flip every element of the matrix across its main diagonal. For example, the 2, 1 element would become the 1, 2 element. Elements where both subscripts are the same, such as 1, 1, will remain the same:
- Implement the transpose function in mat4.cpp. Don't forget to add the function declaration to mat4.h:
#define M4SWAP(x, y) \
{float t = x; x = y; y = t; }
void transpose(mat4 &m) {
M4SWAP(m.yx, m.xy);
M4SWAP(m.zx, m.xz);
M4SWAP(m.tx, m.xw);
M4SWAP(m.zy, m.yz);
M4SWAP(m.ty, m.yw);
M4SWAP(m.tz, m.zw);
}
- Create a transposed function in mat4.cpp. The transposed function modifies a matrix that is passed into it. Don't forget to add the function declaration to mat4.h:
mat4 transposed(const mat4 &m) {
return mat4(
m.xx, m.yx, m.zx, m.tx,
m.xy, m.yy, m.zy, m.ty,
m.xz, m.yz, m.zz, m.tz,
m.xw, m.yw, m.zw, m.tw
);
}
Transposing a matrix is useful if you need to convert a matrix from row-major to column-major or the other way around. In the next section, you will learn how to calculate the determinant of a square matrix.
- 微服務(wù)設(shè)計(jì)(第2版)
- Servlet/JSP深入詳解
- OpenNI Cookbook
- Object-Oriented JavaScript(Second Edition)
- Building RESTful Python Web Services
- C語(yǔ)言程序設(shè)計(jì)上機(jī)指導(dǎo)與習(xí)題解答(第2版)
- 0 bug:C/C++商用工程之道
- QPanda量子計(jì)算編程
- 石墨烯改性塑料
- C#程序設(shè)計(jì)基礎(chǔ)入門(mén)教程
- 零基礎(chǔ)學(xué)SQL(升級(jí)版)
- 例說(shuō)FPGA:可直接用于工程項(xiàng)目的第一手經(jīng)驗(yàn)
- Building Clouds with Windows Azure Pack
- Android從入門(mén)到精通
- Build Your Own PaaS with Docker