- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 191字
- 2021-06-30 14:45:55
Comparing vectors
The last operation that needs to be implemented is vector comparison. Comparison is a component-wise operation; each element must be compared using an epsilon. Another way to measure whether two vectors are the same is to subtract them. If they were equal, subtracting them would yield a vector with no length.
Overload the == and != operators in vec3.cpp. Don't forget to add the function declarations to vec3.h:
bool operator==(const vec3 &l, const vec3 &r) {
vec3 diff(l - r);
return lenSq(diff) < VEC3_EPSILON;
}
bool operator!=(const vec3 &l, const vec3 &r) {
return !(l == r);
}
Important note:
Finding the right epsilon value to use for comparison operations is difficult. In this chapter, you declared 0.000001f as the epsilon. This value is the result of some trial and error. To learn more about comparing floating point values, check out https://bitbashing.io/comparing-floats.html.
In the next section, you will implement vectors with two and four components. These vectors will only be used as a convenient way to store data; they won't actually need any math operations implemented on them.
- INSTANT Mock Testing with PowerMock
- 計算思維與算法入門
- Java Web開發(fā)之道
- C語言程序設(shè)計同步訓(xùn)練與上機指導(dǎo)(第三版)
- JavaScript入門經(jīng)典
- Django 3.0入門與實踐
- Python機器學(xué)習(xí)之金融風(fēng)險管理
- 運維前線:一線運維專家的運維方法、技巧與實踐
- Learning C++ by Creating Games with UE4
- Implementing Microsoft Dynamics NAV(Third Edition)
- 實驗編程:PsychoPy從入門到精通
- Developing Java Applications with Spring and Spring Boot
- Zend Framework 2 Cookbook
- 深度學(xué)習(xí)的數(shù)學(xué):使用Python語言
- 匯編語言程序設(shè)計