Skip to content

Commit

Permalink
fixed various constraints in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jun 27, 2017
1 parent 837c43b commit ac67ef8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down
14 changes: 8 additions & 6 deletions examples/doublePendulum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
}
}));

Expand Down
12 changes: 3 additions & 9 deletions src/factory/Composites.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,15 @@ var Bodies = require('./Bodies');
pointB: { x: wheelAOffset, y: wheelYOffset },
bodyA: wheelA,
stiffness: 1,
length: 0,
render: {
lineWidth: 0
}
length: 0
});

var axelB = Constraint.create({
bodyB: body,
pointB: { x: wheelBOffset, y: wheelYOffset },
bodyA: wheelB,
stiffness: 1,
length: 0,
render: {
lineWidth: 0
}
length: 0
});

Composite.addBody(car, body);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ac67ef8

Please sign in to comment.