clouds fixed

This commit is contained in:
2021-09-18 12:37:32 +02:00
parent 4f30f2ce3a
commit 909fa0c07b
4 changed files with 9 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

BIN
bin/main

Binary file not shown.

View File

@@ -26,14 +26,16 @@ public:
glm::vec4 getUVsExtended(int index, int lengthX, int lengthY) glm::vec4 getUVsExtended(int index, int lengthX, int lengthY)
{ {
int tileX = index % dims.x; int tileX = index % dims.x;
int tileY = index / dims.x; int tileY = index / dims.x + lengthY -1 ;
int secondTileX = lengthX % dims.x; int secondTileX = lengthX % dims.x;
std::cout << "secondTileX: " << secondTileX << "\n"; std::cout << "secondTileX: " << secondTileX << "\n";
glm::vec4 UV; glm::vec4 UV;
UV.x = tileX / (float)dims.x; UV.x = tileX / (float)dims.x;
UV.y = tileY / (float)dims.y; UV.y = tileY / (float)dims.y ;
UV.z = UV.x + (float)secondTileX / dims.x; UV.z = UV.x + (float)secondTileX / dims.x;
UV.w = UV.y - (float)lengthY / dims.y; UV.w = UV.y - (float)1*lengthY / dims.y;
std::cout << "uvs: " << UV.x << " " << UV.y << " " << UV.z << " " << UV.w << " "
<< "\n";
return UV; return UV;
} }
}; };

View File

@@ -8,7 +8,7 @@ Cloud::Cloud(float speed, glm::vec2 pos, glm::vec2 size, int cloudIndex)
{22, 2, 1}, {22, 2, 1},
{24, 1, 1}, {24, 1, 1},
{25, 3, 1}, {25, 3, 1},
{42, 6, 2}}; {42, 6, 3}};
glm::vec4 spriteUVs = spriteSheet.getUVsExtended(cloudIndexes[cloudIndex][0], cloudIndexes[cloudIndex][1], cloudIndexes[cloudIndex][2]); glm::vec4 spriteUVs = spriteSheet.getUVsExtended(cloudIndexes[cloudIndex][0], cloudIndexes[cloudIndex][1], cloudIndexes[cloudIndex][2]);
GLfloat vertices[] = { GLfloat vertices[] = {
@@ -78,9 +78,9 @@ Background::Background()
glm::vec2(xScalar - 500.0f, yScalar), glm::vec2(xScalar - 500.0f, yScalar),
glm::vec2(128.0f * (float)cloudIndexes[cloudIndex][1], 128.0f * (float)cloudIndexes[cloudIndex][2]) * sizeScalar, cloudIndex)); glm::vec2(128.0f * (float)cloudIndexes[cloudIndex][1], 128.0f * (float)cloudIndexes[cloudIndex][2]) * sizeScalar, cloudIndex));
} }
clouds.push_back(new Cloud(1.0f, // clouds.push_back(new Cloud(1.0f,
glm::vec2(1000.0f, 300.0f), // glm::vec2(800.0f, 300.0f),
glm::vec2(128.0f * 6.0f, 128.0f * 3.0f), 4)); // glm::vec2(128.0f * 6.0f, 128.0f * 3.0f)*(4.0f/3.0f), 4));
} }
void Background::drawBackground(SpriteRenderer &renderer, float dt) void Background::drawBackground(SpriteRenderer &renderer, float dt)
{ {