Created
October 18, 2015 17:02
-
-
Save CedricGuillemet/7ecf352692d1143dccd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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