   ray-to-triangle problem
  HiI have a function to check if a ray from camera to mouse coordinates in 3D hits a triangle but it seems to be working somehow wrong..Could someone check the function if there's something wrong?p is the ray start pointd is the ray end pointv0, v1 and v2 are the triangle's vertices' coordinatesint RayIntersectsTriangle(float *p, float *d, float *v0, float *v1, float *v2){float e1[3],e2[3],h[3],s[3],q[3];float a,f,u,v,t;e1[0] = v1[0] - v0[0];e1[1] = v1[1] - v0[1];e1[2] = v1[2] - v0[2];e2[0] = v2[0] - v0[0];e2[1] = v2[1] - v0[1];e2[2] = v2[2] - v0[2];h[0] = (d[1] * e2[2]) - (e2[1] * d[2]);h[1] = (d[2] * e2[0]) - (e2[2] * d[0]);h[2] = (d[0] * e2[1]) - (e2[0] * d[1]);a = (e1[0] * h[0]) + (e1[1] * h[1]) + (e1[2] * h[2]);if (a > -0.00001 && a < 0.00001)return(false);f = 1/a;s[0] = p[0] - v0[0];s[1] = p[1] - v0[1];s[2] = p[2] - v0[2];u = f * ((s[0] * h[0]) + (s[1] * h[1]) + (s[2] * h[2]));if (u < 0.0 || u > 1.0)return(false);q[0] = s[1] * e1[2] - e1[1] * s[2];q[1] = s[2] * e1[0] - e1[2] * s[0];q[2] = s[0] * e1[1] - e1[0] * s[1];v = f * ((d[0] * q[0]) + (d[1] * q[1]) + (d[2] * q[2]));if (v < 0.0 || u + v > 1.0)return(false);t = f * ((e2[0] * q[0]) + (e2[1] * q[1]) + (e2[2] * q[2]));if(t > 0.00001)return(true);elsereturn(false);}I've noticed, when the ray's starting point is at (0,0,0) everything works fine, but when I move the start point the triangle's hit area seems to be moving in the opposite direction or that's what I think..In this screenshot, camera is at x = 0, z = 0 and y = 10. The triangle hit area is marked on red and the real triangle is the white one.http://img98.imageshack.us/img98/4509/asddbb.pngEDIT: I'm using C++ with SDL and openGL   
  Nevermind. Function had no problems, seems like my gluUnProject was in the wrong place, so it didn't give me the real 3D mouse coordinates   