Raytracing



The name of the ray tracer is Blob, which is somewhat funny, it's just a coincident really.
I wrote the original version second year in school with some help of a friend Hans Olofsson,
I have no idea what happened to him really. I would guess he's doing mathematics somewhere.

We called the ray tracer Blob since it mostly created blob-like things.
The quality of the code was horrible, it was probably the first real C program I ever wrote.
I have no idea where the code went, so I wrote a new version over some weekends.
The general idea is to ray trace objects that are implicitly defined
(rather than explicitly defined using polygon meshes) by a function f(x, y, z) -> { true, false }.

Such function would take a coordinate in 3D and answer weather we are inside or outside the object.
For example, a ball.

bool inside_ball(
  Vector& aPosition)
{
  if(Distance(aPosition, centerOfBall) < radiousOfBall)
    return true
  else
    return false;
}

A somewhat more elaborate example


bool
Ball::IsInside(
  LP_Vector3& aPosition)
{
  LP_Vector3 center(0.0f, 0.0f, 0.0f);

  float t = LP_Vector3::Dist(aPosition, center);
  float dist = 1.0f / (t*t);

  for(int i = 0; i < knobs.Count(); i++)
  {
    t = LP_Vector3::Dist(knobs[i], aPosition);
    dist += 1.0f / (t*t*120.0f);
  }

  if(dist > 5.5f)
    return true;

  return false;
}

Or you could create animations.


You get the general idea.

Here's the source code. It's for Visual Studio 2008, but I ported it from Linux source so you should be able to port it back if you want to.
There are not many dependencies on system calls anyway.