I use the translated code from Terathon

I could post the translated code but I use my own vector lib which is using operator overloading

Edit: Ah wait.. for some reason the function has been erased from the lib... I can maybe find it later today

Edit2: Actually I found it again without operator overloaded vectors:
[pascal]function calculateTangentSpaceVector(position1, position2, position3: tvertex): normals;
var side0, side1, normal, tangent, binormal, tangentCross: tvector4f;
deltaV0, deltaV1, deltaU0, deltaU1: real;
begin
side0 := sub(position2.pos, position1.pos);
side1 := sub(position3.pos, position1.pos);
normal := normalize(cross(side0, side1));

deltaV0 := position1.texcoord.y - position2.texcoord.y;
deltaV1 := position3.texcoord.y - position1.texcoord.y;
tangent := normalize(sub(multiply(side0, deltaV1), multiply(side1, deltaV0)));

deltaU0 := position1.texcoord.x - position2.texcoord.x;
deltaU1 := position3.texcoord.x - position1.texcoord.x;
binormal := normalize(sub(multiply(side0, deltau1), multiply(side1, deltau0)));
tangentCross := normalize(cross(tangent, binormal));
if (dot(tangentCross,normal) < 0.0) then
begin
tangent := sub(tangent,tangent);
binormal := sub(binormal,binormal);
end;
result.tangent := tangent;
result.binormal := binormal;
end;[/pascal]