just had a quick couple questions as to why my I keep getting an error saying that x and y are not assigned a value at computeBarycentri2d(x, y, t.v) when in the if(!insideTriangle(x, y, t.v)) the values are assigned as an int value. The error I keep receiving for each value is "identifier x is not defined"
The other issue I am running into is that the continue statement in the if(zp >= depth_buf[y * width + x]) wont work giving me the error "a continue statement can only be used in a loop".
Any sort of help on how to fix these errors is greatly appreciated
void rst::rasterizer::rasterize_triangle(const Triangle& t, const std::array<Eigen::Vector3f, 3>& view_pos)
{
std::array v = t.toVector4();
float trix[3] = {t.v[0][0], t.v[1][0], t.v[2][0] };
float triy[3] = {t.v[0][1], t.v[1][1], t.v[2][1] };
std::pair<float*, float*> xrange = std::minmax_element(trix, trix + 3);
std::pair<float*, float*> yrange = std::minmax_element(triy, triy + 3);
for (int x = std::floor(*xrange.first); x < std::ceil(*xrange.second); ++x)
for(int y = std::floor(*yrange.first); y < std::ceil(*yrange.second); ++y)
if(!insideTriangle(x, y, t.v)) continue;
auto[alpha, beta, gamma] = computeBarycentric2D(x, y, t.v);
float Z = 1.0 / (alpha / v[0].w() + beta / v[1].w() + gamma / v[2].w());
float zp = alpha * v[0].z() / v[0].w() + beta * v[1].z() / v[1].w() + gamma * v[2].z() / v[2].w();
zp *= Z;
if(zp >= depth_buf[y * width + x]) continue;
depth_buf[y * width + x] = zp;
}
Aucun commentaire:
Enregistrer un commentaire