Skip to main content
deleted 8 characters in body
Source Link

Okay so turnsTurns out when the viewport sizes change, the zoom is simply either h2 / h1 or w2 / w1, depending on what field of view we are keeping constant.

In my case, I had the vertical field of view constant, thus I used h2 / h1. So we can have f(x1, y1) = (h2*x1/h1, h2*y2/h1).

This will give us the correct y coordinate but we might get an offset on the x coordinate since the aspect ratio changes. To fix this, we just compute the offset by using the fact that the smaller/larger size of the viewport in the x-axis would have the same centre as the original viewport.

So the offset is just (change in width) / 2 = (w2 - h2*w1/h1) / 2 Finally, f(x1, y1) = ((w2 - h2*w1/h1) / 2 + h2*x1/h1, h2*y2/h1) is the function I needed!

I plugged this into my program and got the desired results!

Okay so turns out when the viewport sizes change, the zoom is simply either h2 / h1 or w2 / w1, depending on what field of view we are keeping constant.

In my case, I had the vertical field of view constant, thus I used h2 / h1. So we can have f(x1, y1) = (h2*x1/h1, h2*y2/h1).

This will give us the correct y coordinate but we might get an offset on the x coordinate since the aspect ratio changes. To fix this, we just compute the offset by using the fact that the smaller/larger size of the viewport in the x-axis would have the same centre as the original viewport.

So the offset is just (change in width) / 2 = (w2 - h2*w1/h1) / 2 Finally, f(x1, y1) = ((w2 - h2*w1/h1) / 2 + h2*x1/h1, h2*y2/h1) is the function I needed!

I plugged this into my program and got the desired results!

Turns out when the viewport sizes change, the zoom is simply either h2 / h1 or w2 / w1, depending on what field of view we are keeping constant.

In my case, I had the vertical field of view constant, thus I used h2 / h1. So we can have f(x1, y1) = (h2*x1/h1, h2*y2/h1).

This will give us the correct y coordinate but we might get an offset on the x coordinate since the aspect ratio changes. To fix this, we just compute the offset by using the fact that the smaller/larger size of the viewport in the x-axis would have the same centre as the original viewport.

So the offset is just (change in width) / 2 = (w2 - h2*w1/h1) / 2 Finally, f(x1, y1) = ((w2 - h2*w1/h1) / 2 + h2*x1/h1, h2*y2/h1) is the function I needed!

I plugged this into my program and got the desired results!

Source Link

Okay so turns out when the viewport sizes change, the zoom is simply either h2 / h1 or w2 / w1, depending on what field of view we are keeping constant.

In my case, I had the vertical field of view constant, thus I used h2 / h1. So we can have f(x1, y1) = (h2*x1/h1, h2*y2/h1).

This will give us the correct y coordinate but we might get an offset on the x coordinate since the aspect ratio changes. To fix this, we just compute the offset by using the fact that the smaller/larger size of the viewport in the x-axis would have the same centre as the original viewport.

So the offset is just (change in width) / 2 = (w2 - h2*w1/h1) / 2 Finally, f(x1, y1) = ((w2 - h2*w1/h1) / 2 + h2*x1/h1, h2*y2/h1) is the function I needed!

I plugged this into my program and got the desired results!