3D Camera setup


I have a question about the 3D camera setup.

I want to put the camera behind the scene and look at 0, 0, 0.

I tried

	s3d.camera.pos.set(0, 0, 5);
	s3d.camera.target.set(0, 0, 0);

Now the camera is behind the scene like I wanted, but the view is horizontally rotated about 90 degrees.

Then I tried

            s3d.camera.up.set(0, 1, 0);

Now the camera is not rotated and it looks all right, but now the x axis is flipped (-x).
When I move a box with x += 0.01, then the box moves to the left instead to the right.

How should I set up the camera to look from behind (-z) to front without rotation and without flipping the x axis?


Héhé, i’ve asked myself the same question and did the same as you.

Here is what i’ve understood:

My conclusion: don’t mess with the up vector, and use the heaps coordinate system.

YMMV, because i’m crippled in mathematics, so i’m doing what i can. If i’m wrong, i’m curious to have the correct answer :slight_smile:


So you are telling me that Z is not front to back (depth) but it is up and down?

That makes sense. I wondered about this line of code in the base3D example

           // put it above the first cube
	obj2.z = 0.7;

That’s because all the 3D tools I’m using and the most 3D Engines have a X => horizontally, Y => vertically, Z => depth coordinate system.

That explains everything. Thank you very much.

Thank you for explaining me and for the nice drawing.


Yes, Z is up vector.

Blender also uses Z as up vector. I suspect 3D Studio is doing the same, and heaps has probably adopt the standard of its default tool.

We have grown accustomed to Z as depth with OpenGL and DirectX (and even before, i remember 3D tutorials on Amiga/ST were using Z as depth, probably because X,Y was «reserved» for 2D)
Even when you know that there are no standard for depth in coordinates systems, it’s a bit disturbing.


You are absolutely right. I think I need glasses. I opened Blender and moved the Cube up and the Z value changed. And I didn’t realize this for maybe two years … :innocent:


I have another question. I am trying to make a CameraController and I want to be able to rotate the camera upside down. But I don’t know how. I tried the cam.up vector, but it just rotates to 90 degrees.

And another question: is there another way to change the view of the camera than with cam.target ?

In my controller I rotate the target around the camera dependent on the mouse input. It work’s but I just want to know if it is possible to work without cam.target.

Thank you.

Found that:

This code chooses the camera’s right & up directions solely as a function of its look direction and a constant world up. Unfortunately because of the Hairy Ball Theorem, we can’t extend this to the whole sphere of possible directions: we always have a singularity somewhere (here, the poles at ±90°). So you’ll need to decide on a new policy for how to manage the camera’s twist, depending on the gameplay needs this camera fulfills. Try describing what you want to happen when the camera pitches past ±90° and we can suggest ways to achieve it