Coder Social home page Coder Social logo

staunsholm / cannon.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from schteppe/cannon.js

0.0 2.0 1.0 2.63 MB

A lightweight 3D physics engine written in JavaScript.

Home Page: http://schteppe.github.com/cannon.js

License: MIT License

JavaScript 99.45% Python 0.55%

cannon.js's Introduction

cannon.js

Lightweight 3D physics for the web

Inspired by three.js and ammo.js, and driven by the fact that the web lacks a physics engine, here comes cannon.js.

Demos - Documentation - Rendering hints - NPM package

Usage

Download the library and include it in your html. Alternatively, build the library yourself (see Makefile).

<script src="cannon.js"></script>

The code below creates a sphere on a plane, steps the simulation, and prints the sphere simulation to the console.

// Setup our world
var world = new CANNON.World();
world.gravity.set(0,0,-9.82);
world.broadphase = new CANNON.NaiveBroadphase();
    
// Create a sphere
var mass = 5, radius = 1;
var sphereShape = new CANNON.Sphere(radius);
var sphereBody = new CANNON.RigidBody(mass,sphereShape);
sphereBody.position.set(0,0,10);
world.add(sphereBody);
    
// Create a plane
var normal = new CANNON.Vec3(0,0,1);
var groundShape = new CANNON.Plane(normal);
var groundBody = new CANNON.RigidBody(0,groundShape);
world.add(groundBody);
    
// Step the simulation
setInterval(function(){
  world.step(1.0/60.0);
  console.log("Sphere z position: " + sphereBody.position.z);
}, 1000.0/60.0);

If you want to know how to use cannon.js with a rendering engine, for example Three.js, see the Examples.

Change log

0.4.3

  • World now dispatches "preStep" and "postStep" events.
  • Introduced Body and Particle. New inheritance: Body -> Particle -> RigidBody.
  • Added Quaternion.toAxisAngle()
  • Added Ray. Basic hit testing for ConvexPolyhedra.
  • RigidBody now dispatches the following events: "collide", "sleep", "sleepy", "wakeup"
  • Added Solver.setSpookParams(k,d) and removed SPOOK param things from World.
  • Sleep functionality for RigidBody

0.4.2 2012-08-06

  • Code seem stable enough to start a change log.

Todo

Ideas and todo's for developers. The todo's are marked with @todo in the code.

  • Collision/contacts between convexhulls and sphere
  • Contact reduction
  • Improved collision detection - spatial hashing, octrees or similar (Continous?)
  • Figure out good Solver base class API - make current Solver to a subclass
  • Better class structure for Constraints, Jacobian entries etc
  • ParallelSolver that uses Web Workers - splits system into independent parts and solves them in parallel - see http://www.html5rocks.com/en/tutorials/workers/basics/
  • Caching of bounding sphere radius
  • Shapes (based on ConvexHull is enough to begin with): Cone, cylinder
  • First-contact impulse forces

cannon.js's People

Contributors

schteppe avatar timrwood avatar chrisforbes avatar mrdoob avatar onionhammer avatar

Watchers

Mikkel Staunsholm avatar James Cloos avatar

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.