Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement generic integrators for the physics world. #40

Open
dkushner opened this issue Dec 16, 2017 · 6 comments
Open

Implement generic integrators for the physics world. #40

dkushner opened this issue Dec 16, 2017 · 6 comments

Comments

@dkushner
Copy link
Contributor

dkushner commented Dec 16, 2017

As you mentioned on the Gitter, I think working towards a generic integrator implementation would be an excellent step towards getting this wonderful project production ready. As far as I can tell (and that's not terribly far considering I've only just started to get a handle on the code base), all of the important pieces seem to be in place.

What design approach were you thinking about for this feature and does this approach sound reasonable? If I understand correctly, the current dependency tree for the systems in order of actual execution looks something like:

SpatialSortSystem -> CollisionSystem -> SolverSystem

Where the collision system relies on the spatial sort being performed to make the BVT query more efficient and the solver system relies on the contact events published by the collision system. Furthermore, the solver system appears to be doing the actual force integration as well as the contact resolution. Is the idea to make the actual integration strategy pluggable by the end user or to simply improve the logic that is already present?

At the very least, it would certainly pay to implement island/sleep detection to be able to prune out inactive bodies and more efficiently parallelize integration. Should also consider supporting linear and angular dampening.

Possible implementations for the integrators include:

  • Symplectic Euler
  • RK4
  • Verlet
@Rhuagh
Copy link
Collaborator

Rhuagh commented Dec 17, 2017

The idea is to separate collision detection and integration so end users can mix and match any way they want.

@Rhuagh
Copy link
Collaborator

Rhuagh commented Dec 17, 2017

I want to separate the solver for the current frame (that do contact resolution and update the actual position/orientation of the bodies), and for the next frame (which is basically just setting up NextFrame so collision detection can be run). The idea is to be able to do next frame calculation and collision detection in parallel with rendering.

@Rhuagh
Copy link
Collaborator

Rhuagh commented Dec 17, 2017

And the spatial sorting etc should be optional, the basic collision system can be used for simpler games that don't need rays etc.

@Rhuagh
Copy link
Collaborator

Rhuagh commented Dec 17, 2017

Check the rb PR if you haven't, some things are already in there

@dkushner
Copy link
Contributor Author

I'm going to take some notes on the current integrator implementation here for both visibility and to confirm with @Rhuagh whether or not I am completely off-base. Referring to the ImpulseSolverSystem implementation, it appears that the current simulation loop takes the following form:

  1. Re-sort DBVT for current step via SpatialSortingSystem.
  2. Perform collision detection via SpatialCollisionSystem and report collision events and manifolds through the CollisionEvent queue.
  3. Resolve pending contacts by applying corrected positions and velocities to the next_frame positions and velocities of all collided bodies (in ImpulseSolverSystem).
  4. Update the current frame positions and velocities to the next_frame positions and velocities for all bodies (in ImpulseSolverSystem).
  5. Perform forward integration on current frame velocities and positions to determine prospective next_frame velocities and positions for all bodies (in ImpulseSolverSystem).

I've not had much experience breaking down a physics engine for an ECS of this type, but perhaps we can consider moving to a sequential impulse/constraint based solution rather than explicit contact resolution?

@Rhuagh
Copy link
Collaborator

Rhuagh commented Dec 18, 2017

That's the plan yes, but I have no experience of that and information on the Internet is scant, so I wanted to do a simple stupid version first, mostly to learn the basics.

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

No branches or pull requests

2 participants