Numa Posted April 17, 2016 Share Posted April 17, 2016 Hi there, I display labels (sprites) when I click on on objects in my scene. I'd like those labels to always be displayed top-left of the object I click on, regardless of the camera position. (I use an arcRotateCamera). How can I figure out what up/left is in camera space? Quote Link to comment Share on other sites More sharing options...
Numa Posted April 18, 2016 Author Share Posted April 18, 2016 Ok I scratched my head and a little and came up with this: ArcRotateCamera.prototype.CameraUpVector = function () { var xu = Math.cos(this.beta) * -Math.cos(this.alpha); var yu = Math.sin(this.beta); var zu = -Math.cos(this.beta) * Math.sin(this.alpha); return new BABYLON.Vector3(xu, yu, zu).normalize(); } ArcRotateCamera.prototype.CameraLeftVector = function () { var xl = Math.sin(this.alpha); var yl = 0; var zl = -Math.cos(this.alpha); return new BABYLON.Vector3(xl, yl, zl).normalize(); } It seems correct ArcRotateCamera has a .upVector but it's just set to the world's up hehe. Quote Link to comment Share on other sites More sharing options...
satguru Posted April 18, 2016 Share Posted April 18, 2016 see if this works var cameraMatrix = camera.getWorldMatrix(); var pos = camera.position; var cameraX = BABYLON.Vector3.TransformCoordinates(BABYLON.Axis.X, cameraMatrix).subtract(pos); var cameraY = BABYLON.Vector3.TransformCoordinates(BABYLON.Axis.Y, cameraMatrix).subtract(pos); var cameraZ = BABYLON.Vector3.TransformCoordinates(BABYLON.Axis.Z, cameraMatrix).subtract(pos); Numa 1 Quote Link to comment Share on other sites More sharing options...
Numa Posted April 18, 2016 Author Share Posted April 18, 2016 Yep that works too 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.