Box2dnode
A port of the box2djs library into a nodejs module
Install / Use
/learn @jadell/Box2dnodeREADME
box2dnode
@author Josh Adell josh.adell@gmail.com
A port of the box2djs library into a node module.
Install
Two options here:
-
Grab the code from its http://github.com/jadell/box2dnode
-
Use npm:
npm install box2d
Option 2 is the recommended way.
Code example
Here is the box2d "Hello World" program from http://www.box2d.org/ written for node:
var sys = require("sys"),
b2d = require("./box2dnode");
// Define world
var worldAABB = new b2d.b2AABB();
worldAABB.lowerBound.Set(-100.0, -100.0);
worldAABB.upperBound.Set(100.0, 100.0);
var gravity = new b2d.b2Vec2(0.0, -10.0);
var doSleep = true;
var world = new b2d.b2World(worldAABB, gravity, doSleep);
// Ground Box
var groundBodyDef = new b2d.b2BodyDef();
groundBodyDef.position.Set(0.0, -10.0);
var groundBody = world.CreateBody(groundBodyDef);
var groundShapeDef = new b2d.b2PolygonDef();
groundShapeDef.SetAsBox(50.0, 10.0);
groundBody.CreateShape(groundShapeDef);
// Dynamic Body
var bodyDef = new b2d.b2BodyDef();
bodyDef.position.Set(0.0, 4.0);
var body = world.CreateBody(bodyDef);
var shapeDef = new b2d.b2PolygonDef();
shapeDef.SetAsBox(1.0, 1.0);
shapeDef.density = 1.0;
shapeDef.friction = 0.3;
body.CreateShape(shapeDef);
body.SetMassFromShapes();
// Run Simulation!
var timeStep = 1.0 / 60.0;
var iterations = 10;
for (var i=0; i < 60; i++) {
world.Step(timeStep, iterations);
var position = body.GetPosition();
var angle = body.GetAngle();
sys.puts(i+": <"+position.x+", "+position.y+"> @"+angle);
}
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
