Jump to content

translate object up/down/left/right in camera space


Recommended Posts

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?


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);


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.

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...