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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。