texture mapping using bilinear interpolation
I have been trying to achieve texture mapping using the bilinear interpolation method.I have been trying to rasterize a triangle thus i first find the barycentric weights and then try to i开发者_如何学Pythonnterpolate the uv co-ordinates but have got no success. Could some one suggest me if i am doing something wrong?
void baryWeights(int x4,int y4)
{
b1=(float)((x4*y2)-(x4*y3)-(x2*y4)+(x2*y3)+(x3*y4)-(x3*y2))/((x1*y2)-(x1*y3)-(x2*y1z)+(x2*y3)+(x3*y1z)-(x3*y2));
b2=(float)((x1*y4)-(x1*y3)-(x4*y1z)+(x4*y3)+(x3*y1z)-(x3*y4))/((x1*y2)-(x1*y3)-(x2*y1z)+(x2*y3)+(x3*y1z)-(x3*y2));
b3=(float)((x1*y2)-(x1*y4)-(x2*y1z)+(x2*y4)+(x4*y1z)-(x4*y2))/((x1*y2)-(x1*y3)-(x2*y1z)+(x2*y3)+(x3*y1z)-(x3*y2));
}
void linearinterpolation()
{
uc=b1*v1u+b2*v2u+b3*v3u;
vc=b1*v1v+b2*v2v+b3*v3v;
}
I get distorted texture mapping for this code that i am using
精彩评论