box2djsの作法 その4
概要
box2djsの作法、調べてみた。
ニュートンの揺り篭、box2djsで無理、matterでやってみた。
写真
サンプルコード
var Engine = Matter.Engine,
Render = Matter.Render,
Runner = Matter.Runner,
Body = Matter.Body,
Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World;
var engine = Engine.create(),
world = engine.world;
var render = Render.create({
element: document.body,
engine: engine,
options: {
width: 600,
height: 400,
showVelocity: true
}
});
Render.run(render);
var runner = Runner.create();
Runner.run(runner, engine);
var cradle = Composites.newtonsCradle(280, 100, 3, 30, 200);
World.add(world, cradle);
Body.translate(cradle.bodies[0], {
x: -180,
y: -100
});
var mouse = Mouse.create(render.canvas),
mouseConstraint = MouseConstraint.create(engine, {
mouse: mouse,
constraint: {
stiffness: 0.2,
render: {
visible: false
}
}
});
World.add(world, mouseConstraint);
render.mouse = mouse;
Render.lookAt(render, {
min: {
x: 0,
y: 50
},
max: {
x: 800,
y: 600
}
});
成果物
var Engine = Matter.Engine,
Render = Matter.Render,
Runner = Matter.Runner,
Body = Matter.Body,
Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World;
var engine = Engine.create(),
world = engine.world;
var render = Render.create({
element: document.body,
engine: engine,
options: {
width: 600,
height: 400,
showVelocity: true
}
});
Render.run(render);
var runner = Runner.create();
Runner.run(runner, engine);
var cradle = Composites.newtonsCradle(280, 100, 3, 30, 200);
World.add(world, cradle);
Body.translate(cradle.bodies[0], {
x: -180,
y: -100
});
var mouse = Mouse.create(render.canvas),
mouseConstraint = MouseConstraint.create(engine, {
mouse: mouse,
constraint: {
stiffness: 0.2,
render: {
visible: false
}
}
});
World.add(world, mouseConstraint);
render.mouse = mouse;
Render.lookAt(render, {
min: {
x: 0,
y: 50
},
max: {
x: 800,
y: 600
}
});
以上。
Author And Source
この問題について(box2djsの作法 その4), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/b70c350989bfe7bab3a0著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .