Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/webgl/p5.Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down