3D Camera setup [SOLVED]


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: