Converting World coordinates to Screen coordinates in Three.js using Projection

There are several excellent stack questions (1, 2) about unprojecting in Three.js, that is how to convert (x,y) mouse coordinates in the browser to the (x,y,z) coordinates in Three.js canvas space. Mostly they follow this pattern: I have been attempting to do the reverse - instead of going from 'screen to world' space, to go from 'world to screen' space. If I know the position of the object in Three.js, how do I determine its position on the screen? There does not seem to be any published solution to this problem. Another question about this just showed up on Stack, but the author claims to have solved the problem with a function that is not working for me. Their solution does not use a projected Ray, and I am pretty sure that since 2D to 3D uses unprojectVector(), that the 3D to 2D solution will require projectVector(). You cannot convert (x,y) coordinates to (x,y,z) coordinates because you lose information. What you have quoted is how to find all points on all objects in the scene which intersect the ray generated by (x,y). The going from 'world to screen' as you request is what projection is all about, and is equivalent to rendering a single point (x,y,z). What you do is you apply the projection matrix to your point (x,y,z). It is presumably the Projector.projectVector(vector, camera) function at http://mrdoob.github.com/three.js/docs/49/#Projector , but due to the fact that it outputs a 3d vector, I can only assume that one of the dimensions is 0 and you can ignore it. Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified: April 22, 2016 @ 8:12 am