3 ms·
It's a must-have for 3D programming, for working with vectors and matrices. OpenGL's shader language is basically C with (hard coded) operator overloading for t
by iainmerrick 10y ago
It's a must-have for 3D programming, for working with vectors and matrices. OpenGL's shader language is basically C with (hard coded) operator overloading for this reason.
- schoen 10y agoCould you explain a little more about how the operator overloading is used in this context? Is it just that arithmetic operators are made to work in their linear algebra sense on objects representing matrices, so M*N will return a new object representing the matrix product M×N?
- hacoo 10y agoThat's exactly how it would be used. Game programming involves a pretty enormous amount of geometry and vector arithmetic, so it's a domain where being able to write s*(u+v) is an advantage over scaleVec(s, addVec(u, v)). Same logic applies to matrices, as you described. Personally, I think there are more important advantages of C++ over C, and operator overloading can get ugly FAST if you're not careful.
- schoen 10y agoThat makes sense. Thanks for the explanation!