P5js V2 get current camera?

In V1 I could get a reference to the current camera like this -

        let p5canvas;

        function setup() {
            p5canvas = createCanvas(400, 400, WEBGL);
            console.log(p5canvas._curCamera);
        }

        function draw() {
            background(220);
        }

but in V2 of p5.Canvas the variable _curCamera is undefined.

It is not ideal solution because the variable _curCamera should be treated as a private variable but needs must.

So what I am looking for is a statement that will give me a reference to the current camera that is the same in V1 and V2.

Any help appreciated :grin:

1 Like

There’s not a public API for either, but in v2 p5Canvas.states.curCamera is the equivalent of what you’re doing. So you could do something like this if you wanted to make yourself a function that works in both:

function getCamera(renderer) {
  if (VERSION.startsWith('2.')) {
    return renderer.states.curCamera;
  } else {
    return renderer._curCamera;
  }
}
// Usage: const cam = getCamera(p5canvas)

(This would probably be a useful API to exist; if you’re interested, feel free to open a feature request on github!)

2 Likes