What is the matrix equivalent to Camera.WorldToScreenPoint?
Hello,
I'm trying to perform Worldspace to Screen Space operations on a very large number of points. Unfortunately compute shaders are not an option as WebGL is one of the required target platform.
However in the meantime I'd like to use a threaded solution. Although this is not a WebGL supported feature either, it may well be in the future, even if distant. I will need to be able to use an alternative to Camera.WorldToScreenPoint and Camera.ScreenToWorldPoint as they are not thread-safe.
From what i could gather I'd be able to perform a similar solution by doing:
Matrix4x4 screen2World = Camera.main.projectionMatrix * Camera.main.cameraToWorldMatrix;
Matrix4x4 world2Screen = screen2World.inverse;
Vector3 point = new Vector3(123, 456, 789); // World space
Vector3 screenSpace = world2Screen.MultiplyPoint(point); // <-- I want to get the screen space point
/* Do something with the screen space point */
point = screen2World.MultiplyPoint(screenSpace); // Convert back to world space
However I am not getting the same results. Is there something I'm missing here?
Any help is much appreciated.
Answer by fguinier · Sep 30, 2015 at 09:03 AM
Hi JJJohan1,
At first glance this would be better :
Matrix4x4 world2Screen = Camera.main.projectionMatrix * Camera.main.worldToCameraMatrix;
Matrix4x4 screen2World = world2Screen.inverse;
Hope it helps :)
Florent
Your answer
Follow this Question
Related Questions
Calculation behind camera.ScreenToWorldPoint 1 Answer
Find a World Position Of an Object inside Canvas 0 Answers
Get the relative dimensions of two different canvases 0 Answers
c# RTS style snapping of game objects 0 Answers
Global direction (e.g. Vector3.forward, Vector3.right) from Mouse drag 0 Answers