I have a world size of 100x100
I want to map this world size to screen size using this mapTo function
function mapTo(pos, from, to) {
let n = pos / from;
return n * to;
}
Now I want to show only a portion of this world scaled up to the screen size, let's call it view size of 10x10 now how should I map this world size of screen size with regards to view size?
I want to show 10x10 world units fit the whole screen.
I've tried to do:
let aWorldPosition = [0, 0];
let worldSize = [100, 100];
let viewSize = [10, 10];
let screenSize = [20, 20];
let r = mapTo(aWorldPosition, worldSize, viewSize);
r = mapTo(r, viewSize, screenSize);
but that doesn't work.
Also I want to be able to move the view so I can show portions of the world.
I've tried this and seems to be working but I don't know if it's correct:
let r = mapTo(aWorldPosition, viewSize, screenSize);
Here viewSize is in world coordinates.