Is it possible to alter a camera’s frustum?
Or, is there some other way of limiting the extents of what a camera renders?
TIA
You can change its FOV (field of view) - is that what you are after?
And also near and far plane.
I’m afraid not, no.
I need to set the left, right, top and bottom sides.
Could you perhaps collaborate more on what is the end result?
Also, are you using perspective or orhographic camera?
The most generic way would be for you to provide custom projection matrix:
https://developer.playcanvas.com/api/pc.CameraComponent.html#calculateProjection
see the relevant code here:
I’m looking into ways to implement a portal-like window (as a much simplified portal to help my understanding and minimise the code required) (https://forum.playcanvas.com/t/portal-like-mirror/23894) and I’d like to render a volume off to one side of from the camera’s forward.
This is for a perspective camera.
The API documentation states that the frustum is read only.(https://developer.playcanvas.com/en/api/pc.CameraComponent.html#frustum)
That’s a daunting amount of code.
Can a custom projection matrix alter the viewing frustum?
yes, the frustum is evaluated from the projection matrix … as long as you generate the custom matrix, the frustum will automatically match.
The code is just for reference to see what the current code does … so you can perhaps base your matrix code on our code, but use the off-center version of it.
This is how the engine computes the matrix … perhaps you can modify this to your needs
Hmm. That looks like it takes a projection matrix and makes a frustum that’s symmetrical about it’s centre.
Is that right? I need it to be offset away from the centre.
Or does the calculateProjection
function have access to the frustum?
To answer my own question, it looks like calculateProjection
does have access to the frustum.
https://forum.playcanvas.com/t/issue-with-non-square-aspect-ratio-and-resizing/10317/10
yes, current projection matrix used by the engine is symmetrical. That’s why you need to provide different off-center projection matrix.
Using calculateProjection
looks like the route to take, and I’ve made promising progress.
However, I need to re-calculate the field of view (FOV) based on the position of the camera relative to the “window” but I can’t pass the value to the function and this.app.root.findByName
doesn’t work since app
isn’t accessible inside calculateProjection
.
Any idea how to proceed?
Answered my own question - use closures. A JavaScript feature not PlayCanvas.