From ac67ef8e5ce5554ac4fed480069a4c3b7ae09a1b Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 28 Jun 2017 00:21:17 +0100 Subject: [PATCH] fixed various constraints in examples --- examples/chains.js | 4 ++-- examples/doublePendulum.js | 14 ++++++++------ src/factory/Composites.js | 12 +++--------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/chains.js b/examples/chains.js index c019b9d7..91b08b2e 100644 --- a/examples/chains.js +++ b/examples/chains.js @@ -43,7 +43,7 @@ Example.chains = function() { return Bodies.rectangle(x, y, 50, 20, { collisionFilter: { group: group } }); }); - Composites.chain(ropeA, 0.5, 0, -0.5, 0, { stiffness: 0.8, length: 2 }); + Composites.chain(ropeA, 0.5, 0, -0.5, 0, { stiffness: 0.8, length: 2, render: { type: 'line' } }); Composite.add(ropeA, Constraint.create({ bodyB: ropeA.bodies[0], pointB: { x: -25, y: 0 }, @@ -57,7 +57,7 @@ Example.chains = function() { return Bodies.circle(x, y, 20, { collisionFilter: { group: group } }); }); - Composites.chain(ropeB, 0.5, 0, -0.5, 0, { stiffness: 0.8, length: 2 }); + Composites.chain(ropeB, 0.5, 0, -0.5, 0, { stiffness: 0.8, length: 2, render: { type: 'line' } }); Composite.add(ropeB, Constraint.create({ bodyB: ropeB.bodies[0], pointB: { x: -20, y: 0 }, diff --git a/examples/doublePendulum.js b/examples/doublePendulum.js index bef69584..70dec159 100644 --- a/examples/doublePendulum.js +++ b/examples/doublePendulum.js @@ -42,7 +42,7 @@ Example.doublePendulum = function() { length = 200, width = 25; - var pendulum = Composites.stack(350, 160, 2, 1, 0, 0, function(x, y) { + var pendulum = Composites.stack(350, 160, 2, 1, -20, 0, function(x, y) { return Bodies.rectangle(x, y, length, width, { collisionFilter: { group: group }, frictionAir: 0, @@ -56,24 +56,26 @@ Example.doublePendulum = function() { pendulum.bodies[0].render.strokeStyle = '#4a485b'; pendulum.bodies[1].render.strokeStyle = '#4a485b'; + + world.gravity.scale = 0.002; - Composites.chain(pendulum, 0.5, 0, -0.5, 0, { + Composites.chain(pendulum, 0.45, 0, -0.45, 0, { stiffness: 1, length: 0, angularStiffness: 0.7, render: { - lineWidth: 0 + strokeStyle: '#4a485b' } }); Composite.add(pendulum, Constraint.create({ bodyB: pendulum.bodies[0], - pointB: { x: -length * 0.5, y: 0 }, - pointA: { x: pendulum.bodies[0].position.x - length * 0.5, y: pendulum.bodies[0].position.y }, + pointB: { x: -length * 0.42, y: 0 }, + pointA: { x: pendulum.bodies[0].position.x - length * 0.42, y: pendulum.bodies[0].position.y }, stiffness: 1, length: 0, render: { - lineWidth: 0 + strokeStyle: '#4a485b' } })); diff --git a/src/factory/Composites.js b/src/factory/Composites.js index 7ef9f3f4..3c9adf76 100644 --- a/src/factory/Composites.js +++ b/src/factory/Composites.js @@ -274,10 +274,7 @@ var Bodies = require('./Bodies'); pointB: { x: wheelAOffset, y: wheelYOffset }, bodyA: wheelA, stiffness: 1, - length: 0, - render: { - lineWidth: 0 - } + length: 0 }); var axelB = Constraint.create({ @@ -285,10 +282,7 @@ var Bodies = require('./Bodies'); pointB: { x: wheelBOffset, y: wheelYOffset }, bodyA: wheelB, stiffness: 1, - length: 0, - render: { - lineWidth: 0 - } + length: 0 }); Composite.addBody(car, body); @@ -317,7 +311,7 @@ var Bodies = require('./Bodies'); */ Composites.softBody = function(xx, yy, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) { particleOptions = Common.extend({ inertia: Infinity }, particleOptions); - constraintOptions = Common.extend({ stiffness: 0.2 }, constraintOptions); + constraintOptions = Common.extend({ stiffness: 0.2, render: { type: 'line', anchors: false } }, constraintOptions); var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y) { return Bodies.circle(x, y, particleRadius, particleOptions);