Giter Club home page Giter Club logo

box's Introduction

Box - Simple Physics

Box is a simple 2D physics engine written in JavaScript. It's primary focus is to be used in very simple games where only basic collisions features are needed, although it will probably get extend with advanced features in the future.

Highlights

  • Low memory footprint with no objects being created at runtime
  • Simple structure with commented code that's easy to grasp
  • Provides a simple and direct way to access contact point information
  • Runs in strict mode with sealed internal objects

Current Features

  • AABB and Circle shapes
  • Contact point information
  • Angular/Velocity
  • Static and Dynamic Friction
  • Comes with a 2D Vector class

Building / Including

You can either use the pre-built version directly from the lib folder or do a custom build:

$ npm install .
$ grunt

Documentation

Auto generated API documentation is available here.

Upcoming Features

  • Finalized public API
  • Collision groups and layers
  • OBB and Polygon shapes
  • Additional contact point information
  • Speed ups for huge scenes by applying spacial partioning

Tutorial

Setting up your World

The constant force applied to all objects is called gravity and is defined as a Box.Vec2.

var gravity = new Box.Vec2(0, 50); 

The resolution of the simulation is determined by 2 values. The first one is the number of steps each call to World.update(dt) will perform. A step is basically a full iteration over all objects and contacts. The dt delta time will be split by the number of steps defined.

var steps = 10;

For example dt of 20ms with 5 steps will advance the simulation by 4ms on each step.

The second value that's responsible for the resolution is the number of iterations. If two bodies overlap, the will get separated by the engine. Now as one can already imagine, this might lead to new overlaps with other bodies. An increased number of iterations will therefore give more precise results and less visual overlap.

var iterations = 10;

Now you can create your Box.World which will simply be empty and resting at first.

var world = new Box.World(gravity, steps, iterations);

Adding bodies

Coming soon.

Updating your world

Coming soon.

Rendering bodies

Coming soon.

Dealing with contacts

Coming soon.

License

Box is licenses under MIT.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.