0

How can I access the perspective camera's projection matrix directly and change one or more of the 16 values?

I tried the code bellow with and without .updateProjectionMatrix() and it doesn't work, probably it is overiden by an internal function:

cameraPersp.projectionMatrix.elements.set = 
(a,b,c,d,
e,f,g,h,
i,j,k,l,
m,n,o,p);

cameraPersp.updateProjectionMatrix();

Also, I have no idea if it can be multiplied, added etc using .set (lack of documentation) -it doesn't raise an error though.

user5515
  • 301
  • 2
  • 18
  • 1
    `camera.projectionMatrix`? The single elements are kept inside the `.elements` property (an array) of a matrix object. – Mugen87 Mar 29 '18 at 17:05
  • I tried the code bellow with and without .updateProjectionMatrix() and it doesn't work, probably it is overiden by an internal function: cameraPersp.projectionMatrix.elements.set = (a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p); cameraPersp.updateProjectionMatrix(); Also, I don't have any idea if it can be multiplied, added etc using .set (lack of documentation) – user5515 Mar 29 '18 at 18:14
  • If you call `.updateProjectionMatrix()`, the `projectionMatrix` is calculated from scratch. This will overwrite any values you've manually set before. The `projectionMatrix` itself is an instance of `Matrix4`: https://threejs.org/docs/#api/math/Matrix4 – Mugen87 Mar 30 '18 at 10:44
  • Yes, I just found out. It works, without using "elements", "=" and "updateProjectionMatrix()" -see update above. How can I change a single matrix value directly? – user5515 Mar 30 '18 at 11:08
  • @user5515 `camera.projectionMatrix.elements[ 0 ] = 1;` – WestLangley Mar 30 '18 at 14:55
  • Yes, apparently that works, thanks. The irony is I tried that a while ago but it didn't work as I wrote it as a number implying row-column order like [31] instead of array... – user5515 Mar 30 '18 at 15:54

1 Answers1

0

So, to set a given matrix to custom float values, directly:

cameraPersp.projectionMatrix.set 
(a,b,c,d,
e,f,g,h,
i,j,k,l,
m,n,o,p);

To change a single matrix value directly:

cameraPersp.projectionMatrix.elements[n] = yourfloatvalue;

In both cases, updateProjectionMatrix() should NOT be called.

user5515
  • 301
  • 2
  • 18