Update model.cpp

fix uv wrapping, thanks to Marek
This commit is contained in:
erwincoumans
2020-10-27 13:38:01 -07:00
committed by GitHub
parent a67681aee5
commit e3274d7fc1

View File

@@ -166,14 +166,23 @@ TGAColor Model::diffuse(Vec2f uvf)
// bool repeat = true;
// if (repeat)
{
uvf[0] = std::modf(uvf[0], &val);
uvf[1] = std::modf(uvf[1], &val);
}
Vec2i uv(uvf[0] * diffusemap_.get_width(), uvf[1] * diffusemap_.get_height());
uvf[0] = std::modf(uvf[0], &val);
if (uvf[0] < 0)
{
uvf[0] = uvf[0] + 1;
}
uvf[1] = std::modf(uvf[1], &val);
if (uvf[1] < 0)
{
uvf[1] = uvf[1] + 1;
}
}
Vec2i uv(uvf[0] * diffusemap_.get_width(), uvf[1] * diffusemap_.get_height());
return diffusemap_.get(uv[0], uv[1]);
}
return TGAColor(255, 255, 255, 255);
}
Vec3f Model::normal(Vec2f uvf)
{