- 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.
- jQuery Mobile Web Development Essentials(Third Edition)
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 測試驅動開發:入門、實戰與進階
- 算法零基礎一本通(Python版)
- HTML5 移動Web開發從入門到精通(微課精編版)
- Python自動化運維快速入門
- The Computer Vision Workshop
- 基于差分進化的優化方法及應用
- Scratch 3游戲與人工智能編程完全自學教程
- Node Cookbook(Second Edition)
- Learning Ionic
- C++程序設計
- Drupal 8 Development Cookbook(Second Edition)
- XML程序設計(第二版)
- Elasticsearch搜索引擎構建入門與實戰