To achieve that you will need to do basic trigonometry. All calculations are done using radians.
1. Calculate the correct ObjectTemplate.zoom.zoomFactor. This value is the vertical FOV and relates to the magnification like this:
Code: Select all
FOV=ATAN(TAN(1.1/2)/Magnification)*2
For example:
4x zoom would result in
Code: Select all
FOV = ATAN(TAN(1.1/2)/4)*2
FOV = 0.304
2. Calculate the angles for the different ranges used in the rangefinder using
3. Convert the angles to pixels on screen using:
Code: Select all
Pixels = TAN(Angle) / TAN(FOV/2) * VerticalPixels/2
The vertical pixels would be the height of your resolution. The result should be rounded to closes integer.
For example:
Angle=0.1, FOV=0.304, VerticalPixels=900
Code: Select all
Pixels=TAN(0.1) / TAN(0.304/2) * 900/2
Pixels=29.377 ~ 29
4. Last step is most annoying: Adjust texture with calculated offsets and test in game. With a texture applied to a 3d mesh, like on binoculars, the pixels in texture will not match the rendered pixels in game. I suggest to take a comparison screenshot and calculate the factor between 2d texture and rendered image in game. Sadly in the end this will require quite some trial and error.
5. Dont try to be too perfect
Getting within +/-20m of actual range would already be very good. Very far ranges will matter even less. I would not even bother trying to get it to work past 1500m. At those distances the differences in pixels between two marks is usually so small that we hardly can display it anyways.
Last a tip regarding the equipment of the imperialists: Even tho they used freedom units back then, use meters in game. It makes things easier to adjust as well as easier for player to use as everything else in game is using meters.