Skip to content

Conversation

@ombalgude
Copy link

Resolves #8097

Changes:

This PR adds a new activeCamera() function that provides a standard joint getter/setter API for accessing and modifying the current active camera in p5.js WebGL mode.

Implementation Details:

  • Added activeCamera() function: A joint getter/setter that follows the pattern used by other p5.js functions like linePerspective()

    • When called with no arguments: returns the current active p5.Camera object
    • When called with a camera argument: sets that camera as the active camera and returns this for chaining
    • Includes _assert3d() validation to ensure it's only used in WebGL mode
  • Added RendererGL.prototype.activeCamera() method: Implements the same getter/setter pattern at the renderer level, reusing existing setCamera() logic

  • Comprehensive test suite: Added 5 test cases covering:

    • Getting the current camera (no arguments)
    • Setting the camera (with argument)
    • Multiple camera switching scenarios
    • Chaining behavior
    • Correct camera object reference handling

Benefits:

  • Provides a standard API for camera access that's consistent with other p5.js functions
  • Enables library creators to write code that works with both V1 and V2 (when V1 support is added)
  • Maintains full backward compatibility with existing setCamera() function
  • Follows established p5.js patterns for joint getter/setter functions

Files Modified:

  • src/webgl/p5.Camera.js: Added fn.activeCamera() and RendererGL.prototype.activeCamera() with full JSDoc documentation and examples
  • test/unit/webgl/p5.Camera.js: Added comprehensive test suite for activeCamera() functionality

Screenshots of the change:

N/A - This is a code-only change that adds a new API function. No visual changes.

PR Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant