Numa Posted April 14, 2016 Share Posted April 14, 2016 Hi there, I believe that's how you go from world to screen coordinates: var screenPoint = BABYLON.Vector3.Project(worldPoint, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), camera.viewport.toGlobal(engine)); To go from screen to world I found the Unproject function, is there any example of how to use it? And do those functions take the camera radius into account? Quote Link to comment Share on other sites More sharing options...
Kesshi Posted April 14, 2016 Share Posted April 14, 2016 You can have a look at Scene.createPickingRay(). Its basicly a screen to wolrd transformation. Here is the code:https://github.com/BabylonJS/Babylon.js/blob/master/src/babylon.scene.ts#L2479 At the end Ray.CreateNew() is used which uses the unproject function:https://github.com/BabylonJS/Babylon.js/blob/master/src/Culling/babylon.ray.ts#L282 Quote Link to comment Share on other sites More sharing options...
Numa Posted April 14, 2016 Author Share Posted April 14, 2016 Ok thanks I'll have a look! Quote Link to comment Share on other sites More sharing options...
FlashyGoblin Posted April 14, 2016 Share Posted April 14, 2016 Here is an example of getting the 3D position of your scene from where you click your mouse on the canvas area. Hope it helps. canvas.addEventListener("pointerdown", function (evt) { var pickResult = scene.pick(evt.clientX, evt.clientY, function (mesh) { return mesh; }); if (pickResult.hit) { console.debug("3D position", pickResult.pickedPoint); } }, false); Quote Link to comment Share on other sites More sharing options...
Numa Posted April 16, 2016 Author Share Posted April 16, 2016 It looks like sprites don't get hit by rays? (open console to see logs) http://www.babylonjs-playground.com/#EVYAT edit: I found pickSprite but it doesn't return the hit point hehe. All I want to do is draw a line from a point on a sprite to the center of the scene. How do I get that point on the sprite converted to the 3d world? I've got a feeling I'm missing something really obvious. Quote Link to comment Share on other sites More sharing options...
iiceman Posted April 16, 2016 Share Posted April 16, 2016 Hi there, you can use pickResult.pickedSprite.position, but since the sprites are always squares it looks a bit weird. Maybe you are better of with using planes? http://www.babylonjs-playground.com/#EVYAT#1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 16, 2016 Share Posted April 16, 2016 You are not forced to have squared sprites: http://www.babylonjs-playground.com/#EVYAT#2 iiceman and Numa 2 Quote Link to comment Share on other sites More sharing options...
Numa Posted April 16, 2016 Author Share Posted April 16, 2016 2 hours ago, Deltakosh said: You are not forced to have squared sprites: http://www.babylonjs-playground.com/#EVYAT#2 !!!!!!!!! that's what I meant by " I've got a feeling I'm missing something really obvious" ahah :facepalm: :facepalm: THANK YOU! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 17, 2016 Share Posted April 17, 2016 No problem, this is why we have a forum Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.