November 1, 2009

Sprint 3: The basic 3D Math

Pffff...this sprint has taken way too long...Holidays, professional career (yes, I have to work for a living...) and a crashed development environment has slowed me down big time...So I had to rebuild my development environment from scratch...luckily, I could retreive a backup of my sources so far...but still, it delayed me big time...

Anyway, I have completed the utility data types & functions around vectors, points, normals and matrices. I based all the functions on the tables described in Kevin Suffern's book "Ray Tracing from the Ground Up",but I decided to make a Vector3D, Point3D and Normal3D as three different private types. Kevin Suffern uses a single object that can represent all three, but he indicates that that is actually badprogramming practice. I tend to agree with him on this, so I decided to follow good programming practice, and we'll see when we hit problems...sometimes bad programming is more efficient or easier...

Since Ada 2005 does not support overriding assignment, I will probably have to develop some additional utility functions to do something like:

Vec1 := Point1

This would be perfectly legal in Kevin Suffern's approach, but not in mine, since they are of a different type. So I would hav to write a function like:

function Point3D_to_Vector3D (pnt: in Point3D) return Vector3D is
Result: Vector3D;
begin
   Result.x := pnt.x;
   Result.y := pnt.y
   Result.z := pnt.z;
end Point3D_to_Vector3D;

Similar functions would have to be added for Point to Normal, Normal to Vector and alike...But I have not written these, as I am not sure if I would ever need them. I also wrote an Inverse function to calculate the inverse of a Matrix3D. Kevin Suffern uses the "create by inspection" method to build up the inverse out of the basic affine transformations. I decided to use the more mathematical approach. Furthermore, a lot of overrides have been written to allow vector & matrix manipulations like:

V1 := Inverse(M1 * M2) * V2;

Now I will start working on the color class, so I can plot pixels in a generic color space. This should be a fairly short sprint, I hope...

Until next time,
Marinko