追記(20111101): この記事のままだと姿勢(回転)の値がとれていません.姿勢を反映した版( Box2DJS_Demo_Stack_With_Rotate.qtz
)をこちらからdownloadしていただきコードを確認してください.
結果
Video streaming by Ustream
Box2DJS - Physics Engine for JavaScript
Custom Javascriptの中身
//import /Users/work/Desktop/box2d-js_0.1.0/lib/prototype-1.6.0.2.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/common/b2Settings.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/common/math/b2Vec2.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/common/math/b2Mat22.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/common/math/b2Math.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2AABB.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2Bound.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2BoundValues.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2Pair.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2PairCallback.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2BufferedPair.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2PairManager.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2BroadPhase.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2Collision.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/Features.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2ContactID.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2ContactPoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2Distance.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2Manifold.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2OBB.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/b2Proxy.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/ClipVertex.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2Shape.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2ShapeDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2BoxDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2CircleDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2CircleShape.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2MassData.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2PolyDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/collision/shapes/b2PolyShape.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2Body.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2BodyDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2CollisionFilter.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2Island.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2TimeStep.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2ContactNode.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2Contact.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2ContactConstraint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2ContactConstraintPoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2ContactRegister.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2ContactSolver.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2CircleContact.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2Conservative.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2NullContact.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2PolyAndCircleContact.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/contacts/b2PolyContact.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2ContactManager.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2World.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/b2WorldListener.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2JointNode.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2Joint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2JointDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2DistanceJoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2DistanceJointDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2Jacobian.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2GearJoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2GearJointDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2MouseJoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2MouseJointDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2PrismaticJoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2PrismaticJointDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2PulleyJoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2PulleyJointDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2RevoluteJoint.js
//import /Users/work/Desktop/box2d-js_0.1.0/js/box2d/dynamics/joints/b2RevoluteJointDef.js
//import /Users/work/Desktop/box2d-js_0.1.0/demos/demo_base.js
//import /Users/work/Desktop/box2d-js_0.1.0/demos/stack.js
//output QCPortTypeStructure posYs
//output QCPortTypeStructure posXs
//input QCPortTypeNumber foo
//input QCPortTypeBoolean init
//output QCPortTypeNumber dummy
var world = createWorld();
demos.InitWorlds[0](world);
function main(foo, init) {
if (init) {
world = createWorld();
demos.InitWorlds[0](world);
}
world.Step(1.0/60, 1);
var aryX= new Array();
var aryY= new Array();
for (var b = world.m_bodyList; b; b = b.m_next) {
for (var s = b.GetShapeList(); s != null; s = s.GetNext()) {
var pos= s.m_position;
aryX.push(pos.x);
aryY.push(pos.y);
}
}
var ret= new Object();
ret.posXs= aryX;
ret.posYs= aryY;
ret.dummy= foo;
return ret;
}
QC
描画部
fooはCustom JavaScriptを動かし続けるため(時刻で処理するパッチにしてないので).
CountはposXs等のCountで良いのだがDemoのデータに動かない要素が入っていたのでそのあたりを使わないため.
描画部(Iteratorの中)
割り算はスケール合わせ用
Box2DJS: Box2DJS - Physics Engine for JavaScript
Custom Javascript Patch: Custom Javascript Patch - quartz composerのパッチとか
0 件のコメント:
コメントを投稿