官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 射洪县| 永寿县| 定安县| 桐乡市| 通辽市| 大化| 泽州县| 宝坻区| 观塘区| 德保县| 获嘉县| 罗城| 竹溪县| 洛浦县| 乌拉特中旗| 勃利县| 马公市| 马鞍山市| 麻阳| 澳门| 武强县| 高淳县| 武威市| 曲松县| 枞阳县| 柳河县| 潼南县| 博客| 莒南县| 临沧市| 新巴尔虎左旗| 视频| 郎溪县| 垦利县| 黎城县| 潼关县| 措美县| 萨嘎县| 刚察县| 阜城县| 香格里拉县|