For doing such I decided to start by overloading twice the * operator:
1 2 3 4 5 6 7
inline Color operator * (Color& c, float a) {
Color color;
color.red = c.red * a;
color.green = c.green * a;
color.blue = c.blue * a;
return color;
}
1 2 3 4 5 6
inline Color operator * (Color& c, Color d) {
Color color;
color.red = c.red * d.red;
color.green = c.blue * d.blue;
color.blue = c.green * d.green;
}
I expected it to solve the matter, but the compiler tells me
/media/34GB/demos/asmfrt-master/RayTracer.cpp|299|error: no match for ‘operator*’ in ‘operator*(((Color&)(& light_intensity)), lambert) * mat.Mtl::kd’|
I guess I can solve this issue using a temporary Color structure, that will store the result of a float by color multiplication (or a color by color) and then to do the other multiplication. And of course, there is the += operator to be overloaded
But I would like to do everything in a single line of code. Is it possible? Thanks for help.
many compilers support some form of force_inline if you want to override the compiler's decision and time it to see if you can make it better. Straight inline keyword is often ignored entirely, though. You can also #include to inline if you must on a compiler that lacks a force, but its ugly. Most of the time, all you are going to do is discover that the compiler made the right choice. Once in a great while, you will outsmart it.
Ok, I am able to compile it and run it (after adding a "return color" and swapping the blue and green colors that were added in the second overloading). Anyway, as I mentioned in the first message, my final goal was to replace