Jump to content

Vector3.unproject() strange behaviour


Tyrahell
 Share

Recommended Posts

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, 1

0, 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 ) :angry:

 

Am i doing something wrong ?

 

++Tyra :o Lost in spaces...

 

 

 

 

 

 

Link to comment
Share on other sites

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, 

Link to comment
Share on other sites

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 :P:D:lol:

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...