p5.js中p5.Camera的setPosition()方法用於將攝像機的位置設置為世界空間中的給定點。更改位置時,它可保持當前相機方向。
用法:
setPosition( x, y, z )
參數:此方法接受上述和以下所述的三個參數:
- x:它是一個數字,表示該點在世界空間中的x位置。
- y:它是一個數字,表示該點在世界空間中的y位置。
- z:該數字表示點在世界空間中的z位置。
以下示例說明了p5.js中的setPosition()方法:
例:
Javascript
let currCamera;
function setup() {
createCanvas(500, 500, WEBGL);
helpText = createP(
"Move the sliders to change the " +
"position of the camera"
);
helpText.position(20, 0);
// Create the camera
currCamera = createCamera();
// Create three sliders for changing the
// position of the camera
xPosSlider = createSlider(-360, 360, 0);
xPosSlider.position(20, 40);
yPosSlider = createSlider(-360, 360, 0);
yPosSlider.position(20, 70);
zPosSlider = createSlider(0, 800, 600);
zPosSlider.position(20, 100);
}
function draw() {
clear();
lights();
normalMaterial();
debugMode();
// Get the x, y, z values from the
// sliders
let currX = xPosSlider.value();
let currY = yPosSlider.value();
let currZ = zPosSlider.value();
// Set the position of the camera
// to these points in the world space
currCamera.setPosition(currX, currY, currZ);
cylinder(90);
}
輸出:
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
相關用法
- Lodash _.method()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
- Node.js http.IncomingMessage.method用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- HTML DOM isEqualNode()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- Node.js fs.link()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toString()用法及代碼示例
- Javascript Number.isInteger( )用法及代碼示例
- Javascript Number.isFinite()用法及代碼示例
- Javascript toFixed()用法及代碼示例
- Javascript toPrecision()用法及代碼示例
- JavaScript Math abs()用法及代碼示例
- JavaScript Math sqrt()用法及代碼示例
- JavaScript Math floor()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.Camera setPosition() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。