I want to map textures triangles for 3D rendering in my ray tracer. I am using barycentric coordinates to locate points on the triangles. But the result isn't correct. This is what I did :
3 triangle vertices : a b c
1 intersection point (Raytracing) : p
vertex coordinates are a.x a.y a.z / b.x b.y b.z / c.x c.y c.z
texture coordinates are a.tx a.ty / b.tx b.ty / c.tx c.ty
Firstly , I get the distance between the intersection point and one of the triangle vertices:
d1 = get_distance(p, a);
d2 = get_distance(p, b);
d3 = get_distance(p, c);
Secondly , I calculate the barycentric ratio for each vertices :
r1 = d1 / (d1 + d2 + d3);
r2 = d2 / (d1 + d2 + d3);
r3 = d3 / (d1 + d2 + d3);
And finally , I determine the coordinates of the point on the image :
x_img = (r1 * a.tx) + (r2 * b.tx) + (r3 * c.tx);
y_img = (r1 * a.ty) + (r2 * b.ty) + (r3 * c.ty);
But it doesn't work. Can you explain me why please ?
The render of Kik-Ass Head :
![kickass]: http://imgur.com/3LAjrWm


