Javascript 在透视中投影时反转z轴

Javascript 在透视中投影时反转z轴,javascript,math,canvas,perspectivecamera,Javascript,Math,Canvas,Perspectivecamera,我正在创造一个节奏游戏。但我并没有使用节拍器来计算屏幕上音符的位置(游戏界面)。我所拥有的是一个带有注释映射的文件,它非常类似于字幕文件 问题是,当我在透视图中投影注释时,注释没有正确显示。似乎我已经反转了Z轴,我无法改变它。我想知道如何正确更改轴,因为。或者如果有人能帮我解决其他问题,我将不胜感激。我尝试了不同的方法,但我无法正确地显示笔记 ,以及执行透视图计算的函数 function updateNotes() { currentPosition = (sound.seek() *

我正在创造一个节奏游戏。但我并没有使用节拍器来计算屏幕上音符的位置(游戏界面)。我所拥有的是一个带有注释映射的文件,它非常类似于字幕文件

问题是,当我在透视图中投影注释时,注释没有正确显示。似乎我已经反转了Z轴,我无法改变它。我想知道如何正确更改轴,因为。或者如果有人能帮我解决其他问题,我将不胜感激。我尝试了不同的方法,但我无法正确地显示笔记

,以及执行透视图计算的函数

function updateNotes() {
    currentPosition = (sound.seek() * 1000);

    notes.forEach(function(note, index) {
    var notePosition = (currentPosition * noteSpeed) - ((note.position * noteSpeed) - deadLine);

    if (notePosition > offScreenY && notePosition < height) {
    var ball = new Ball3d(5, '#000000');
    var scale = fov / (fov + notePosition);
    console.log(notePosition);
    ball.x = halfWidth;
    ball.y = halfHeight + notePosition * scale;
    ball.scaleX = ball.scaleY = scale;
    ball.draw(context);
    balls.push(ball);
  } else {
    // elimino la nota
    balls.splice(index, 1);
  }
  });
}
函数updateNotes(){
currentPosition=(sound.seek()*1000);
notes.forEach(函数(注释,索引){
var notePosition=(当前位置*noteSpeed)-(note.position*noteSpeed)-截止日期);
if(notePosition>offScreenY&¬ePosition

提前感谢。

z轴没有反转,音符是从上到下的,但随着它们的缩小,它们似乎离得更远,因此您必须调整您的比例分配。使用
var标度=(fov+notePosition)/fov时它看起来更像是向用户走来的,尽管您必须稍微调整您的公式以使其看起来更好

//初始化变量
var canvas=document.getElementById('canvas'),
context=canvas.getContext('2d'),
宽度=画布。宽度=窗口。内部宽度,
高度=画布。高度=窗口。内部高度,
半宽度=宽度/2,
半高=高度/2,
截止日期=高度-100,
视场=250,
offScreenY=-100,
currentPosition=0,
balls=[],
注速度=0.3,
动物;
新嚎叫({
src:['https://rawcdn.githack.com/noeszc/atwood/master/assets/sounds/mario.ogg'],
onload:function(){setup();},
onend:function(){stop();}
});
函数设置(){
声音。播放();
声音。静音();
提取截止日期();
gameLoop();
}
函数gameLoop(){
animId=requestAnimationFrame(gameLoop,画布);
clearRect(0,0,宽度,高度);
updateNotes();
提取截止日期();
}
函数updateNotes(){
currentPosition=(sound.seek()*1000);
notes.forEach(函数(注释,索引){
var notePosition=(当前位置*noteSpeed)-(note.position*noteSpeed)-截止日期);
if(notePosition>offScreenY&¬ePosition
正文{
保证金:0;
}
帆布{
显示:块;
}


很难知道你想要什么。猜一猜,试试球。y=高度-音符位置*刻度感谢您的回复,我尝试的是让注释来自远方,如下所示