Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
xorz57 committed Jan 30, 2024
1 parent be80353 commit 7319d7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions include/Cloth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

struct Cloth : SoftBody {
Cloth(const glm::vec2 &position, unsigned int rows, unsigned int cols, float padding);

float particleMass{1.0f};
float particleRadius{1.0f};
float springConstant{100.0f};
float dampingConstant{2.0f};
};
7 changes: 2 additions & 5 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Application::Application() {
}

void Application::Run() {
const unsigned int rows = 32u;
const unsigned int cols = 32u;
const unsigned int rows = 16u;
const unsigned int cols = 16u;
const float padding = 8.0f;
const glm::vec2 position = 0.5f * glm::vec2(mMode.width, mMode.height) - 0.5f * padding * glm::vec2(cols - 1, rows - 1);
mSoftBodies.emplace_back(Cloth(position, rows, cols, padding));
Expand Down Expand Up @@ -89,9 +89,6 @@ void Application::Run() {
}
}
mWindow.draw(clothSurface);
}

for (const SoftBody &softBody: mSoftBodies) {
for (const Spring &spring: softBody.springs) {
sf::VertexArray line(sf::Lines, 2);
line[0].position.x = spring.mParticle1.position.x;
Expand Down
6 changes: 3 additions & 3 deletions src/Cloth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Cloth::Cloth(const glm::vec2 &position, unsigned int rows, unsigned int cols, fl
for (unsigned int row = 0; row < rows; ++row) {
for (unsigned int col = 0; col < cols; ++col) {
const bool pinned = (row == 0) ? true : false;
particles.emplace_back(position + padding * glm::vec2(col, row), 1.0f, 2.0f, pinned);
particles.emplace_back(position + padding * glm::vec2(col, row), particleMass, particleRadius, pinned);
}
}

Expand All @@ -18,12 +18,12 @@ Cloth::Cloth(const glm::vec2 &position, unsigned int rows, unsigned int cols, fl
if (col < cols - 1) {
Particle &particle1 = particles[row * cols + col];
Particle &particle2 = particles[row * cols + col + 1];
springs.emplace_back(particle1, particle2, distance(particle1, particle2), 256.0f, 2.0f);
springs.emplace_back(particle1, particle2, distance(particle1, particle2), springConstant, dampingConstant);
}
if (row < rows - 1) {
Particle &particle1 = particles[row * cols + col];
Particle &particle2 = particles[(row + 1) * cols + col];
springs.emplace_back(particle1, particle2, distance(particle1, particle2), 256.0f, 2.0f);
springs.emplace_back(particle1, particle2, distance(particle1, particle2), springConstant, dampingConstant);
}
}
}
Expand Down

0 comments on commit 7319d7d

Please sign in to comment.