将 3D 点投影到 2D 点会使事情发生反转
似乎相机后面的所有东西都倒过来了或者什么的:
这是原始模型:
所以相机位于“框架”的右侧开口处。
这是深度计算(我认为问题就在这里):
function 3dto2d(x, y, z) {
var scale = cameradistance / (cameradistance - z);
return {
'x' : x * scale,
'y' : y * scale
};
}
有人知道这个问题吗?
编辑:我在这里有答案:
function 3dto2d(x, y, z) {
var scale = cameradistance / (cameradistance - (z >= cameradistance ? cameradistance - 1 : z));
return {
'x' : x * scale,
'y' : y * scale
};
}
It seems everything in back of the camera get's inverted back or something:
This is the original model:
So the camera is in the right opening of the "frame".
Here's the depth calculation (I think the problem is here):
function 3dto2d(x, y, z) {
var scale = cameradistance / (cameradistance - z);
return {
'x' : x * scale,
'y' : y * scale
};
}
Does someone know this problem?
EDIT: I have the answer here:
function 3dto2d(x, y, z) {
var scale = cameradistance / (cameradistance - (z >= cameradistance ? cameradistance - 1 : z));
return {
'x' : x * scale,
'y' : y * scale
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当点具有
z <= 0
时,这也发生在我身上,因为这样投影公式无效。只是不要以点z <= 0
的方式旋转对象。它是倒置的,因为公式 y = 1 / x 是关于原点点对称的。因此,对于
x <= 0
,则y
变为-y
。例如,1 / 2 = 1 / 2
,但是1 / -2 = - 1 / 2
。说到这一点,我想说你最好改变你的引擎,以便将值
z <= 0
映射到z = 1
(或其他东西)更小)。当然,尽管这是一个廉价的伎俩。可能有更有意义的技术。This also happened to me when points have a
z <= 0
, because then the projection formulas are invalid. Just don't rotate your object in such a way that points getz <= 0
.It's inverted because the formula
y = 1 / x
is point symmetric around the origin. So forx <= 0
theny
becomes-y
. E.g.,1 / 2 = 1 / 2
, but1 / -2 = - 1 / 2
.To come to the point, I'd say you'd be best off altering your engine so as to map values
z <= 0
toz = 1
(or something smaller). Though this is a cheap trick, of course. There are probably more meaningful techniques for this.