From 5f018e76bac9d0c9f6e1761ea25bb508ecab99d7 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 30 Sep 2021 19:25:38 -0700 Subject: [PATCH] cloth wind rippling --- src/Silkworm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Silkworm.c b/src/Silkworm.c index 7d86b69..9196464 100644 --- a/src/Silkworm.c +++ b/src/Silkworm.c @@ -351,6 +351,8 @@ typedef struct Silkworm_Context float yBound; uint32_t clothDensity; + float timeElapsed; + uint8_t* currentBufferAddress; /* GM doesnt let you pass more than 4 arguments with different types lol */ /* keep track of these so can do callbacks */ @@ -403,6 +405,7 @@ void Silkworm_Init() context->xBound = 1000; context->yBound = 1000; context->clothDensity = 4; + context->timeElapsed = 0; context->nodeDestructionDataCapacity = 16; context->nodeDestructionData = malloc(sizeof(Silkworm_Vector2) * context->nodeDestructionDataCapacity); @@ -731,6 +734,8 @@ void Silkworm_Update(double deltaTime) } Silkworm_PerformDestroys(); + + context->timeElapsed += delta; } double Silkworm_CreateNode(double xPosition, double yPosition, double mass, double friction, double radius, double pushFactor, double windFactor) @@ -1084,8 +1089,8 @@ void Silkworm_ApplyWind(double xSpeed, double ySpeed) if (node != NULL && !node->pinned) { - node->position.x += (float)xSpeed * 0.025f * node->windFactor; - node->position.y += (float)ySpeed * 0.025f * node->windFactor; + node->position.x += (0.5f * sinf(context->timeElapsed / 15 + node->position.y / 2) + 0.5f) * (float)xSpeed * 0.05f * node->windFactor; + node->position.y += (0.5f * sinf(context->timeElapsed / 15 + node->position.x / 3) + 0.5f) * (float)ySpeed * 0.05f * node->windFactor; } } } @@ -1977,6 +1982,8 @@ void Silkworm_ClearAll() } Silkworm_PerformDestroys(); + + context->timeElapsed = 0; } void Silkworm_Finish()