From 66e768c89bf91fb05a93ecd2519898eb70b7b8d4 Mon Sep 17 00:00:00 2001 From: mattkae Date: Fri, 23 Dec 2022 16:37:31 -0500 Subject: Gently rotating falkes --- themes/dist/output.wasm | Bin 135775 -> 135987 bytes themes/src/Snowflake.cpp | 18 ++++++++++++------ themes/src/Snowflake.h | 8 +++----- 3 files changed, 15 insertions(+), 11 deletions(-) (limited to 'themes') diff --git a/themes/dist/output.wasm b/themes/dist/output.wasm index 78fbef4..ed74d8b 100755 Binary files a/themes/dist/output.wasm and b/themes/dist/output.wasm differ diff --git a/themes/src/Snowflake.cpp b/themes/src/Snowflake.cpp index e9f6d5d..9941a5b 100644 --- a/themes/src/Snowflake.cpp +++ b/themes/src/Snowflake.cpp @@ -6,7 +6,8 @@ const Vector4 snowColor = Vector4(1.0, 0.98, 0.98, 1); -inline void generateSnowflakeShape(matte::List* vertices, i32 numArms, f32 radius, f32 innerRadius) { +inline void generateSnowflakeShape(matte::List* vertices, i32 numArms, f32 outerRadius, f32 innerRadius) { + outerRadius = outerRadius + innerRadius; f32 dx = ((2 * PI) / numArms) / 3.0; for (i32 centerIdx = 0; centerIdx < (3 * numArms); centerIdx+=3) { f32 degreeStart = dx * centerIdx; @@ -18,8 +19,8 @@ inline void generateSnowflakeShape(matte::List* vertices, i32 numArms, f32 sinStart = sinf(degreeStart); f32 sinEnd = sinf(degreeEnd); - Vector2 leftEnd = Vector2(radius * cosStart, radius * sinStart); - Vector2 rightEnd = Vector2(radius * cosEnd, radius * sinEnd); + Vector2 leftEnd = Vector2(outerRadius * cosStart, outerRadius * sinStart); + Vector2 rightEnd = Vector2(outerRadius * cosEnd, outerRadius * sinEnd); Vector2 diff = (rightEnd - leftEnd) / 2.0; Vector2 leftStart = Vector2(-diff.x, -diff.y) + Vector2(innerRadius * cosStart, innerRadius * sinStart); Vector2 rightStart = diff + Vector2(innerRadius * cosEnd, innerRadius * sinEnd); @@ -35,10 +36,15 @@ inline void generateSnowflakeShape(matte::List* vertices, i32 numArms, inline void initFlake(SnowflakeParticleRenderer* renderer, SnowflakeUpdateData* ud) { ud->vtxIdx = renderer->vertices.numElements; - generateSnowflakeShape(&renderer->vertices, randomIntBetween(4, 16), randomFloatBetween(8.f, 16.f), randomFloatBetween(2.f, 6.f)); + generateSnowflakeShape(&renderer->vertices, + randomIntBetween(4, 12), + randomFloatBetween(4.f, 12.f), + randomFloatBetween(4.f, 12.f)); + ud->numVertices = renderer->vertices.numElements - ud->vtxIdx; ud->velocity = Vector2(randomFloatBetween(-10, 10), randomFloatBetween(-100, -85)); ud->position = Vector2(randomFloatBetween(0, renderer->xMax), randomFloatBetween(renderer->yMax, 3 * renderer->yMax)); + ud->rotateVelocity = randomFloatBetween(-PI / 8.f, PI / 8.f); } void SnowflakeParticleRenderer::load(SnowflakeLoadParameters params, Renderer2d* renderer) { @@ -82,7 +88,6 @@ void SnowflakeParticleRenderer::load(SnowflakeLoadParameters params, Renderer2d* GL_FALSE, sizeof(Vertex2D), (GLvoid *)(offsetof(Vertex2D, vMatrix) + offset)); - //glVertexAttribDivisor(renderer->attributes.vMatrix + idx, 1); } glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -97,8 +102,9 @@ inline void resetFlake(SnowflakeParticleRenderer* renderer, SnowflakeUpdateData* inline void updateFlake(SnowflakeParticleRenderer* renderer, SnowflakeUpdateData* ud, i32 s, f32 dtSeconds, bool addWind) { if (addWind) ud->velocity += renderer->windSpeed; ud->position += ud->velocity * dtSeconds; + ud->rotation += ud->rotateVelocity * dtSeconds; - Mat4x4 m = Mat4x4().translateByVec2(ud->position); + Mat4x4 m = Mat4x4().translateByVec2(ud->position).rotate2D(ud->rotation); for (i32 v = ud->vtxIdx; v < (ud->vtxIdx + ud->numVertices); v++) { renderer->vertices.data[v].vMatrix = m; } diff --git a/themes/src/Snowflake.h b/themes/src/Snowflake.h index c6323d6..02673c1 100644 --- a/themes/src/Snowflake.h +++ b/themes/src/Snowflake.h @@ -6,11 +6,9 @@ struct Renderer2d; struct Vertex2D; struct SnowflakeLoadParameters { - i32 numSnowflakes = 1000; + i32 numSnowflakes = 500; f32 rateOfSnowfall = 0.1f; Vector2 flakeV0 = { 0, 1 }; - f32 flakeSize = 5.f; - f32 flakeSizeDeviation = 1.f; Vector4 snowColor = { 0.8, 0.8, 0.8, 1.0 }; f32 windIntervalSeconds = 1.5; }; @@ -19,8 +17,8 @@ struct SnowflakeUpdateData { Vector2 v0; Vector2 velocity; Vector2 position; - f32 rotation; - bool onGround = false; + f32 rotateVelocity = 0.f; + f32 rotation = 0; i32 vtxIdx = 0; i32 numVertices = 0; -- cgit v1.2.1