- 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.
- FuelPHP Application Development Blueprints
- Getting Started with Gulp(Second Edition)
- Facebook Application Development with Graph API Cookbook
- Flutter開發(fā)實(shí)戰(zhàn)詳解
- Bulma必知必會(huì)
- Android NDK Beginner’s Guide
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第4版)
- WebRTC技術(shù)詳解:從0到1構(gòu)建多人視頻會(huì)議系統(tǒng)
- 從零開始學(xué)C#
- Robot Framework Test Automation
- 軟件測試技術(shù)
- 輕松學(xué)Scratch 3.0 少兒編程(全彩)
- Continuous Integration,Delivery,and Deployment
- 亮劍C#項(xiàng)目開發(fā)案例導(dǎo)航
- ArcGIS Blueprints