Hey guys!
It seems I misunderstand unproject concept.
Lets say I have a camera at position (20, 0 ,0).
Then I’m creating new vector and unproject it from camera NDC:
THREE.Vector3().unproject(camera));
In this case I’m expecting this vector after unprojecting in world coordinates to have the same coordinates as the camera - (20, 0, 0).
But in reality it returns (18.000199980002, 1.1021943644760852e-15, 7.806019937778277e-16).
While Y and Z looks fine why X become 18, it is not looking like precision error?
I’m using the latest(134) but I also checked a few more versions and it works the same way there. I’ve found an interesting thing based on your advice:
when I unproject the camera inside the init function - it returns the vector (20, 0, -1.9998000199979997). (no clue why z is not zero here also)
but when I unproject camera inside animate function - it returns (18.000199980002, -1.2245243467126813e-16, -4.4404480536952556e-16) (I see some pattern here, since 20 - 1.9998000199979997 is equal 18.000199980002, but this computations and differences still make no sense to me)
I’ve found out that the camera near plane plays the crucial role in this calculations, so basically I was thinking of NDC as a basis with a center in the camera position but it ends up being more tricky thing
Great Find,
I always set Camera Near to small float close to zero. With Camera Near set to 0.0001, the formula return the correct coords. As to why 1 returns wrong data is beyond my paygrade.
I would consider this a bug!