Static p5_sys::global::camera [−][src]
pub static camera: CameraInternalType
Expand description
Sets the camera position for a 3D sketch. Parameters for this function define the position for the camera, the center of the sketch (where the camera is pointing), and an up direction (the orientation of the camera).
This function simulates the movements of the camera, allowing objects to be viewed from various angles. Remember, it does not move the objects themselves but the camera instead. For example when centerX value is positive, the camera is rotating to the right side of the sketch, so the object would seem like moving to the left.
See this example to view the position of your camera.
When called with no arguments, this function creates a default camera equivalent to camera(0, 0, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0);
Examples
function setup() { createCanvas(100, 100, WEBGL); } function draw() { background(204); //move the camera away from the plane by a sin wave camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0); plane(10, 10); }
//move slider to see changes! //sliders control the first 6 parameters of camera() let sliderGroup = []; let X; let Y; let Z; let centerX; let centerY; let centerZ; let h = 20; function setup() { createCanvas(100, 100, WEBGL); //create sliders for (var i = 0; i < 6; i++) { if (i === 2) { sliderGroup[i] = createSlider(10, 400, 200); } else { sliderGroup[i] = createSlider(-400, 400, 0); } h = map(i, 0, 6, 5, 85); sliderGroup[i].position(10, height + h); sliderGroup[i].style('width', '80px'); } } function draw() { background(60); // assigning sliders' value to each parameters X = sliderGroup[0].value(); Y = sliderGroup[1].value(); Z = sliderGroup[2].value(); centerX = sliderGroup[3].value(); centerY = sliderGroup[4].value(); centerZ = sliderGroup[5].value(); camera(X, Y, Z, centerX, centerY, centerZ, 0, 1, 0); stroke(255); fill(255, 102, 94); box(85); }
Parameters
x?
camera position value on x axis
y?
camera position value on y axis
z?
camera position value on z axis
centerX?
x coordinate representing center of the sketch
centerY?
y coordinate representing center of the sketch
centerZ?
z coordinate representing center of the sketch
upX?
x component of direction ‘up’ from camera
upY?
y component of direction ‘up’ from camera
upZ?
z component of direction ‘up’ from camera