Day 2 of working on my ray tracer. I've been here since 4:00pm, it is now past 10pm.
I started it on Thursday, generating rays, and doing intersection for spheres, and tried to link stuff together.
Today included debugging the stuff I wrote on Thursday, and do shading and generate shadow rays.
Debugging has taken me until now. Now I remember how much I hate C++. For reasons I can't figure out, I have everything mapped out and theoretically should work, but it doesn't. For example, I wanted to print out the value of a variable to see if it's set properly. However, if I set it to another variable first, I get 0 as a result for some reason.
ie
a = root[0];
b = root[0];
std::cerr << root[0] << std::endl;
gives me 0, but if I remove those first 2 lines, it prints out the values they're supposed to be. You have no idea how frustrating it was!! I'm trying to pass references between functions, and testing to see if those values are actually set and returned took me so long, because of things like that. If I print out the value in the function, it works, but when I print the value after the function call, for some reason it's not set when it should be! I wrote foo() functions that pass variables and set them the same way, and those worked...
Anyway, somehow after testing my patience for hours and hours, I got it working, somewhat. I'll write as I go along.
[22:15]
Okay, it's tracing a sphere, but for some reason, it's tracing only the last one in the object tree. After printing out the names of the spheres, I discover that the t values used in the intersection point is calculated correctly, and it is passed correctly. I have a condition that if the (number of roots > 0), draw the sphere. Apparently that condition only returns true for the latest sphere (I don't know why, it should be true whenever the ray intersects an object). So fine, I changed the condition to (obj hit != NULL), and that seemed to fix it.
[22:27]
I get this, which is what I'm supposed to get, only if I print out debugging info. If I comment out the debugging stuff, I get
this. WHY?!?!?! It's just printing stuff to std::cerr!! if I don't do it, it doesn't trace the rest of the image?!?
[22:37]
And it gets weirder! If I print out random junk, it doesn't work! it only works if I print out obj->get_name()!!! fffffffff screw it, I'm gonna go work on shadows and stuff, maybe this will fix itself >__>
[23:46]
After some time away procrastinating, hey look, it fixed itself! >__<
[00:17]
I hate const! I think I'm going home now, will come back tomorrow when I'm less frustrated. arrgggh