Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments to the buoyancy demo to make the code more easily reusable #263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions demos/buoyancy.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
} else if(aabb.lowerBound[1] < planePosition[1]){
// Partially submerged
var width = aabb.upperBound[0] - aabb.lowerBound[0];
var height = 0 - aabb.lowerBound[1];
var height = planePosition[1] - aabb.lowerBound[1];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was caught by this issue as well when I was running my own implementation.

areaUnderWater = width * height;
p2.vec2.set(centerOfBouyancy, aabb.lowerBound[0] + width / 2, aabb.lowerBound[1] + height / 2);
} else {
Expand All @@ -95,15 +95,15 @@

// Compute lift force
p2.vec2.subtract(liftForce, planePosition, centerOfBouyancy);
p2.vec2.scale(liftForce, liftForce, areaUnderWater * k);
p2.vec2.scale(liftForce, liftForce, areaUnderWater * k / body.shapes.length);
liftForce[0] = 0;

// Make center of bouycancy relative to the body
p2.vec2.subtract(centerOfBouyancy,centerOfBouyancy,body.position);

// Viscous force
body.getVelocityAtPoint(v, centerOfBouyancy);
p2.vec2.scale(viscousForce, v, -c);
p2.vec2.scale(viscousForce, v, -c / body.shapes.length);

// Apply forces
body.applyForce(viscousForce,centerOfBouyancy);
Expand Down