- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 236字
- 2021-06-30 14:45:57
Comparing matrices
Comparing matrices is a component-wise operation. Two matrices are the same only if all their components are the same. To compare two matrices, loop through and compare all of their components. Since you are comparing floating point numbers, an epsilon should be used.
Create a new file, mat4.cpp. Implement the matrix equality and inequality operators in this file. The equality operator should check whether two matrices are the same; the inequality operator returns the opposite of the equality operator. Don't forget to add the function declarations to mat4.h:
bool operator==(const mat4& a, const mat4& b) {
for (int i = 0; i < 16; ++i) {
if (fabsf(a.v[i] - b.v[i]) > MAT4_EPSILON) {
return false;
}
}
return true;
}
bool operator!=(const mat4& a, const mat4& b) {
return !(a == b);
}
Important note
The MAT4_EPSILON constant should be defined in mat4.h. 0.000001f is a good default value to use.
When comparing matrices by component, you are checking for literal equality. There are other ways to define matrix equality; for example, regardless of shape, the volume of two matrices can be compared using their determinants. Matrix determinants will be covered later in this chapter.
In the next section, you will learn how to add matrices together.
- UI圖標創意設計
- Moodle Administration Essentials
- Vue.js 2 and Bootstrap 4 Web Development
- Web Application Development with R Using Shiny(Second Edition)
- Building Mapping Applications with QGIS
- 基于Swift語言的iOS App 商業實戰教程
- SQL基礎教程(視頻教學版)
- Python算法從菜鳥到達人
- Webpack實戰:入門、進階與調優
- Deep Learning with R Cookbook
- Arduino可穿戴設備開發
- 從零開始學Android開發
- 軟硬件綜合系統軟件需求建模及可靠性綜合試驗、分析、評價技術
- Koa與Node.js開發實戰
- Swift Essentials(Second Edition)