I think I'll be updating my old journal posts to highlight the algorithm that added the said feature. I'll start now...
First, I had to refactor some code so that I could call my raytracing function recursivly (that's the way for reflections, pretty obvious when you think about it). And the actual reflection pseudo code is:
// this is part of the function Raytrace()
if( depth >= MAX_DEPTH ) // prevent endless reflection
reflectionDir = ray.direction() - 2.0*Dot( ray.direction(), surfaceNormal ) * surfaceNormal;
reflectionColor = Color::NONE;
// the RAY_OFFSET is to prevent the ray from interecting with the object it came from.
reflectedRay = Ray(intersectionPoint + reflectionDir*RAY_OFFSET, reflectionDir);
call Raytrace( reflectedRay, depth+1, reflectionColor );
pixelColor += material.reflection() * reflColor * material.color(intersection);
There's something odd with my pic... there's a weird color difference. But reference pic nr 3 renders just fine (check my last journal entry).
Note, the black spheres are black because I don't have refraction yet.
EDIT: FIXED! The camera problem was that the up vector I got wasn't correct, have to recalculate it. So here's the "recalculate the up vector" function and the "calculate the view rectangle on the near plane"
cRectangle cCamera::getNear() const
// the up vector is normalized,
// thus upScale is the same as the opposite side
upScale = tan(Deg2Rad(_yFOV/2.0)) * _near,
rightScale = _whRatio * upScale;
const cVector3<> rightDir = Cross(_up, direction())*rightScale,
upDir = _up*upScale, centerNear = position() + _near*direction();
const cVector3<> front = direction();
const cVector3<> right = Cross(_up, front).normalize();
_up = Cross(front, right);
Kudos to uavfun for helping me figure out the problem!