|
@@ -127,6 +127,8 @@ export default {
|
|
// this.setConcernementMapItem(this.cid, this);
|
|
// this.setConcernementMapItem(this.cid, this);
|
|
// this.setConcernementScale(this.cid, this.scale);
|
|
// this.setConcernementScale(this.cid, this.scale);
|
|
this.mapitem.scale = this.scale;
|
|
this.mapitem.scale = this.scale;
|
|
|
|
+
|
|
|
|
+ // window.addEventListener('resize', this.onWindowResize.bind(this));
|
|
},
|
|
},
|
|
// mounted() {
|
|
// mounted() {
|
|
// console.log(`ConcernementsMapItem ${this.concernement.id} mounted`, this.canvasMap.canvas);
|
|
// console.log(`ConcernementsMapItem ${this.concernement.id} mounted`, this.canvasMap.canvas);
|
|
@@ -255,6 +257,16 @@ export default {
|
|
// }
|
|
// }
|
|
},
|
|
},
|
|
deep: true
|
|
deep: true
|
|
|
|
+ },
|
|
|
|
+ // window as been resized
|
|
|
|
+ map_item_ray: {
|
|
|
|
+ handler (n, o) {
|
|
|
|
+ console.log(`map_item_ray updated o: ${o}, n: ${n}`);
|
|
|
|
+ this.ray = n;
|
|
|
|
+ this.updateMatterBodyRay();
|
|
|
|
+ this.updatePaperObjectSize(n,o);
|
|
|
|
+ },
|
|
|
|
+ deep: true
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
@@ -465,25 +477,19 @@ export default {
|
|
let entite_range = [3, 100];
|
|
let entite_range = [3, 100];
|
|
let ray_range = [this.ray*0.8,this.ray*1.2];
|
|
let ray_range = [this.ray*0.8,this.ray*1.2];
|
|
let ray = ray_range[0] + (this.entites.length - entite_range[0]) * (ray_range[1] - ray_range[0]) / (entite_range[1] - entite_range[0]);
|
|
let ray = ray_range[0] + (this.entites.length - entite_range[0]) * (ray_range[1] - ray_range[0]) / (entite_range[1] - entite_range[0]);
|
|
- this.body_parts = [
|
|
+ // this.body_parts = [
|
|
- Matter.Bodies.circle(0, 0, ray, {
|
|
+ // Matter.Bodies.circle(0, 0, ray)
|
|
- // item_type: 'concernement',
|
|
+ // ];
|
|
- // id: this.concernement.id,
|
|
|
|
- })
|
|
|
|
- ];
|
|
|
|
|
|
|
|
// INFO map a range of numbers to another range of numbers https://stackoverflow.com/a/46462321
|
|
// INFO map a range of numbers to another range of numbers https://stackoverflow.com/a/46462321
|
|
let mass_range = [5,15];
|
|
let mass_range = [5,15];
|
|
let mass = mass_range[0] + (this.entites.length - entite_range[0]) * (mass_range[1] - mass_range[0]) / (entite_range[1] - entite_range[0]);
|
|
let mass = mass_range[0] + (this.entites.length - entite_range[0]) * (mass_range[1] - mass_range[0]) / (entite_range[1] - entite_range[0]);
|
|
|
|
|
|
// create the body
|
|
// create the body
|
|
- this.body = Matter.Body.create({
|
|
+ this.body = Matter.Bodies.circle(0, 0, ray, {
|
|
- parts: this.body_parts,
|
|
|
|
item_type: 'concernement',
|
|
item_type: 'concernement',
|
|
id: this.id,
|
|
id: this.id,
|
|
frictionAir: 0,
|
|
frictionAir: 0,
|
|
- // mass: Math.pow(3, this.entites.length),
|
|
|
|
- // mass: 10,
|
|
|
|
mass: mass,
|
|
mass: mass,
|
|
restitution: 0.06,
|
|
restitution: 0.06,
|
|
collisionFilter: {
|
|
collisionFilter: {
|
|
@@ -520,7 +526,51 @@ export default {
|
|
// }
|
|
// }
|
|
]
|
|
]
|
|
}
|
|
}
|
|
- });
|
|
+ })
|
|
|
|
+ // this.body = Matter.Body.create({
|
|
|
|
+ // parts: this.body_parts,
|
|
|
|
+ // item_type: 'concernement',
|
|
|
|
+ // id: this.id,
|
|
|
|
+ // frictionAir: 0,
|
|
|
|
+ // // mass: Math.pow(3, this.entites.length),
|
|
|
|
+ // // mass: 10,
|
|
|
|
+ // mass: mass,
|
|
|
|
+ // restitution: 0.06,
|
|
|
|
+ // 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
|
|
|
|
+
|
|
|
|
+ // // 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);
|
|
|
|
+
|
|
|
|
+ // // // 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);
|
|
Matter.Body.setPosition(this.body, this.pos);
|
|
|
|
|
|
// add init velocity
|
|
// add init velocity
|
|
@@ -543,6 +593,17 @@ export default {
|
|
y: -delta + Math.random()*delta*2
|
|
y: -delta + Math.random()*delta*2
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ updateMatterBodyRay(){
|
|
|
|
+ console.log('updateMatterBodyRay',this.ray, this.body);
|
|
|
|
+ let entite_range = [3, 100];
|
|
|
|
+ let ray_range = [this.ray*0.8,this.ray*1.2];
|
|
|
|
+ let new_ray = ray_range[0] + (this.entites.length - entite_range[0]) * (ray_range[1] - ray_range[0]) / (entite_range[1] - entite_range[0]);
|
|
|
|
+ let old_ray = this.body.circleRadius;
|
|
|
|
+ let scale = new_ray/old_ray;
|
|
|
|
+ Matter.Body.scale(this.body, scale, scale);
|
|
|
|
+ // Matter.Body.set(this.body, 'circleRadius', ray);
|
|
|
|
+ console.log(`this.body circleRadius ${this.body.circleRadius}`);
|
|
|
|
+ },
|
|
// PAPER OBJECTS
|
|
// PAPER OBJECTS
|
|
initPaperObjects(){
|
|
initPaperObjects(){
|
|
|
|
|
|
@@ -579,9 +640,52 @@ export default {
|
|
// if (this.concernement.has_doleance) {
|
|
// if (this.concernement.has_doleance) {
|
|
// this.addNewPaperSymbolInstance('doleance_icon', false, 0.7);
|
|
// this.addNewPaperSymbolInstance('doleance_icon', false, 0.7);
|
|
// }
|
|
// }
|
|
-
|
|
+
|
|
|
|
+
|
|
this.initPaperEvents()
|
|
this.initPaperEvents()
|
|
},
|
|
},
|
|
|
|
+ async updatePaperObjectSize(n,o){
|
|
|
|
+ await nextTick();
|
|
|
|
+ // INFO we redraw the points with the new ray AND sacle the backgrounds ... would it be simplier to only resize the whole mapitem ???
|
|
|
|
+ // window has been resized
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // if open
|
|
|
|
+ if (this.is_open) {
|
|
|
|
+ // move to the new position
|
|
|
|
+ // INFO we need to change position first for the contours to be redraw in the right place
|
|
|
|
+ this.pos = this.paper_main_object.position = {
|
|
|
|
+ x: (this.canvas.width - this.cartouch_width) / 2,
|
|
|
|
+ y: this.canvas.height / 2
|
|
|
|
+ };
|
|
|
|
+ this.constraint.pointA = this.pos;
|
|
|
|
+ Matter.Body.setPosition(this.body, this.pos);
|
|
|
|
+
|
|
|
|
+ // reset the paper contents with paper symbols redrew by MapConcernements.vue
|
|
|
|
+ this.setPaperContents();
|
|
|
|
+
|
|
|
|
+ // scale
|
|
|
|
+ // let s = this.getOpeningAvailableScale();
|
|
|
|
+ // this.paper_main_object.scale(1 / this.scale);
|
|
|
|
+ // this.paper_main_object.scale(s);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // in any case
|
|
|
|
+ // delet the old contours
|
|
|
|
+ let clearables = ['contours'];
|
|
|
|
+ clearables.forEach(child_name => {
|
|
|
|
+ if (this.paper_main_object.children[child_name]) {
|
|
|
|
+ this.paper_main_object.children[child_name].remove();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // rebuild the contours with the new ray
|
|
|
|
+ this.parseEntityPointsValues()
|
|
|
|
+ this.sailentEntites = this.concernement.sailentEntites = this.getJarvisEnvelopeConvexeEntites(this.entites)
|
|
|
|
+ // redraw the contours
|
|
|
|
+ this.paper_main_object.addChild(this.setPaperContour());
|
|
|
|
+
|
|
|
|
+ },
|
|
/*
|
|
/*
|
|
* called by openClose() function
|
|
* called by openClose() function
|
|
*/
|
|
*/
|
|
@@ -650,7 +754,6 @@ export default {
|
|
addNewPaperSymbolInstance(name, back, scale){
|
|
addNewPaperSymbolInstance(name, back, scale){
|
|
let instance = new paper.SymbolItem(this.paper_symbol_definitions[name]); // , {x:0,y:0}
|
|
let instance = new paper.SymbolItem(this.paper_symbol_definitions[name]); // , {x:0,y:0}
|
|
instance.name = name;
|
|
instance.name = name;
|
|
- // instance.pivot = new paper.Point({x:0,y:0});
|
|
|
|
instance.position = this.pos;
|
|
instance.position = this.pos;
|
|
let s = scale ? this.scale * scale : this.scale;
|
|
let s = scale ? this.scale * scale : this.scale;
|
|
instance.scale(s);
|
|
instance.scale(s);
|
|
@@ -2003,6 +2106,16 @@ export default {
|
|
}, 100);
|
|
}, 100);
|
|
},
|
|
},
|
|
// OPEN / CLOSE (with tween)
|
|
// OPEN / CLOSE (with tween)
|
|
|
|
+ getOpeningAvailableScale(){
|
|
|
|
+// calcul opened size regarding window size and surounding contents
|
|
|
|
+ let header = document.querySelector('header#header');
|
|
|
|
+ let header_height = header.clientHeight;
|
|
|
|
+ let map_nav = document.querySelector('nav#map-nav');
|
|
|
|
+ let map_nav_height = map_nav.clientHeight;
|
|
|
|
+ let s_h = (this.canvas.height - header_height - map_nav_height) / (this.ray*2*1.15);
|
|
|
|
+ let s_w = (this.canvas.width - this.cartouch_width) / (this.ray*2*1.7);
|
|
|
|
+ return Math.min(s_h, s_w)
|
|
|
|
+ },
|
|
openClose(open) { // async
|
|
openClose(open) { // async
|
|
// await nextTick(); // not working
|
|
// await nextTick(); // not working
|
|
console.log(`ConcernementsMapItem ${this.id} openClose: ${open}`);
|
|
console.log(`ConcernementsMapItem ${this.id} openClose: ${open}`);
|
|
@@ -2015,14 +2128,7 @@ export default {
|
|
this.setPaperContents();
|
|
this.setPaperContents();
|
|
this.handlePaperVisibilityOnBeforeOpen();
|
|
this.handlePaperVisibilityOnBeforeOpen();
|
|
|
|
|
|
- // calcul opened size regarding window size and surounding contents
|
|
+ let s = this.getOpeningAvailableScale();
|
|
- let header = document.querySelector('header#header');
|
|
|
|
- let header_height = header.clientHeight;
|
|
|
|
- let map_nav = document.querySelector('nav#map-nav');
|
|
|
|
- let map_nav_height = map_nav.clientHeight;
|
|
|
|
- let s_h = (this.canvas.height - header_height - map_nav_height) / (this.ray*2*1.15);
|
|
|
|
- let s_w = (this.canvas.width - this.cartouch_width) / (this.ray*2*1.7);
|
|
|
|
- let s = Math.min(s_h, s_w)
|
|
|
|
|
|
|
|
// create once the opening tweening
|
|
// create once the opening tweening
|
|
this.tween = new Tween.Tween({s: this.scale, x: this.pos.x, y: this.pos.y, o: 0})
|
|
this.tween = new Tween.Tween({s: this.scale, x: this.pos.x, y: this.pos.y, o: 0})
|
|
@@ -2074,8 +2180,7 @@ export default {
|
|
|
|
|
|
// record new scale
|
|
// record new scale
|
|
this.prev_scale = this.scale;
|
|
this.prev_scale = this.scale;
|
|
- this.scale = obj.s;
|
|
+ this.scale = this.mapitem.scale = obj.s;
|
|
- this.mapitem.scale = this.scale;
|
|
|
|
this.opacity = obj.o;
|
|
this.opacity = obj.o;
|
|
// console.log('tween update obj.s', obj.s);
|
|
// console.log('tween update obj.s', obj.s);
|
|
this.pos = {x:obj.x, y:obj.y};
|
|
this.pos = {x:obj.x, y:obj.y};
|
|
@@ -2448,7 +2553,10 @@ export default {
|
|
// apply a force in direction of one side or an other depending of the start position
|
|
// apply a force in direction of one side or an other depending of the start position
|
|
// the force is exponentialy inversed proportional to the distance from the side
|
|
// the force is exponentialy inversed proportional to the distance from the side
|
|
// INFO logarithmic force : https://stackoverflow.com/questions/846221/logarithmic-slider/846249#846249
|
|
// INFO logarithmic force : https://stackoverflow.com/questions/846221/logarithmic-slider/846249#846249
|
|
- // TODO cartouch width should change regarding actual cartouch is opened or not (and how many cartouch are opened)
|
|
+ // cartouch width should change regarding actual cartouch is opened or not (and how many cartouch are opened)
|
|
|
|
+
|
|
|
|
+ // TODO force is proportional to window size
|
|
|
|
+
|
|
// X
|
|
// X
|
|
let pseudo_center_x = this.opened_concernement
|
|
let pseudo_center_x = this.opened_concernement
|
|
? (this.canvas.width - this.cartouch_width) / 2
|
|
? (this.canvas.width - this.cartouch_width) / 2
|
|
@@ -2545,15 +2653,17 @@ export default {
|
|
}
|
|
}
|
|
|
|
|
|
},
|
|
},
|
|
- respawn() {
|
|
+ checkOverflow() {
|
|
// respawn element if outside screen
|
|
// respawn element if outside screen
|
|
- let respanw = false;
|
|
+ let pad = 1;
|
|
- if(this.pos.x <= 0){ this.pos.x = 50; respanw=true;}
|
|
+ let circleray = this.body.circleRadius+pad*1.1;
|
|
- if(this.pos.x >= this.canvas.width){ this.pos.x = this.canvas.width - 50; respanw=true;}
|
|
+ let respawn = false;
|
|
- if(this.pos.y <= 0){ this.pos.y = 50; respanw=true;}
|
|
+ if(this.pos.x <= pad){ this.pos.x = circleray; respawn=true;}
|
|
- if(this.pos.y >= this.canvas.height){ this.pos.y = this.canvas.height - 50; respanw=true;}
|
|
+ if(this.pos.x >= this.canvas.width-pad){ this.pos.x = this.canvas.width - circleray; respawn=true;}
|
|
- if (respanw) {
|
|
+ if(this.pos.y <= pad){ this.pos.y = circleray; respawn=true;}
|
|
- // this.pos = respanw_pos;
|
|
+ if(this.pos.y >= this.canvas.height-pad){ this.pos.y = this.canvas.height - circleray; respawn=true;}
|
|
|
|
+ if (respawn) {
|
|
|
|
+ // this.pos = respawn_pos;
|
|
Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
|
|
Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
|
|
// this.setInitBodyVelocity();
|
|
// this.setInitBodyVelocity();
|
|
Matter.Body.setVelocity(this.body, {x:0,y:0});
|
|
Matter.Body.setVelocity(this.body, {x:0,y:0});
|
|
@@ -2561,7 +2671,7 @@ export default {
|
|
|
|
|
|
},
|
|
},
|
|
onAfterEngineUpdate (event) {
|
|
onAfterEngineUpdate (event) {
|
|
- this.respawn();
|
|
+ this.checkOverflow();
|
|
|
|
|
|
this.paper_main_object.position = this.pos = this.body.position;
|
|
this.paper_main_object.position = this.pos = this.body.position;
|
|
|
|
|
|
@@ -2575,8 +2685,33 @@ export default {
|
|
// }
|
|
// }
|
|
|
|
|
|
this.handlePaperVisibilityOnAfterEnginUpdate()
|
|
this.handlePaperVisibilityOnAfterEnginUpdate()
|
|
|
|
+
|
|
|
|
|
|
|
|
+ // DEBUG
|
|
|
|
+ // this.debugDrawMatterBodyCircle();
|
|
|
|
+ // END DEBUG
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
+ // onWindowResize(event){
|
|
|
|
+ // // console.log('mapitem onWindowResize', event, this);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // },
|
|
|
|
+ debugDrawMatterBodyCircle(){
|
|
|
|
+ if (this.paper_main_object.children['debug_circle']) {
|
|
|
|
+ this.paper_main_object.children['debug_circle'].remove();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let debugcircle = new paper.Path.Circle({
|
|
|
|
+ center: this.pos,
|
|
|
|
+ // radius: this.ray,
|
|
|
|
+ radius: this.body.circleRadius,
|
|
|
|
+ strokeColor: '#f00',
|
|
|
|
+ strokeWidth: 1,
|
|
|
|
+ name: 'debug_circle'
|
|
|
|
+ })
|
|
|
|
+ this.paper_main_object.addChild(debugcircle)
|
|
|
|
+ }
|
|
},
|
|
},
|
|
render() {
|
|
render() {
|
|
// console.log('render()', this.ctx);
|
|
// console.log('render()', this.ctx);
|