Anyone have source code or tips how to make function that finds out intersection point with line and plane in 3D space? We know line's start point and direction vectors and also position and normal vector for plane.

This is what i have come up with but it doesn't work when i move either line or plane from 0,0,0 point.

[pascal]function Dot(const a,b: P3f): single;
begin
result:=a.x*b.x + a.y*b.y + a.z*b.z;
end;

function vDec(const a,b: P3f): P3f;
begin
result.x:=a.x-b.x; result.y:=a.y-b.y; result.z:=a.z-b.z;
end;

procedure rayPlaneCollision(const rayOrigin, rayDirection,
planeOrigin, planeNormal: P3f; intersection: pP3f);
var u,d: single;
begin
d:=dot(planeNormal,rayDirection);
if d=0 then exit; // No intersection
u:=dot(planeNormal,vDec(planeOrigin,rayOrigin)) /d;
intersection.x:=rayOrigin.x+u*rayDirection.x;
intersection.y:=rayOrigin.y+u*rayDirection.y;
intersection.z:=rayOrigin.z+u*rayDirection.z;
end;[/pascal]

Update: It does work when planeOrigin and rayorigin are at exact same (anywhere) point, but that is cheating because that is also the same as intersection point.