Tyrahell Posted September 8, 2014 Share Posted September 8, 2014 Hello everybody, After some time dealing with Vector3.unproject(), i got serious doubt about my way to use it. I try to unproject a screen vector (1,0,0) to a world coordinate vector and the result of unproject() is always the same even if the ViewMatrix or WorldMatrix is changing. Here is my code :var pMScene = myScene.getProjectionMatrix();var vMScene = myScene.getViewMatrix();var wMCamera = myScene.activeCamera.getWorldMatrix();var globalView = myScene.activeCamera.viewport.toGlobal(engine);var ViewportWidth = globalView.width;var ViewportHeight = globalView.height; var screenVector = new BABYLON.Vector3(1,0,0);var worldVector = BABYLON.Vector3.Unproject( screenVector, ViewportWidth, ViewportHeight, wMCamera, vMScene, pMScene );My projection Matrix is constant : 1.6, 0, 0, 0,0, 2.4, 0, 0,0, 0, 1, 10, 0, -0.1, 0 My viewMatrix depends of the scene view, quite logical, same for the worldMatrix depending from the camera fov. My viewport seems correct : width = 1200, height = 900. And my unprojected vector (1, 0, 0) is always (-0.051, 0.042, 0.1 ) Am i doing something wrong ? ++Tyra Lost in spaces... Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 8, 2014 Share Posted September 8, 2014 Hi, Can you try by using this : var wMCamera = BABYLON.Matrix.Identity();Anyway, what are you trying to do ? You have an example of creating a picking ray here, maybe that can help : Scene.prototype.createPickingRay()Cheers, Quote Link to comment Share on other sites More sharing options...
Tyrahell Posted September 8, 2014 Author Share Posted September 8, 2014 Well, im trying to express a screen unit vector into a world vector to translate my geometry Does unproject() seems to be the way to go ? ++Tyra Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 8, 2014 Share Posted September 8, 2014 You are right unproject is the good way to do that:) But if you want to unproject into world, the world matrix must be set to identity. You have to use it if you want to unproject into a mesh local world. Tyrahell 1 Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 9, 2014 Share Posted September 9, 2014 Here is a solution, what do you think about it ? var pMScene = scene.getProjectionMatrix(); var vMScene = scene.getViewMatrix(); var wMCamera = BABYLON.Matrix.Identity(); //scene.activeCamera.getWorldMatrix(); var globalView = scene.activeCamera.viewport.toGlobal(engine); var ViewportWidth = globalView.width; var ViewportHeight = globalView.height; var screenVector = new BABYLON.Vector3(0,0,0); var screenVector2 = new BABYLON.Vector3(1,0,0); var worldVector = BABYLON.Vector3.Unproject( screenVector, ViewportWidth, ViewportHeight, wMCamera, vMScene, pMScene ); var worldVector2 = BABYLON.Vector3.Unproject( screenVector2, ViewportWidth, ViewportHeight, wMCamera, vMScene, pMScene ); var res = worldVector2.subtract(worldVector); res.normalize(); box.locallyTranslate(res);Cheers, Tyrahell 1 Quote Link to comment Share on other sites More sharing options...
Tyrahell Posted September 9, 2014 Author Share Posted September 9, 2014 Temechon and DK your awesome ! Thanks to you i can now design my own arcrotatecamera with translation on right-clic like CAD software ! Ill publish some code sample for the community when it will be over I close this topic and go back to the other one to finish my arcrotatecamera with translation! Thanks thanks thanks Temechon 1 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.