summaryrefslogtreecommitdiff
path: root/2d/softbody/softbody_2
diff options
context:
space:
mode:
authormattkae <mattkae@protonmail.com>2022-04-28 21:10:51 -0400
committermattkae <mattkae@protonmail.com>2022-04-28 21:10:51 -0400
commit3a52fa8cae56c9ff9ea194a959f7469b4db48ef0 (patch)
tree61a919c99664e60c239c0218772082e278ac5fb8 /2d/softbody/softbody_2
parent38d89c1182a61ca4e024e0834ae9187db76c67f8 (diff)
Diffstat (limited to '2d/softbody/softbody_2')
-rw-r--r--2d/softbody/softbody_2/SpringRectangle.h22
-rwxr-xr-x2d/softbody/softbody_2/dist/output.wasmbin44744 -> 51716 bytes
2 files changed, 8 insertions, 14 deletions
diff --git a/2d/softbody/softbody_2/SpringRectangle.h b/2d/softbody/softbody_2/SpringRectangle.h
index 02e5308..2156314 100644
--- a/2d/softbody/softbody_2/SpringRectangle.h
+++ b/2d/softbody/softbody_2/SpringRectangle.h
@@ -33,8 +33,6 @@ struct SoftbodyRectangle {
Vector2 springDimensions;
// Runtime data
- Vector2 velocity;
- Vector2 worldPosition;
PointMassUpdateData* updateData = NULL;
float32 rotationalVelocity = 0.f;
float32 rotation = 0.f;
@@ -47,8 +45,7 @@ struct SoftbodyRectangle {
Vertex2d* pointsVertices = NULL;
void load(Renderer2d* renderer) {
- velocity = Vector2(0, 0);
- worldPosition = Vector2(800.f / 2 - width / 2, 400.f);
+ auto worldPosition = Vector2(800.f / 2 - width / 2, 400.f);
springDimensions = Vector2(width / springDensity, height / springDensity);
int32 numVertices = springDensity * springDensity; // Each subdivision is a square.
int32 numIndices = 6 * ((springDensity - 1) * (springDensity - 1));
@@ -62,10 +59,15 @@ struct SoftbodyRectangle {
int32 iIdx = 0;
float32 inverseDensity = 1.f / springDensity;
float32 halfInv = inverseDensity / 2.f;
+ float32 rotation = PI / 8.f;
for (int32 y = 0; y < springDensity; y++) { // Rows
for (int32 x = 0; x < springDensity; x++) { // Columns
- Vector2 vpos = Vector2(x * inverseDensity - halfInv, y * inverseDensity- halfInv);
- // Get the position in mode coordinates
+ Vector2 vpos = Vector2(
+ x * inverseDensity - halfInv,
+ y * inverseDensity - halfInv
+ );
+ vpos = vpos.rotate(rotation);
+ // Get the position in model coordinates
vpos.x = vpos.x * width;
vpos.y = vpos.y * height;
updateData[vIdx].localPosition = vpos;
@@ -157,12 +159,6 @@ struct SoftbodyRectangle {
}
}
- // -- Calculate the rotation of the entire body
- //rotationalVelocity = 0.1f;
- //auto gravityDt = GRAVITY_ACCELERATION * dtSeconds;
- //velocity = velocity + gravityDt;
- //worldPosition = worldPosition + (velocity * dtSeconds);
-
// -- Euler integrate and update the local position of each vertex.
for (int32 v = 0; v < pointsMesh.numVertices; v++) {
auto pointMass = &updateData[v];
@@ -171,8 +167,6 @@ struct SoftbodyRectangle {
pointMass->acceleration = pointMass->force / jointMassKg;
pointMass->velocity = pointMass->velocity + (pointMass->acceleration * dtSeconds);
pointMass->worldPosition = pointMass->worldPosition + (pointMass->velocity * dtSeconds);
- // pointMass->restingPosition = pointMass->restingPosition.rotateAround(rotationalVelocity * dtSeconds, modelPosition);
- // pointMass->currentPosition = pointMass->currentPosition.rotateAround(rotationalVelocity * dtSeconds, modelPosition);
vertices[v].position = pointMass->worldPosition;
pointsVertices[v].position = pointMass->worldPosition;
diff --git a/2d/softbody/softbody_2/dist/output.wasm b/2d/softbody/softbody_2/dist/output.wasm
index 98cade0..da27ab7 100755
--- a/2d/softbody/softbody_2/dist/output.wasm
+++ b/2d/softbody/softbody_2/dist/output.wasm
Binary files differ