Jump to content

Bounding box display


Recommended Posts

  • 2 weeks later...

It is what I was looking for, thanks @Nico, unfortunately I found a bug. I modified the jsfiddle to show the bug:




I noticied that the following line gives weird results whereas if you unzoom, the bug doesn't appear anymore and the results are correct:

screenCoordinates = BABYLON.Vector3.TransformCoordinates(screenCoordinates, camera.getProjectionMatrix());

Here are my results:


no bug: for i=1 screenCoordinates = (-16.69; -1.59)

no bug: for i=7 screenCoordinates = (-12.74; -4.94)


bug: for i=1 screenCoordinates = (15.33; 1.46)

bug: for i=7 screenCoordinates = (21.43; 8.31)


For the other i values, results for "bug" and "no bug" do not really change whereas for i=1 and i=7, negative values become positive values.


I found in the code the funciton BABYLON.Vector3.Project, I guess we could use it to replace:

var screenCoordinates = BABYLON.Vector3.TransformCoordinates(mesh.getBoundingInfo().boundingBox.vectorsWorld[i], camera.getViewMatrix());screenCoordinates = BABYLON.Vector3.TransformCoordinates(screenCoordinates, camera.getProjectionMatrix());        var objectScreenPosition = new BABYLON.Vector2(screenCoordinates.x * (canvas2D.width / 2) + canvas2D.width / 2, canvas2D.height - (screenCoordinates.y * (canvas2D.height / 2) + canvas2D.height / 2));

but I didn't manage to use it correctly.

Link to comment
Share on other sites

Now the maths are correct :)




These two articles were really helpful http://stackoverflow.com/questions/3329308/perspective-projection-how-do-i-project-points-which-are-behind-camera



The issue was due to the fact that some summits of the bounding box can be behind the camera.

Edited by gwenael
Link to comment
Share on other sites

  • 4 weeks later...

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.

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.


  • Recently Browsing   0 members

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