Original Post
Basically I'm trying to obtain the 3d position of a 2d texture coordinate on a 3d model, given the 3d position and 2d texture coordinate of the 3 points of the triangle which the 2d texture coordinate is on. I attempted to take a linear approach with the following fomula: And here is a picture for the more visual thinkers:
The 'x, y, z' represents the 3d position of the point, while the 'v, w' represents the texture coordinate of the point. 'x, y, z' can be any given point in 3d space, and the 'v, w' can be any value between 0 - 1. The formula I have there only takes 2 points into account which I think is the problem, but I'm not sure. Thanks in advance to anyone who attemps to solve this.
float v1, w1, x1, y1, z1;
float v2, w2, x2, y2, z2;
float v3, w3, x3, y3, z3;
float a, b, c, d, e, f;
//vertex 1
v1 = 0.1f;
w1 = 0.1f;
x1 = 1.0f;
y1 = 0.3f;
z1 = 1.7f;
//vertex 2
v2 = 0.8f;
w2 = 0.1f;
x2 = 18.2f;
y2 = 13.6f;
z2 = 7.6f;
//vertex 3
v3 = 0.1f;
w3 = 0.8f;
x3 = 0.3f;
y3 = 6.2f;
z3 = 10.3f;
//calc 2x3 matrix
a = (x1*w2 - x2*w1) / (w2*v1 - w1*v2);
b = (x1*v2 - x2*v1) / (w1*v2 - w2*v1);
c = (y1*w2 - y2*w1) / (w2*v1 - w1*v2);
d = (y1*v2 - y2*v1) / (w1*v2 - w2*v1);
e = (z1*w2 - z2*w1) / (w2*v1 - w1*v2);
f = (z1*v2 - z2*v1) / (w1*v2 - w2*v1);
//point in question
float v0, w0, x0, y0, z0;
v0 = 0.37f;
w0 = 0.53f;
//calc position of point in question
x0 = (a*v0)+(b*w0);
y0 = (c*v0)+(d*w0);
z0 = (e*v0)+(f*w0);
The 'x, y, z' represents the 3d position of the point, while the 'v, w' represents the texture coordinate of the point. 'x, y, z' can be any given point in 3d space, and the 'v, w' can be any value between 0 - 1. The formula I have there only takes 2 points into account which I think is the problem, but I'm not sure. Thanks in advance to anyone who attemps to solve this.