-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #519 from RafaelBarbosatec/develop
Version 3.9.2
- Loading branch information
Showing
20 changed files
with
146 additions
and
139 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:bonfire/bonfire.dart'; | ||
|
||
// Mixin responsable to give the bounce behavior. (experimental) | ||
mixin ElasticCollision on BlockMovementCollision { | ||
double _restitution = 2; | ||
bool _bouncingObjectEnabled = true; | ||
|
||
void setupElasticCollision({ | ||
bool? enabled, | ||
double? restitution, | ||
}) { | ||
_bouncingObjectEnabled = enabled ?? _bouncingObjectEnabled; | ||
_restitution = restitution ?? _restitution; | ||
} | ||
|
||
// source https://chrishecker.com/images/e/e7/Gdmphys3.pdf | ||
// Applying Impulse | ||
@override | ||
Vector2 getVelocityReflection( | ||
PositionComponent other, | ||
CollisionData data, | ||
) { | ||
if (_bouncingObjectEnabled) { | ||
Vector2 otherVelocity = | ||
(other is Movement) ? other.velocity : Vector2.zero(); | ||
Vector2 relativeVelocity = otherVelocity - velocity; | ||
|
||
if (relativeVelocity.dot(data.normal) > 0) { | ||
return super.getVelocityReflection(other, data); | ||
} | ||
|
||
double bRestitution = | ||
(other is ElasticCollision) ? other._restitution : _restitution; | ||
|
||
double e = min(_restitution, bRestitution); | ||
|
||
double j = -(1 + e) * relativeVelocity.dot(data.normal); | ||
|
||
double mass = (this is HandleForces) ? (this as HandleForces).mass : 1; | ||
double massB = (other is HandleForces) ? (other).mass : 1; | ||
j /= mass + massB; | ||
|
||
Vector2 impulse = data.normal * j; | ||
return impulse; | ||
} | ||
return super.getVelocityReflection(other, data); | ||
} | ||
} |
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
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
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
Oops, something went wrong.