Improved contact types #616
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
A lot of Avian's current contact types store some redundant data, aren't properly optimized, and aren't explicit enough about what they represent.
This PR is a clean-up pass to make the types a bit smaller and clearer.
Solution
Contactstotal_normal_impulseproperty withtotal_normal_impulse,total_normal_impulse_magnitude, andmax_normal_impulsehelperstotal_normal_forcehelpertotal_tangent_impulseproperty andtotal_friction_forcehelperContactManifoldContactManifold::contactstoContactManifold::pointsArrayVecwith a capacity of 2 instead of aVecto store 2DContactManifoldpoints directly on the stacknormal1andnormal2with a single world-spacenormaltotal_normal_impulseandmax_normal_impulsehelpersContactDataContactDatatoContactPoint(represents a point in a contact manifold)ManifoldPointlike in Box2D; not sure which one is betterpoint1andpoint2tolocal_point1andlocal_point2for explicitnessnormal1andnormal2fromContactPoint, since the normal is already stored in theContactManifoldOther
Migration Guide
There have been several changes to Avian's contact types to make them more optimized and clearer.
Contactstotal_normal_impulseproperty has been replaced with atotal_normal_impulsehelper method.total_normal_forcehelper has been deprecated. Instead, just divide the impulse by the substep timestep.total_tangent_impulseproperty andtotal_friction_forcehelper have been removed for being inaccurate/misleading. The tangent impulse magnitudes of each individual point can still be accessed.ContactManifoldContactManifold::contactshas been renamed toContactManifold::points.normal1andnormal2have been replaced with a single world-spacenormal, pointing from the first shape to the second.ContactDataContactDatahas been renamed toContactPoint, since it specifically represents a point in a contact manifold, not general contact data.point1andpoint2have been renamed tolocal_point1andlocal_point2for explicitnessnormal1andnormal2have been removed, since the normal is already stored in theContactManifold.