Skip to content

Instantly share code, notes, and snippets.

@CedricGuillemet
Created October 18, 2015 17:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricGuillemet/7ecf352692d1143dccd9 to your computer and use it in GitHub Desktop.
Save CedricGuillemet/7ecf352692d1143dccd9 to your computer and use it in GitHub Desktop.
void computeForce(TileSheetNode& node, TileSheetNode& childNode, bool keepClose)
{
float dist = distance(node.mPos, childNode.mPos);
if (dist < 0.01f)
{
return;
}
float idealDist = node.mRadius + childNode.mRadius;
vec_t dir = normalized(node.mPos - childNode.mPos);
float dif = idealDist - dist;
vec_t force = dir * dif * 0.5f;
if (keepClose)
{
if (dif > 0.f)
return;
// move a bit
node.mPos += force * 1.0f;
childNode.mPos -= force * 1.0f;
}
else
{
if (dif < 0.f)
return;
node.mForce += force * 0.3f;
childNode.mForce -= force * 0.3f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment