gpt4 book ai didi

javascript - THREE.js 相机遵循特定路径

转载 作者:行者123 更新时间:2023-11-28 11:49:32 25 4
gpt4 key购买 nike

我正在尝试使用 THREE.js 制作游戏。我有一条包含很多曲线和一些直线路径的路径。

我在网上找到了一个例子,尝试实现TrackballControls.js让摄像头沿着一条线走,但是摄像头不看前方,移动起来很奇怪。

这是代码:

var controls = new THREE.TrackballControls(camera, render.domElement);
var numPoints = 50;
spline = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(50, 0, 0),
new THREE.Vector3(0, 0, -100)
]);

var material = new THREE.LineBasicMaterial({
color: 0xff00f0,
});

var geometry = new THREE.Geometry();
var splinePoints = spline.getPoints(numPoints);

for (var i = 0; i < splinePoints.length; i++) {
geometry.vertices.push(splinePoints[i]);
}

line = new THREE.Line(geometry, material);
line.position.set(0, 0, 0);
scene.add(line);
var counter = 0;

if (counter <= 1) {
camera.position.copy( spline.getPointAt(counter) );
tangent = spline.getTangentAt(counter).normalize();
axis.crossVectors(up, tangent).normalize();
var radians = Math.acos(up.dot(tangent));
camera.quaternion.setFromAxisAngle(axis, radians);
counter += 0.005
} else {
counter = 0;
}

谢谢。

最佳答案

以下example展示如何创建遵循样条曲线的相机。只需点击“相机样条动画 View ”按钮即可查看效果。也许你可以使用底层代码来解决你的问题。

关于javascript - THREE.js 相机遵循特定路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40331353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com