Page 1 of 1

($square/2) == floor($square/2) ???

Posted: Tue Jan 04, 2011 6:41 pm
by gth759k
I'm converting a simple raytracer I made in php over to c++ and I can't figure out how to convert a certain part. The code below creates a "tile/checkered" pattern that can be put on a plane, I didn't make it up myself, I copied it from a javascript raytracer and just modified the function calls to make it work, so the javascript version of this code was very similar. Anyways, what is the == doing? In c++ it doesn't work at all and when I run it with just setColorRed((square/2)) it doesn't make the correct pattern of every other square being black or white. Any suggestions?

Code: Select all

$square = floor($intersection_position->getVectorX()) + floor($intersection_position->getVectorZ());

$winning_object_color->setColorRed(($square/2) == floor($square/2));
$winning_object_color->setColorGreen(($square/2) == floor($square/2));
$winning_object_color->setColorBlue(($square/2) == floor($square/2));

Re: ($square/2) == floor($square/2) ???

Posted: Tue Jan 04, 2011 7:30 pm
by Christopher
"($square/2) == floor($square/2)" is going to evaluate to true/false (or 1/0 perhaps in this case). It will be true if $square is even and false if it is odd. So to make the squares it is passing RGB 1,1,1 or 0,0,0.

Re: ($square/2) == floor($square/2) ???

Posted: Tue Jan 04, 2011 7:46 pm
by gth759k
Thanks so much! I got it working now!

Re: ($square/2) == floor($square/2) ???

Posted: Wed Jan 05, 2011 5:16 am
by VladSun
LOL, that's a bad code :)

Code: Select all

if (!($square % 2)) ...