currentPosition is the current position of your view. In order to check a ray for intersections you will probably need the origin from where the ray is projected.
I used it in this rayIntersection function:
the triangle is defined by three points a,b,c
and subsequently by the vectors ab,ac
the return is the factor by which you have to scale _dir to reach
the intersection point: hit = _origin + (return)*_dir;
public float rayIntersection(Point3f _origin, Vector3f _dir) {
Vector3f pvec = Util3d.makeNormal(ac,_dir);
float det = Util3d.dotProduct(ab,pvec);
if (det > -Util3d.EPSILONf && det < Util3d.EPSILONf) return 0;
float inv_det = 1.0f / det;
Vector3f tvec = Util3d.makeVector(a,_origin);
float u = Util3d.dotProduct(tvec,pvec) * inv_det;
if (u < 0.0f || u > 1.0f) return 0;
Vector3f qvec = Util3d.makeNormal(ab,tvec);
float v = Util3d.dotProduct(qvec,_dir)*inv_det;
if ( v < 0.0 || (u+v) > 1.0 ) return 0;
return Util3d.dotProduct(ac,qvec)*inv_det;
}
PS: don’t ask me how or why this works. I got it from some publication about efficient intersection computation and ported it
to java. It has not let me down so far.