Add cylindrical mapping!

This commit is contained in:
Godzil
2020-03-04 16:16:35 +00:00
parent 1b6c14691b
commit 7209244f48
6 changed files with 123 additions and 3 deletions

View File

@@ -67,8 +67,17 @@ public:
}
static void planarMap(Tuple point, double &u, double &v) {
u = fmod(point.x, 1);
v = fmod(point.z, 1);
u = modulo(point.x, 1.0);
v = modulo(point.z, 1.0);
}
static void cylindricalMap(Tuple point, double &u, double &v) {
/* Let's get the azimuthal angle, same as with the spherical mapping */
double theta = atan2(point.x , point.z);
double raw_u = theta / (2 * M_PI);
u = 1 - (raw_u + 0.5);
v = modulo(point.y, 1.0);
}
Colour patternAt(Tuple point)
@@ -83,6 +92,10 @@ public:
case PLANAR_MAP:
this->planarMap(point, u, v);
break;
case CYLINDRICAL_MAP:
this->cylindricalMap(point, u, v);
break;
}
return this->pattern->uvPatternAt(u, v);