Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

feat: pass physics values to onFrame callback #136

Merged
merged 3 commits into from
Apr 8, 2021

Conversation

parkerziegler
Copy link
Contributor

@parkerziegler parkerziegler commented Apr 2, 2021

This PR fulfills a feature request from @littlemilkstudio.

The onFrame callback now receives the position, velocity, and acceleration values in addition to the progress value. For useGravity2D, which never received a progress value because the orbit animation is infinite by nature, onFrame also receives these vectors.

This should make accessing these physics values for us in Three.js / r3f fairly trivial. The API would look something like the following for useGravity2D:

useGravity2D({
  config: {
    // Physics configuration values
  },
  onFrame: ({ position, velocity, acceleration }) => {
    // Execute some code with the raw physics values, all of which are tuples representing vectors.
  }
});

For the other hooks, access will be slightly different. progress is the first argument passed to onFrame. I didn't want to group progress with the physics values to prevent a breaking API change.

useFriction({
  config: {
    // Physics configuration values
  },
  onFrame: (progress, { position, velocity, acceleration }) => {
    // Execute some code with the raw physics values, all of which are two tuples representing vectors.
  }
});

Hopefully this can be helpful for our Three.js shot! Let me know if there are some missing additional values that would be helpful here.

@parkerziegler
Copy link
Contributor Author

FYI @littlemilkstudio I know you're on the road so merging this as is!

@parkerziegler parkerziegler merged commit ac78d11 into saturn Apr 8, 2021
@parkerziegler parkerziegler deleted the feat/pass-physics-values-to-onFrame branch April 8, 2021 16:44
@maxyinger
Copy link

Looks great! thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants