I'm trying to re-implement the business card ray tracer in rust for fun and profit. As far as I can tell all of the logic is in place, but for the life of me I can't figure out how correctly convert from my floating point values to the RGB bytes that the ppm file format expects. In the original code (C++), it looks like this:
printf("%c%c%c",(int)p.x,(int)p.y,(int)p.z);
where p
is a 3-d vector of floats representing an RGB value. I didn't have much luck with print!
, so after much tweaking I wrote the equivalent expression as:
let mut out = io::stdout();
out.write(&[(p.x as u8),(p.x as u8),(p.x as u8)]);
However, the output is way off (I can post it if you really want, but suffice it to say that the correct output has plenty of non-printable characters, while my version is quite printable). I honestly don't understand the nuances of type conversion for either language. Anyone care to lend a hand?
Edit: full source (note that I use floats as vector attributes)