Whether there is a method to calculate the world coordinate XYZ to the screen point XY coordinate in Babylon. For example, U3D’s camera.WorldToScreenPoint (obj.transform.position);
may be this will help
var coordinates = BABYLON.Vector3.Project(vector3,
BABYLON.Matrix.Identity(),
scene.getTransformMatrix(),
camera.viewport.toGlobal(
engine.getRenderWidth(),
engine.getRenderHeight(),
));
So this is supposed WorldToScreenPoint
Yo @Atul_Sharma … What about ScreenToWorldPoint … How we we do that ?
I think i found the answer: If world to screen to point is Vector3.Project … then Screen To World point must be Vecter2.Unproject
From @Deltakosh
var vector= BABYLON.Vector3.Unproject(
mousePosition,
engine.getRenderWidth(),
engine.getRenderHeight(),
BABYLON.Matrix.Identity(), scene.getViewMatrix(),
scene.getProjectionMatrix());
where mousePosition is the Vector2 with the screen X/Y coord you want to convert to world space
Right ???
Yes that is the right function but the first parameter is a vec3: you also need to provide a z value in screen space (value between 0 and 1).
Hi,
Is there any way to convert world points(in latitude and longitude) to screen point which is the path array for tube structure in react-babylonjs?
You need to convert longitude/latitude into cartesian coordinates.
Here’s the first link that appeared in Google:
@Evgeni_Popov could you please help me with another example?
You see a red pin, it is an indicator of object’s position in the world.
If you press UpArrow and move forward a little bit, red pin will be on top of screen, but must be on the bottom all the time(because object is behind us).
I think I should adjust matrices somehow, but I can’t figure out what I should change.
PS I have a game with objects on the XZ plane so I want to help players to rich objects in world.
You can try not to call ProjectToRef
but do the clipping in clip space yourself:
You will see you get some Infinity when the object is too far behind, but it seems the display is still ok.