rescaling superposition constraints on reseting mapitem scale

This commit is contained in:
Bachir Soussi Chiadmi 2024-02-05 16:04:58 +01:00
parent 609964b358
commit 7984c9c7d0

View File

@ -2150,36 +2150,8 @@ export default {
// Matter.Body.scale(this.body, obj.s, obj.s)
this.paper_main_object.scale(obj.s);
// update superposition constraints points poisitions
if (this.concernement.superposition_constraints_id
&& this.concernement.superposition_constraints_id[this.id]
&& this.concernement.superposition_constraints_id[this.id].length)
{
// get all the constraints of the world
let all_constrains = Matter.Composite.allConstraints(this.matterEngine.world);
// loop through all constraint ids recorded in the concernement
// get only the constraint of this concernement mapitem
for(let constraint_id of this.concernement.superposition_constraints_id[this.id]) {
// get the right constraint object from matter
let constraint;
for (const c of all_constrains) {
if (c.id === constraint_id) {
constraint = c;
break;
}
}
if (constraint) {
// tween the constraint point
let ab = this.cid === constraint.concernementA.id ? 'A' : 'B';
let point = constraint[`point${ab}`];
// revert to the original point
let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
// newpoint from original point
let newpoint = Matter.Vector.create(oripoint.x * obj.s, oripoint.y * obj.s)
constraint[`point${ab}`] = newpoint;
}
}
}
// update superposition constraints points positions
this.resetSuperpositionsConstraintsScaling(obj.s);
// record new scale
this.prev_scale = this.scale;
@ -2298,6 +2270,37 @@ export default {
}
this.tween.easing(Tween.Easing.Quadratic.InOut).start();
},
resetSuperpositionsConstraintsScaling(s){
if (this.concernement.superposition_constraints_id
&& this.concernement.superposition_constraints_id[this.id]
&& this.concernement.superposition_constraints_id[this.id].length)
{
// get all the constraints of the world
let all_constrains = Matter.Composite.allConstraints(this.matterEngine.world);
// loop through all constraint ids recorded in the concernement
// get only the constraint of this concernement mapitem
for(let constraint_id of this.concernement.superposition_constraints_id[this.id]) {
// get the right constraint object from matter
let constraint;
for (const c of all_constrains) {
if (c.id === constraint_id) {
constraint = c;
break;
}
}
if (constraint) {
// tween the constraint point
let ab = this.cid === constraint.concernementA.id ? 'A' : 'B';
let point = constraint[`point${ab}`];
// revert to the original point
let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
// newpoint from original point
let newpoint = Matter.Vector.create(oripoint.x * s, oripoint.y * s)
constraint[`point${ab}`] = newpoint;
}
}
}
},
async resetMapItemPosition(){
await nextTick();
console.log('resetMapItemPosition');
@ -2317,9 +2320,10 @@ export default {
this.paper_main_object.scale(1 / this.scale);
// then scale again to new scale
this.paper_main_object.scale(s);
this.prev_scale = this.scale = s;
// TODO handle superposition scaling
this.resetSuperpositionsConstraintsScaling(s);
// record the new scale
this.prev_scale = this.scale = s;
},
// ENGINE UPDATE
onBeforeEngineUpdate (event) {