Jump to content

Z-axis pointing up


Recommended Posts


I've started porting my PlayCanvas-based project to BABYLON.js, but I seem to be stuck on a fairly basic thing - I cannot figure how to convince the engine that in my scene, the up axis is not Y, but Z.

Basically I'm looking for the BABYLON equivalent of the following code:

var camera = new pc.Entity();
g_camera = camera.addComponent("camera", {
    clearColor: new pc.Color(zoneData.bgColor[0], zoneData.bgColor[1], zoneData.bgColor[2])

var cameraDist = 10;

// look at [0 0 0] from [-1 -1 1]*cameraDist to get a Diablo-style view
// [0 0 1] points up
var camVec = new pc.Vec3(-1, -1, 1);
camVec.scale(cameraDist / camVec.length());

var camLookAt = pc.Vec3.ZERO;
var camUp = new pc.Vec3(1, 1, 1);

camera.lookAt(camLookAt, camUp);

// later on - translate camera to follow the player


I wouldn't mind using ArcRotateCamera if I can get it to work.

I tried setting camera.upVector, but that just ended up distorting the view.

Then I tried the following dirty hack, but that didn't do the job either (no errors, but nothing is displayed)

(<any>camera)._camMatrix = BABYLON.Matrix.Zero();
BABYLON.Matrix.LookAtLHToRef(camVec, camLookAt, camUp, (<any> camera)._camMatrix);

Thanks for any help.

Link to comment
Share on other sites

Part of what I had done wrong was setting upVector to the "correct" [1 1 1].normalize() instead of simply [0 0 1].

However, as you can see in the playground I linked, the view is still not quite correct - it's shifted the right and looks slightly tilted. What would be the right way to fix that?

Link to comment
Share on other sites

Well crap, thought I wasn't asking that much.

Chaging to Y-up would mean not only rotating all the models, but also their placement, and also all logic dealing with entities' position, rotation and so on. The codebase is not that small.

Is it possible to transform the entire world except the camera? That would do without changing everything.

Link to comment
Share on other sites

On 4/11/2016 at 7:56 AM, dbawel said:


Could it be that you exported from a Z axis up application?

All our assets, as well as the server software, are built as Z-up. I intend to keep it that way, not just because the work involved in changing everything, but because Z-up is really the only system that makes sense to me in any non-trivial 3D world.


On 4/11/2016 at 11:20 PM, Deltakosh said:

@minexew: I'm interested by what you changed in the ArcRotateCamera. Perhaps we can integrate your changes?

I did it in a rather hacky way, implementing only the absolute minimum needed. However, if you're interesting in merging this, I can look into developing a proper patch.


Thanks for all the help.

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