int c0 = (0xF & (data >> 16)) % 8;
int c1 = (0xF & (data >> 20)) % 8;
int c2 = (0xF & (data >> 24)) % 8;
int c3 = (0xF & (data >> 28)) % 8;
Triangle triangle = WaterModel.t012[c0][c1][c2];
boolean hit = false;
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
hit = true;
}
triangle = WaterModel.t230[c2][c3][c0];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
ray.u = 1-ray.u;
ray.v = 1-ray.v;
hit = true;
}
triangle = WaterModel.westt[c0][c3];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double y = ray.t * ray.d.y + ray.x.y;
double z = ray.t * ray.d.z + ray.x.z;
y -= QuickMath.floor(y);
z -= QuickMath.floor(z);
ray.u = z;
ray.v = y;
hit = true;
}
triangle = WaterModel.westb[c0];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double y = ray.t * ray.d.y + ray.x.y;
double z = ray.t * ray.d.z + ray.x.z;
y -= QuickMath.floor(y);
z -= QuickMath.floor(z);
ray.u = z;
ray.v = y;
hit = true;
}
triangle = WaterModel.eastt[c1][c2];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double y = ray.t * ray.d.y + ray.x.y;
double z = ray.t * ray.d.z + ray.x.z;
y -= QuickMath.floor(y);
z -= QuickMath.floor(z);
ray.u = z;
ray.v = y;
hit = true;
}
triangle = WaterModel.eastb[c1];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double y = ray.t * ray.d.y + ray.x.y;
double z = ray.t * ray.d.z + ray.x.z;
y -= QuickMath.floor(y);
z -= QuickMath.floor(z);
ray.u = z;
ray.v = y;
hit = true;
}
triangle = WaterModel.southt[c0][c1];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double x = ray.t * ray.d.x + ray.x.x;
double y = ray.t * ray.d.y + ray.x.y;
x -= QuickMath.floor(x);
y -= QuickMath.floor(y);
ray.u = x;
ray.v = y;
hit = true;
}
triangle = WaterModel.southb[c1];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double x = ray.t * ray.d.x + ray.x.x;
double y = ray.t * ray.d.y + ray.x.y;
x -= QuickMath.floor(x);
y -= QuickMath.floor(y);
ray.u = x;
ray.v = y;
hit = true;
}
triangle = WaterModel.northt[c2][c3];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double x = ray.t * ray.d.x + ray.x.x;
double y = ray.t * ray.d.y + ray.x.y;
x -= QuickMath.floor(x);
y -= QuickMath.floor(y);
ray.u = 1-x;
ray.v = y;
hit = true;
}
triangle = WaterModel.northb[c2];
if (triangle.intersect(ray)) {
ray.n.set(triangle.n);
ray.n.scale(QuickMath.signum(-ray.d.dot(triangle.n)));
ray.t = ray.tNear;
double x = ray.t * ray.d.x + ray.x.x;
double y = ray.t * ray.d.y + ray.x.y;