The online racing simulator
Question about FOV and how it works? (threejs problem)
Hello,
im trying to create my own 3D rendered scene on top of LFS window, for now using IS_CPP packet with tick interval and it seems giving right output that i managed to convert, but i want to know how to make LFS FOV into threejs FOV. Currently in the example i created PerspectiveCamera in threejs with 80 FOV as default. In the video that is below you can see LFS FOV in shift+u view, and it looks 112-113 LFS FOV almost same as threejs FOV (80).




Maybe someone was doing something same as this, manipulating 3D space externally, because i do not have experience with injections into DLL to draw something similiar using LFS itself. Im looking for better ideas, maybe someone already did that before.

Object is moving like this, because framerate is different in game and in scene, but it should stand in right location.
https://streamable.com/h6wesa
Looks like threejs uses vertical FOV, while LFS FOV is horizontal FOV.

The conversion:

3JS fov = 80
half_fov = 40
// now take the tangent so we can convert to horizontal:
tan(half_fov) = 0.8391
// convert this vertical tangent of half_fov to horizontal tangent of half_fov (for 16:9 screen):
(16/9) * tan(half_fov) = 1.491
// convert this to a half_fov using inverse tangent (arctan)
atan((16/9) * tan(half_fov)) = 56.16 degrees
// finally multiply by 2 to get the LFS fov
112.3 degrees

So assuming 16:9 screen:

lfs_fov = 2 * atan( (16/9) * tan(threejs_fov / 2) )

or:

threejs_fov = 2 * atan( (9/16) * tan(lfs_fov / 2) )
Quote from Scawen :Looks like threejs uses vertical FOV, while LFS FOV is horizontal FOV.

The conversion:

3JS fov = 80
half_fov = 40
// now take the tangent so we can convert to horizontal:
tan(half_fov) = 0.8391
// convert this vertical tangent of half_fov to horizontal tangent of half_fov (for 16:9 screen):
(16/9) * tan(half_fov) = 1.491
// convert this to a half_fov using inverse tangent (arctan)
atan((16/9) * tan(half_fov)) = 56.16 degrees
// finally multiply by 2 to get the LFS fov
112.3 degrees

So assuming 16:9 screen:

lfs_fov = 2 * atan( (16/9) * tan(threejs_fov / 2) )

or:

threejs_fov = 2 * atan( (9/16) * tan(lfs_fov / 2) )

Thanks it works as expected!
First time used in JS it gave me invalid output, because i had to convert FOV into rad and result into degrees, and your explanation above really helped me to understand and check if those values are right by doing it in my code.

const threejsFOV = 2 * toDeg(Math.atan((9/16) * Math.tan(toRad(LFSFOV / 2))));

This is how it looks now: https://streamable.com/pucon8
#4 - zeeaq
Quote from Scawen :Looks like threejs uses vertical FOV, while LFS FOV is horizontal FOV.

The conversion:

3JS fov = 80
half_fov = 40
// now take the tangent so we can convert to horizontal:
tan(half_fov) = 0.8391
// convert this vertical tangent of half_fov to horizontal tangent of half_fov (for 16:9 screen):
(16/9) * tan(half_fov) = 1.491
// convert this to a half_fov using inverse tangent (arctan)
atan((16/9) * tan(half_fov)) = 56.16 degrees
// finally multiply by 2 to get the LFS fov
112.3 degrees

So assuming 16:9 screen:

lfs_fov = 2 * atan( (16/9) * tan(threejs_fov / 2) )

or:

threejs_fov = 2 * atan( (9/16) * tan(lfs_fov / 2) )

This is also useful for when one uses an online calculator to set ideal FOV, since most of those give out vertical FOV values.

FGED GREDG RDFGDR GSFDG