ssloy / tinyrenderer

A brief computer graphics / rendering course
https://github.com/ssloy/tinyrenderer/wiki
Other
20.68k stars 1.98k forks source link

In lesson2,something wrong in function `barycentric` when i run task in Vscode and i fix it. #132

Closed lvgangyang closed 1 year ago

lvgangyang commented 1 year ago

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)

ssloy commented 1 year ago

Check the latest version of the code in the repo. https://github.com/ssloy/tinyrenderer/blob/6d3acdb9ee452449b528ef3900ef5528dad0f807/our_gl.cpp#L24