Shading triangles with clang++-8
So I am following your course here, and I struggled a bit with the shading lecture. This might be a compiler issue, meaning, the compiler stops me from doing things that I do not want.
My geometry.h basically looks the same as here, and multiplying a vector with a scalar value looks like this:
template <typename T>
struct Vector2D {
...
inline Vector2D operator*(float scalar) const {
return Vector2D{x*scalar, y*scalar};
}
...
However I found that, since I am following the GSL (core guidelines for c++), and using initializer list constructors ( using the {}, instead of () ), the compiler will either complain, or result in faulty code. This might be due to clang in this case, but I suspect MSVC++ and g++ will result in the same compiler error:
error: type 'float' cannot be narrowed to 'int' in initializer list [-Wc++11-narrowing]
So, changing that to:
inline Vector2D operator*(float scalar) const {
return Vector2D{static_cast<T>(x*scalar), static_cast<T>(y*scalar)};
}
Fixes the issue. These are not issues related to the course in itself, but perhaps might be worth noting. If it's irrelevant, just close and remove this issue. Thanks again for awesome content.
Thank you for your point! In fact, the geometry.h MUST be rewritten completely with modern C++. It was made with c++98 and this is quite ridiculous these days. If you can offer a better implementation, do not hesitate to do a pull request.