vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
875 B

  1. /**
  2. * Created by Alex on 2/23/2015.
  3. */
  4. var BarnesHut = require("./compontents/BarnesHutSolver")
  5. var SpringSolver = require("./compontents/SpringSolver")
  6. var CentralGravitySolver = require("./compontents/CentralGravitySolver")
  7. function PhysicsEngine(body, options) {
  8. this.body = body;
  9. this.nodesSolver = new BarnesHut(body, options);
  10. this.edgesSolver = new SpringSolver(body, options);
  11. this.gravitySolver = new CentralGravitySolver(body, options);
  12. }
  13. PhysicsEngine.prototype.calculateField = function () {
  14. this.nodesSolver.solve();
  15. };
  16. PhysicsEngine.prototype.calculateSprings = function () {
  17. this.edgesSolver.solve();
  18. };
  19. PhysicsEngine.prototype.calculateCentralGravity = function () {
  20. this.gravitySolver.solve();
  21. };
  22. PhysicsEngine.prototype.calculate = function () {
  23. this.calculateCentralGravity();
  24. this.calculateField();
  25. this.calculateSprings();
  26. };