Skip to content

Verlet solver physics engine based in Rust and Macroquad.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

GhtGhoster/mq-verlet

Repository files navigation

Verlet solver

A Verlet solver based on this and this video, test it here. The purpose of this project is to familiarize myself with simple physics simulations, shaders, and using egui and macroquad crates.

Presets are made with a fullscreen or near fullscreen window at FHD resolution in mind.

This code is undocumented as it was an exploratory project with me having very little to no idea of what I was doing as I was doing it. Even so, the code should be structured relatively nicely, hopefully enough so that it's readable and undestandable without excessive headaches.

More interesting crates to look out for in the future:

Be advised that egui-miniquad's dependency quad-url relies on an old, vulnerable version of webbrowser and neither me nor GitHub's Dependabot can fix it. This isn't actually used in code anywhere but be careful.

Limits and issues:

Approximate object limits before FPS drops (mileage may vary):

  • Naive (every object against every other object): 1600
  • Cellularized (matrix/cell-based optimization): 3300
  • Optimized heap usage: 5000

Few glaring issue of the simulation:

  • The optimization cell block size has to be quite a bit larger than the object given a homogenous obj size due to "popcorn effect"
  • The simulation still freaks out at large quantities of objects moving
  • Not running quite as fast as I'd hoped
  • Only supports circles
  • Relying on shaders and passing in uniforms to render anything but monochrome circles is slow
  • When running this natively without target SFPS enabled, at very high frame-ratesthe simulation freaks out. (Pressumably because of f32 rounding error)

Plans and features that didn't make it

  • resistance
  • making wasm work for android
  • time warp thingy, including complete stop (adjust frame_time before passing to update)
  • make everything f64 (or generic?) and compare performance
  • spawned from this: 3d version
  • the fire is about as good as I can get it, maybe try removing temperature based on how much the object traveled since last frame
  • learn how to use shaders more effectively (water shader in the book, passing in whole textures etc) - screen reading shaders
  • auto shaking (with looping over stuff and bpm/settable delay per shake)
  • mixer (cw or ccw shake timed accordingly)
  • if last sim frame time < target frame time: disable target frame time

Instructions and dependencies:

All scripts listed below are compatible with default Windows installation of PowerShell (v6+ not required) as well as bash for Linux (scripts are polyglot)

(The bash portion of the polyglot scripts is untested, use with caution and please report back with results or a pull request)

(This is only necessary to run once after a repository was first created with the mq-wbg-template template.)

This script installs wasm-bindgen-cli (version 0.2.84), basic-http-server and adds wasm32-unknown-unknown to possible compilation targets. Note that this version of wasm-bindgen-cli is required for the pipeline defined in this repository.

(This is only necessary to run once on a single computer as the effects of this script are global.)

This script builds the project for the wasm32-unknown-unknown target in --release mode, generates WASM bindings, and patches the generated JavaScript file. It also moves the relevant files to their appropriate directories in preparation for running the project on a local server or on GitHub Pages.

This script hosts the built project on a local basic-http-server server and opens a browser at its location.

(One does not need to restart the server after building the project again, reloading the webpage in the browser is sufficent.)

(This is necessary over just opening the index.html file in your browser so that the required resources load properly.)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Verlet solver physics engine based in Rust and Macroquad.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks