scaling superpositions constraints on concernement opening

This commit is contained in:
2023-09-04 14:36:14 +02:00
parent a6dc15d646
commit a418682a72
4 changed files with 112 additions and 54 deletions

View File

@@ -107,6 +107,8 @@ export default {
this.initPaperObjects()
// }
}
this.setConcernementMapItem(this.id, this);
},
// mounted() {
// console.log(`ConcernementsMapItem ${this.concernement.id} mounted`, this.canvasMap.canvas);
@@ -130,7 +132,7 @@ export default {
// console.log('mapItem watch is_opened', n, this.is_opened);
if(n){ // opened
this.openClose(true);
}else{ // closed
}else if(o) { // closed if was opened
this.openClose(false);
}
},
@@ -180,7 +182,8 @@ export default {
},
methods: {
...mapActions(CommonStore,['setHoverElmt']),
...mapActions(ConcernementsStore,['openCloseConcernements',
...mapActions(ConcernementsStore,['setConcernementMapItem',
'openCloseConcernements',
'hideShowConcernement',
'setBesoinPaperId',
'setOpenedDoleanceField',
@@ -369,7 +372,7 @@ export default {
// INFO https://github.com/liabru/matter-attractors/issues/8
// INFO https://github.com/liabru/matter-attractors/blob/master/index.js
// INFO https://github.com/liabru/matter-attractors/blob/master/build/matter-attractors.js#L180
// MatterAttractors.Attractors.gravityConstant = -20;
MatterAttractors.Attractors.gravityConstant = -20;
// Create parts of the body : main big circle & entities
// INFO map a range of numbers to another range of numbers https://stackoverflow.com/a/46462321
@@ -400,37 +403,37 @@ export default {
collisionFilter: {
group: -1
},
// plugin: {
// attractors: [
// // // there is a built in helper function for Newtonian gravity!
// // // you can find out how it works in index.js
// MatterAttractors.Attractors.gravity
plugin: {
attractors: [
// // there is a built in helper function for Newtonian gravity!
// // you can find out how it works in index.js
MatterAttractors.Attractors.gravity
// // function(bodyA, bodyB) {
// // var force = {
// // x: (bodyA.position.x - bodyB.position.x) * 1e-6,
// // y: (bodyA.position.y - bodyB.position.y) * 1e-6
// // }
// // // apply force to both bodies
// // Matter.Body.applyForce(bodyA, bodyA.position, force);
// // Matter.Body.applyForce(bodyB, bodyB.position, Matter.Vector.neg(force));
// // }
// function(bodyA, bodyB) {
// var force = {
// x: (bodyA.position.x - bodyB.position.x) * 1e-6,
// y: (bodyA.position.y - bodyB.position.y) * 1e-6
// }
// // apply force to both bodies
// Matter.Body.applyForce(bodyA, bodyA.position, force);
// Matter.Body.applyForce(bodyB, bodyB.position, Matter.Vector.neg(force));
// }
// // INFO https://github.com/liabru/matter-attractors/blob/master/build/matter-attractors.js#L192
// // function (bodyA, bodyB){
// // // use Newton's law of gravitation
// // var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
// // distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
// // normal = Matter.Vector.normalise(bToA),
// // magnitude = -MatterAttractors.Attractors.gravityConstant * (bodyA.mass * bodyB.mass / distanceSq),
// // force = Matter.Vector.mult(normal, magnitude);
// INFO https://github.com/liabru/matter-attractors/blob/master/build/matter-attractors.js#L192
// function (bodyA, bodyB){
// // use Newton's law of gravitation
// var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
// distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
// normal = Matter.Vector.normalise(bToA),
// magnitude = -MatterAttractors.Attractors.gravityConstant * (bodyA.mass * bodyB.mass / distanceSq),
// force = Matter.Vector.mult(normal, magnitude);
// // // to apply forces to both bodies
// // Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
// // Matter.Body.applyForce(bodyB, bodyB.position, force);
// // }
// ]
// }
// // to apply forces to both bodies
// Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
// Matter.Body.applyForce(bodyB, bodyB.position, force);
// }
]
}
});
Matter.Body.setPosition(this.body, this.pos);
@@ -1123,7 +1126,7 @@ export default {
if (!this.is_opened) {
this.paper_main_object.children.entites_superposes.visible = true; // if not opened and has_superpositions draw the entites_superposes points
} else {
this.paper_main_object.children.entites_superposes.visible = false;
this.paper_main_object.children.entites_superposes.visible = true;
}
} else {
this.paper_main_object.children.entites_superposes.visible = false;
@@ -1389,15 +1392,32 @@ export default {
Matter.Body.scale(this.body, obj.s, obj.s)
this.paper_main_object.scale(obj.s);
// update superposition constraints
if (Object.keys(this.concernement.superposition_constraints).length) {
// console.log('concernement superposition_constraints', this.concernement.superposition_constraints);
for(let constraint_id in this.concernement.superposition_constraints) {
let constraint = this.concernement.superposition_constraints[constraint_id];
// console.log('concernement mapitem constraint', constraint);
let ab = this.id === constraint.concernementA.id ? 'A' : 'B';
let point = constraint[`point${ab}`];
// console.log('point', point);
// revert to the original point
let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
let newpoint = Matter.Vector.create(oripoint.x * obj.s, oripoint.y * obj.s)
constraint[`point${ab}`] = newpoint;
}
}
// record new scale
this.prev_scale = this.scale;
this.scale = obj.s;
this.opacity = obj.o;
// console.log('tween update obj.s', obj.s);
this.pos = {x:obj.x, y:obj.y};
Matter.Body.setPosition(this.body, this.pos);
})
.onComplete((obj) => {
// console.log('tween complete obj.s', obj.s);
// record tween one last time
this.prev_scale = this.scale = obj.s;
this.opacity = obj.o;
@@ -1416,6 +1436,8 @@ export default {
});
Matter.Composite.add(this.matterEngine.world, [this.body, this.constraint]);
this.is_opening = false;
});
// recreate the matter engine event to get it a the end of the events stack
@@ -1446,6 +1468,22 @@ export default {
Matter.Body.scale(this.body, obj.s, obj.s)
this.paper_main_object.scale(obj.s);
// update superposition constraints
if (this.concernement.superposition_constraints && Object.keys(this.concernement.superposition_constraints).length) {
// console.log('concernement superposition_constraints', this.concernement.superposition_constraints);
for(let constraint_id in this.concernement.superposition_constraints) {
let constraint = this.concernement.superposition_constraints[constraint_id];
// console.log('concernement mapitem constraint', constraint);
let ab = this.id === constraint.concernementA.id ? 'A' : 'B';
let point = constraint[`point${ab}`];
// console.log('point', point);
// revert to the original point
let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
let newpoint = Matter.Vector.create(oripoint.x * obj.s, oripoint.y * obj.s)
constraint[`point${ab}`] = newpoint;
}
}
// record new scale
this.prev_scale = this.scale;
this.scale = obj.s;
@@ -1476,7 +1514,7 @@ export default {
}
if (this.opened_concernement) {
if (this.opened_concernement.id !== this.id) {
if (this.opened_concernement.id !== this.id && this.opened_concernement.superposed_concernements_id.indexOf(this.id) < 0) {
this.pushAside()
}
} else if (this.map_mode === 'proximite'