Post by inventordave on Sept 1, 2021 19:00:36 GMT
Hi Jamis et al!
I first started working through the book over a year ago, and I have only worked on the raytracer intermittently, however, I have developed it as a Browser app to quite a substantial extent (the *ongoing* build can be found live at www.inventordave.com/rt-dt/raytracer.html. To use the later sample scenes (all found in the left-most drop-down box above the app console to the left of the canvas), please open the dev console and type 'preLoadResources()', and this will load the support files (textures & normal maps for the moment). I personally recommend after loading the resource files, to select 'Earth & Moon', it uses a point light and an area light.
Anyways, the reason for me creating this post is this:
I have just discovered for the first time that the implementation of my Camera object has been wrong. I put my copy of Jamis's book in lock-box storage recently, so I can't go back and check the original source, so it may turn out that when I was going through the part about generating the Camera object, I was durnk and mis-read, then mis-implemented my Camera, but,
I am sure, sure, that Jamis gave instructions to use 2 different methods to produce C.half_width & C.half_height values depending on the aspect ratio. As in, if the aspect ratio was > 1 (hsize > vsize, or, canvas width > canvas height, or otherwise), that would require seperate calculations for the C.half_width and C.half_height values, but this is wrong. The following code is correct:
The 2nd thing that I swear I got straight from the book, but was wrong, is
I swear C.half_view was calculated by
If so, Jamis made an error in his trigonometry. The value we want is the tangent of the *other* non-90deg angle in the right-angle triangle that represents 1/2 of the triangle representing the field of view. Thus,
The correct way to calculate C.half_view is,
Please, because I cannot immediately get access to my personal copy of the book, tell me, was I drunk and mis-parsed Jamis's instructions? Or, have I found an error in the, quite fun and accessible, text?
*To be clear, my helper function 'radians(n)' takes an angle in degrees, and converts it to radians, because JS Math.tan() requires an angle in radians, and obvs, C.fov is passed as an argument to the Camera constructor as a value in radians.*
Tell me if either or both of these apparent mistakes are just me being incoherent when coding my object/constructor code, and then forgetting what I've done, or if I'm right.
Thanks muchly,
Dave.
I first started working through the book over a year ago, and I have only worked on the raytracer intermittently, however, I have developed it as a Browser app to quite a substantial extent (the *ongoing* build can be found live at www.inventordave.com/rt-dt/raytracer.html. To use the later sample scenes (all found in the left-most drop-down box above the app console to the left of the canvas), please open the dev console and type 'preLoadResources()', and this will load the support files (textures & normal maps for the moment). I personally recommend after loading the resource files, to select 'Earth & Moon', it uses a point light and an area light.
Anyways, the reason for me creating this post is this:
I have just discovered for the first time that the implementation of my Camera object has been wrong. I put my copy of Jamis's book in lock-box storage recently, so I can't go back and check the original source, so it may turn out that when I was going through the part about generating the Camera object, I was durnk and mis-read, then mis-implemented my Camera, but,
I am sure, sure, that Jamis gave instructions to use 2 different methods to produce C.half_width & C.half_height values depending on the aspect ratio. As in, if the aspect ratio was > 1 (hsize > vsize, or, canvas width > canvas height, or otherwise), that would require seperate calculations for the C.half_width and C.half_height values, but this is wrong. The following code is correct:
C.aspect = hsize / vsize;
C.half_width = C.half_view;
C.half_height = C.half_view / C.aspect;
My memory of the book, and the code I implemented, did not do this single method of calculating the values, but it should.
[I shall explain why, on the off-chance I'm not a complete cretin: The "fov" angle is innately about a horizontal perspective. As in, regardless of whether the aspect ratio is > 1 or < 1, we only ever adjust/ratio the vertical aspect of the Camera's "scope" (C.half_height), the horizontal aspect (C.half_width) is *always* defined directly by the "field of view"...
The 2nd thing that I swear I got straight from the book, but was wrong, is
I swear C.half_view was calculated by
C.half_view = Math.tan(C.fov/2)
If so, Jamis made an error in his trigonometry. The value we want is the tangent of the *other* non-90deg angle in the right-angle triangle that represents 1/2 of the triangle representing the field of view. Thus,
The correct way to calculate C.half_view is,
C.half_view = Math.tan(radians(90) - (C.fov/2))
I thought that Jamis's instruction was to do:
C.half_view = Math.tan(C.fov/2)
Please, because I cannot immediately get access to my personal copy of the book, tell me, was I drunk and mis-parsed Jamis's instructions? Or, have I found an error in the, quite fun and accessible, text?
*To be clear, my helper function 'radians(n)' takes an angle in degrees, and converts it to radians, because JS Math.tan() requires an angle in radians, and obvs, C.fov is passed as an argument to the Camera constructor as a value in radians.*
Tell me if either or both of these apparent mistakes are just me being incoherent when coding my object/constructor code, and then forgetting what I've done, or if I'm right.
Thanks muchly,
Dave.