Graphics 摄影机控件与它们应该是的相反。为什么?
我正在Three.js中创建一个可玩的迷宫。所有对象(地板、天花板和墙壁)都已放置在正X轴和Z轴内。相机的放置方式如下所示:Graphics 摄影机控件与它们应该是的相反。为什么?,graphics,three.js,camera,axis,Graphics,Three.js,Camera,Axis,我正在Three.js中创建一个可玩的迷宫。所有对象(地板、天花板和墙壁)都已放置在正X轴和Z轴内。相机的放置方式如下所示: camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1,
camera = new THREE.PerspectiveCamera(45,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(0, 0.25, 0);
// The camera is placed pointing to the nearest open path from the
// initial position. Check mazeGenerator.js for the reference of
// "coordinates".
if(grid[1][0] == coordinates.W)
{
camera.lookAt(new THREE.Vector3(1, 0.25, 0));
}
else
{
camera.lookAt(new THREE.Vector3(0, 0.25, 1));
}
它是这样运动的:
function keyboardCheck()
{
var movementSpeed = 0.02;
var rotationSpeed = 0.03;
if(keyboard.pressed('w') || keyboard.pressed('up'))
{
camera.translateZ(-movementSpeed);
}
if(keyboard.pressed('a') || keyboard.pressed('left'))
{
camera.rotateY(rotationSpeed);
}
if(keyboard.pressed('d') || keyboard.pressed('right'))
{
camera.rotateY(-rotationSpeed);
}
}
如果我在没有lookAt功能的情况下放置相机,它似乎面向[0,0,0],但当然我想做的是通过使相机面向最近的开放路径来帮助播放器
为了使它向前移动,我必须减小Z,否则当你按下向前移动键时,它会向后移动。这让我觉得,即使我告诉相机看某个方向,对象的Z轴与世界的Z轴相反
问题本身是:为什么会发生这种情况
事先非常感谢
相机向下看其负z轴,因此要向前移动,请执行以下操作:
camera.translateZ( - distance );
所有其他对象都被视为沿其正z轴的方向查看,因此要向前移动其他对象,可以使用
object.translateZ( distance );
3.js r.85