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
};
}
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 / xis point symmetric around the origin. So forx <= 0thenybecomes-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 <= 0toz = 1(or something smaller). Though this is a cheap trick, of course. There are probably more meaningful techniques for this.