algorithmic Zoom calculation help rmmv?

Status
Not open for further replies.

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
Would anyone have the right math formula to calculate the zoom in rpg maker mv?
I need one based on the mouse position.


PHP:
const SM_S = SceneManager._scene;
const mapZoom = SM_S._spriteset._tilemap.scale;
PHP:
    function wheel_(event) {//TODO: zoom system
        if(event.wheelDeltaY>0){
            mapZoom.x+=0.05;
            mapZoom.y+=0.05;
            $gameMap._displayX+=0.05
            dX+=0.05;
        }else{
            mapZoom.x-=0.05;
            mapZoom.y-=0.05;
            $gameMap._displayX-=0.05
            dX-=0.05;
        }
    };
thank
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
I have tried to deal with zoom, but always failed in the end :( However, maybe it'd be more appropriate to use $gameMap._displayX+= Math.floor (0.05 * Graphics.boxWidth) multiplied by 1 or -1 depending on which half of the screen your mouse is.
Same for the Y direction.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
Someone explain to me a trick that seems logical to me, it remains for me more than to apply it.
Ideally I would like something a little more mathematical.
The idea is to remember coordinates of certain point on screen, and then restore them.

PHP:
class myCamera extends PIXI.Container {
       constructor {
              super();
              memCoord = new PIXI.Point();
           memCoord2 = new PIXI.Point();
       }

   public pushPivot(pos) {
       this.toLocal(pos, null, this.memCoord);
   }

   public popPivot(pos) {
       this.toLocal(pos, null, this.memCoord2);
       this.pivotTarget.x -= this.memCoord2.x - this.memCoord.x;
       this.pivotTarget.y -= this.memCoord2.y - this.memCoord.y;
   }
}
//declare scale somewhere. you can do it in camera too.
var scale = 1.0;
...
//zoom in
const mousePos = renderer.interaction.mouse.global;
stage.camera.pushPivot(mousePos);

scale *= 1.1;
camera.scale.set(scale);

stage.camera.popPivot(mousePos);
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
ho yess, finaly, no need to touch the $gameMap._displayX

PHP:
    memCoord = new PIXI.Point();
    memCoord2 = new PIXI.Point();
    function pushPivot(pos) {
        SM_S._spriteset._tilemap.toLocal(pos, null, memCoord);
    }
    function popPivot(pos) {
        SM_S._spriteset._tilemap.toLocal(pos, null, memCoord2);
        SM_S._spriteset._tilemap.pivot.x -= memCoord2.x - memCoord.x;
        SM_S._spriteset._tilemap.pivot.y -= memCoord2.y - memCoord.y;
    }
    function wheel_(event) {//TODO: zoom system
        setMouseXY();
        const mousePos = new PIXI.Point(mX,mY);
        pushPivot(mousePos);
        if(event.wheelDeltaY>0){
            mapZoom.x+=0.1
            mapZoom.y+=0.1
        }else{
           mapZoom.x-=0.1;
           mapZoom.y-=0.1;
        }
        popPivot(mousePos);
    };
 

hiddenone

Lurker Extraordinaire
Global Mod
Joined
Feb 19, 2014
Messages
2,497
Reaction score
5,334
First Language
english
Primarily Uses
RMMZ

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,585
Latest member
Reversinator
Top