mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 13:56:24 +02:00
Fixing comments, code style and constnats
This commit is contained in:
parent
0e13b1623b
commit
e8691c2f20
1 changed files with 25 additions and 27 deletions
|
@ -475,30 +475,29 @@ public:
|
|||
static QImage extractEquirectangularFace(const QImage& source, gpu::Texture::CubeFace face, int faceWidth) {
|
||||
QImage image(faceWidth, faceWidth, source.format());
|
||||
|
||||
glm::vec2 dstInvSize(1.0 / (float)image.width(), 1.0 / (float)image.height());
|
||||
float RAD_TO_SRC = 4.0f / glm::pi<float>();
|
||||
glm::vec2 dstInvSize(1.0f / (float)image.width(), 1.0f / (float)image.height());
|
||||
|
||||
struct CubeToXYZ {
|
||||
gpu::Texture::CubeFace _face;
|
||||
CubeToXYZ(gpu::Texture::CubeFace face) : _face(face) {}
|
||||
|
||||
glm::vec3 xyzFrom(const glm::vec2& uv) {
|
||||
auto nuv = glm::vec2(-1.0 + 2.0f * uv.x, 1.0 - 2.0f * uv.y);
|
||||
auto faceDir = glm::normalize(glm::vec3(-1.0f + 2.0f * uv.x, -1.0f + 2.0f * uv.y, 1.0f));
|
||||
|
||||
switch (_face) {
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_BACK_POS_Z:
|
||||
return glm::normalize(glm::vec3(-nuv.x, nuv.y, 1.0));
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_FRONT_NEG_Z:
|
||||
return glm::normalize(glm::vec3(nuv.x, nuv.y, -1.0));
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_LEFT_NEG_X:
|
||||
return glm::normalize(glm::vec3(1.0, nuv.y, nuv.x));
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_RIGHT_POS_X:
|
||||
return glm::normalize(glm::vec3(-1.0, nuv.y, -nuv.x));
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_BOTTOM_NEG_Y:
|
||||
return glm::normalize(glm::vec3(-nuv.x, -1.0, nuv.y));
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_TOP_POS_Y:
|
||||
default:
|
||||
return glm::normalize(glm::vec3(-nuv.x, 1.0, -nuv.y));
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_BACK_POS_Z:
|
||||
return glm::vec3(-faceDir.x, faceDir.y, faceDir.z);
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_FRONT_NEG_Z:
|
||||
return glm::vec3(faceDir.x, faceDir.y, -faceDir.z);
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_LEFT_NEG_X:
|
||||
return glm::vec3(faceDir.z, faceDir.y, faceDir.x);
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_RIGHT_POS_X:
|
||||
return glm::vec3(-faceDir.z, faceDir.y, -faceDir.x);
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_BOTTOM_NEG_Y:
|
||||
return glm::vec3(-faceDir.x, -faceDir.z, faceDir.y);
|
||||
case gpu::Texture::CubeFace::CUBE_FACE_TOP_POS_Y:
|
||||
default:
|
||||
return glm::vec3(-faceDir.x, faceDir.z, -faceDir.y);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -511,6 +510,7 @@ public:
|
|||
|
||||
auto flatDir = glm::normalize(glm::vec2(xyz.x, xyz.z));
|
||||
auto uvRad = glm::vec2( atan2(flatDir.x, flatDir.y), -asin(xyz.y));
|
||||
// Flip the vertical axis to QImage going top to bottom
|
||||
|
||||
const float LON_TO_RECT_U = 1.0f / (glm::pi<float>());
|
||||
const float LAT_TO_RECT_V = 2.0f / glm::pi<float>();
|
||||
|
@ -519,17 +519,15 @@ public:
|
|||
};
|
||||
RectToXYZ rectToXYZ;
|
||||
|
||||
|
||||
int srcFaceHeight = source.height();
|
||||
int srcFaceHeight = source.height();
|
||||
int srcFaceWidth = source.width();
|
||||
|
||||
glm::vec2 dstCoord;
|
||||
glm::ivec2 srcPixel;
|
||||
for (int y = 0; y < faceWidth; ++y) {
|
||||
dstCoord.y = (y + 0.5) * dstInvSize.y;
|
||||
|
||||
dstCoord.y = 1.0 - (y + 0.5f) * dstInvSize.y; // Fill cube face images from top to bottom
|
||||
for (int x = 0; x < faceWidth; ++x) {
|
||||
dstCoord.x = (x + 0.5) * dstInvSize.x;
|
||||
dstCoord.x = (x + 0.5f) * dstInvSize.x;
|
||||
|
||||
auto xyzDir = cubeToXYZ.xyzFrom(dstCoord);
|
||||
auto srcCoord = rectToXYZ.uvFrom(xyzDir);
|
||||
|
@ -537,10 +535,8 @@ public:
|
|||
srcPixel.x = floor(srcCoord.x * srcFaceWidth);
|
||||
srcPixel.y = floor(srcCoord.y * srcFaceHeight);
|
||||
|
||||
if (((uint32)srcPixel.x >= (uint32)source.width()) || ((uint32) srcPixel.y >= (uint32) source.height()) ) {
|
||||
//image.setPixel(x, y, 0xff000011);
|
||||
} else {
|
||||
image.setPixel(x, y, 0xff000000 | source.pixel(QPoint(srcPixel.x, srcPixel.y)));
|
||||
if (((uint32) srcPixel.x < (uint32) source.width()) && ((uint32) srcPixel.y < (uint32) source.height())) {
|
||||
image.setPixel(x, y, source.pixel(QPoint(srcPixel.x, srcPixel.y)));
|
||||
|
||||
// Keep for debug, this is showing the dir as a color
|
||||
// glm::u8vec4 rgba((xyzDir.x + 1.0)*0.5 * 256, (xyzDir.y + 1.0)*0.5 * 256, (xyzDir.z + 1.0)*0.5 * 256, 256);
|
||||
|
@ -702,12 +698,14 @@ gpu::Texture* TextureUsage::processCubeTextureColorFromImage(const QImage& srcIm
|
|||
faces.push_back(image.copy(QRect(layout._faceZPos._x * faceWidth, layout._faceZPos._y * faceWidth, faceWidth, faceWidth)).mirrored(layout._faceZPos._horizontalMirror, layout._faceZPos._verticalMirror));
|
||||
faces.push_back(image.copy(QRect(layout._faceZNeg._x * faceWidth, layout._faceZNeg._y * faceWidth, faceWidth, faceWidth)).mirrored(layout._faceZNeg._horizontalMirror, layout._faceZNeg._verticalMirror));
|
||||
} else if (layout._type == CubeLayout::EQUIRECTANGULAR) {
|
||||
int faceWidth = image.width() / 4;
|
||||
// THe face width is estimated from the input image
|
||||
const int EQUIRECT_FACE_RATIO_TO_WIDTH = 4;
|
||||
const int EQUIRECT_MAX_FACE_WIDTH = 2048;
|
||||
int faceWidth = std::min(image.width() / EQUIRECT_FACE_RATIO_TO_WIDTH, EQUIRECT_MAX_FACE_WIDTH);
|
||||
for (int face = gpu::Texture::CUBE_FACE_RIGHT_POS_X; face < gpu::Texture::NUM_CUBE_FACES; face++) {
|
||||
QImage faceImage = CubeLayout::extractEquirectangularFace(image, (gpu::Texture::CubeFace) face, faceWidth);
|
||||
faces.push_back(faceImage);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
qCDebug(modelLog) << "Failed to find a known cube map layout from this image:" << QString(srcImageName.c_str());
|
||||
|
|
Loading…
Reference in a new issue