17 if (face < 0 || face >= 6)
return false;
18 static const RiseMath::Vector3 normal[] = {{0,-1,0},{1,0,0},{-1,0,0},{0,1,0},{0,0,-1},{0,0,1}};
19 static const RiseMath::Vector3 right[] = {{1,0,0},{0,1,0},{0,-1,0},{-1,0,0},{1,0,0},{1,0,0}};
20 static const RiseMath::Vector3 down[] = {{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,-1,0},{0,1,0}};
21 static const int originU[] = {0,2038,-2038,4076,0,0};
22 static const int originV[] = {0,0,0,0,-2038,2038};
23 const int a = 2 * (u - originU[face]) + 1 - 2038;
24 const int b = 2 * (v - originV[face]) + 1 - 2038;
25 const bool crossU = std::abs(a) > 2038, crossV = std::abs(b) > 2038;
26 if ((crossU && crossV) || std::abs(a) >= 6114 || std::abs(b) >= 6114)
return false;
27 const float sign = (crossU ? a : b) < 0 ? -1.f : 1.f;
28 const int du[] = {0,1,1,0}, dv[] = {0,0,1,1};
29 for (
int i = 0; i < 4; ++i)
31 const float x = float(u + du[i] - originU[face] - 1019);
32 const float y = float(v + dv[i] - originV[face] - 1019);
33 auto p = crossU ? right[face] * (sign * 1019.f) + normal[face] * (2038.f - std::fabs(x)) + down[face] * y
34 : crossV ? down[face] * (sign * 1019.f) + normal[face] * (2038.f - std::fabs(y)) + right[face] * x
35 : normal[face] * 1019.f + right[face] * x + down[face] * y;