0

i hope you're all doing great even though it's probably hot as hell outside!

I am currently working with Three.js' CSS3DRenderer to combine both DOM elements and webGL content. I managed to do everything i wanted but now I'm kinda curious about how this all works.

Here is a link to the source code : CSS3DRenderer

I understand that the principle of the nested div elements (renderer with perpective, camera with worldInverse aka view matrix and objects with model matrix) is to reproduce the matrix product : MVP to obtain div position on canvas from 3D coordinates. Using "perspective" css property applied to children elements and transform-style preserve3D etc.. That's how i understand it. I hope i'm not wrong, please don't hesitate to correct me ^^.

However my questions are regarding the fov computation from the projection matrix of the camera and why it used that way. First line 275 :

var fov = camera.projectionMatrix.elements[ 5 ] * _heightHalf;

from what i know this element from the projection matrix is the following : (2 * near) / (top - bottom). How does it relate to the fov? and why multiply it by the heightHalf of the rendering domElement?

Furthermore line 294 :

var cameraCSSMatrix = camera.isOrthographicCamera ?
'scale(' + fov + ')' + getCameraCSSMatrix( camera.matrixWorldInverse ) :
'translateZ(' + fov + 'px)' + getCameraCSSMatrix( camera.matrixWorldInverse );

it uses the previously calculated fov to apply a scale to the cameraElement if it is orthographic or a translation if it's a perspective camera. I don't get why it is done precisely that whay and i would like to understand it.

Can anybody shed some light on this matter =/ ?

Tank you for reading my post :) and sorry for my bad english.

Jonathan
  • 1
  • 2
  • 1
    You are focusing on what makes this code so brilliant. (1) `fov` is a poor choice for the variable name, IMO. Think of it as a distance. (2) Read [this commit](https://github.com/mrdoob/three.js/commit/cdbe2f86df306c8c7c1882c3d3f6cd0f42a1f7d5) to understand where the current formula comes from. – WestLangley Aug 06 '18 at 17:19
  • I think this is much better illustrated with some diagrams and trigonometry, i'll try to post some sketches. – pailhead Aug 06 '18 at 18:15
  • Sorry i'm having a hard time understanding it even when i'm looking at Matrix4.makePerspective. I may be lacking some basics i guess :(. – Jonathan Aug 07 '18 at 07:31
  • Can somebody please help, i'm stuck =/ @pailhead. – Jonathan Aug 13 '18 at 07:40

0 Answers0