From e122564f65fcc9b1364a5d7a6f860fd454753315 Mon Sep 17 00:00:00 2001 From: Om <144691499+ombalgude@users.noreply.github.com> Date: Tue, 23 Sep 2025 17:45:59 +0530 Subject: [PATCH] feat(webgl) : Add activeCamera() and deprecate setCamera() --- src/webgl/p5.Camera.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index b687f916c5..743fb283ce 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -3980,14 +3980,36 @@ function camera(p5, fn){ return _cam; }; - RendererGL.prototype.setCamera = function(cam) { + /** + * Sets the active camera. + * @method activeCamera + * @for p5.RendererGL + * @param {p5.Camera} [cam] camera that should be made active. + * @chainable + */ + /** + * Returns the active camera. + * @method activeCamera + * @for p5.RendererGL + * @return {p5.Camera} the active camera. + */ + RendererGL.prototype.activeCamera = function(cam) { + if (cam === undefined) { + return this.states.getValue('curCamera'); + } this.states.setValue('curCamera', cam); + return this; + }; + + RendererGL.prototype.setCamera = function(cam) { + this.activeCamera(cam); // set the projection matrix (which is not normally updated each frame) this.states.setValue('uPMatrix', this.states.uPMatrix.clone()); this.states.uPMatrix.set(cam.projMatrix); this.states.setValue('uViewMatrix', this.states.uViewMatrix.clone()); this.states.uViewMatrix.set(cam.cameraMatrix); + return this; }; }