In lesson2,something wrong in function `barycentric` when i run task in Vscode and i fix it.
lvgangyang opened this issue · 1 comments
lvgangyang commented
The function barycentric
,when i the assess pts
member variable ,pts[][]
can't pass the compiler.
Here is the solution
Vec3f barycentric(Vec2i *pts, Vec2i P) {
Vec3f u = Vec3f(pts[2].u-pts[0].u, pts[1].u-pts[0].u, pts[0].u-P.u)^Vec3f(pts[2].v-pts[0].v, pts[1].v-pts[0].v, pts[0].v-P.v);
/* `pts` and `P` has integer value as coordinates
so `abs(u[2])` < 1 means `u[2]` is 0, that means
triangle is degenerate, in this case return something with negative coordinates */
if (std::abs(u.z)<1) return Vec3f(-1,1,1);
return Vec3f(1.f-(u.x+u.y)/u.z, u.y/u.z, u.x/u.z);
}
the other wrong i cant pass compiler is
TGAColor(255, 0, 0)
it should be TGAColor(255, 0, 0, 255)