New demo project for beginning 3D

The default up vector of the camera command is 0,1,0, ie y up. The practical result is that height is along the y axis.

The official documentation for OpenGL says “By default, the camera is situated at the origin, points down the negative z-axis, and has an up-vector of (0, 1, 0)”.

Any number of explanatory web pages say the default for OpenGL is y-up. In fact, I can’t find any that say anything different. Are you saying that all of them have a misconception, too? Because I have not invented anything I have written - it all comes from explanations I have read.

Default camera makes sense if you use orthographic projection and emulate 2D inside a 3D world. Which is what Codea does with drawing primitives and sprites. With ortho, the distance from camera to objects doesn’t matter, and y axis pointing up feels natural.

However, as soon as you want to use the third dimension in a meaningful way, it is best to move the camera elsewhere, and orient it in such a way that (x,y) plane becomes “the ground” and z is pointing upwards - just as @LoopSpace suggested. Then the world coordinates of objects will make intuitive sense, i think.

I guess what i’m trying to say is that the choice of OpenGL default camera location and orientation might be odd ( it makes a better sense for 2D scene, than for 3D scene ), but the axis arrangement is fine. Feels intuitive.

(disclaimer: i’m actually neither a right-handed nor a left-handed person, and often have troubles figuring out which way to rotate a screw to tighten/loosen it :slight_smile: )

@LoopSpace, @juce -

I think the problem lies partly in mentally switching from 2D to 3D view.

And I think the key to seeing it as you have explained it, is to start in 2D, and to imagine that the XY plane is on the floor (and not vertical, as it appears to be in Codea), and that the camera is positioned overhead looking down, so everything is drawn flat on the floor.

When you switch to 3D, you add Z depth, so now you can move toward and away from the camera. But nothing else changes.

Now that explanation makes more sense to me. I’m sure it’s what you’ve been saying all along, but I think it’s much clearer when you put 2D into the same top down context as 3D.

I still don’t like the right handed option, though, because (as you have imagined it above) the y height axis runs along the floor instead of up and down, as in real life. And I’m sure for most people starting out in 3D, regardless of explanations, it takes some time to get used to making z values negative. So I do wonder why they chose it…

Anyway, thank you both for your patience. At last I feel I have something I can use to logically explain 3D axes, even if the rationale for them isn’t clear.

Yay! You’re nearly there!

and not vertical, as it appears to be in Codea

y only appears vertical to you because you are holding your iPad up in front of you. If you hold it flat, y will be forwards. So your decision to call y vertical depends entirely on how you are holding the iPad, and will differ for different people. If I’m lying on my side while coding, the y direction will actually be along the sofa and the x direction will be upwards. Should I then say that x is up? So the coordinate system of the viewer is unreliable and to be avoided. Better to use the coordinate system of the world where z is up, y is forwards, and x is right.

The right-handed convention for axes is pretty much universal. While it may not be obvious to you, and you may have found a few others on the internet for whom it is similarly confusing, the vast majority of programmers will be used to right-handed axes and all of the literature assumes right-handed axes so OpenGL would be seriously shooting themselves in both feet if they decided to go for left-handed coordinates.

And you do not have to make z values negative. There is no obvious default position for a camera in 3D, so the fact that OpenGL initialises it to where it is does not mean that the OpenGL designers think that that is where it ought to be. You are meant to think about your scene and place the camera where is best for that scene. If your game is a “top down” type of game, you would put the camera at something like (0,0,100) looking at (0,0,0) with (0,1,0) as “up”. If your game is a “player viewpoint” type of game, you would put it at (0,-10,0), again looking at (0,0,0), with (0,0,1) as “up”.

You should thus think of OpenGL’s default position as that they’ve left the camera lying on the floor with the lens pointing downwards (presumably to avoid getting dust on it). You are meant to pick it up and point it in the direction that you want. But only you can decide on where to put it and what direction to point it in.

@Ignatz I think I get it, the “up” value of 0,1,0 means that the top of the camera is pointing in the direction 0,1,0, which is sideways, and negative z, where you’re looking at, is actually down, it just appears like it’s straight forward. Here’s a poorly-made diagram to help:

Image

Turns out everything I’ve made in 3D was on its side! :open_mouth:

@SkyTheCoder - that’s exactly what I was thinking… :stuck_out_tongue:

I don’t play around with 3D that much, but I have a simple example with the camera values set at 0,0,200,0,0,0,0,1,0 . This means the camera is at 0,0,200 (x,y,z) looking at 0,0,0 with 0,1,0 ( y value up ). So +Y is up, -Y is down, +X is to the right, -X is to the left and +Z is behind me and -Z is in front. If I set 1,0,0 ( x value up ) +X is up, -X down, +Y is left, -Y is right and +Z is behind me, -Z in front. If I set 0,0,1 ( z value up ) Codea crashes. I haven’t figured out why yet. So with y up, it’s basically the + - values of graph paper used in geometry except the +z value would go forward instead of backward in geometry.

Codea crashes because the up value cannot be colinear with the line of view (line formed from position to origin)

Thanks @yojimbo2000. Saves me the trouble of trying to figure it out.

(takes a deep breath) so let me see if I get this one.

Dave’s example has the camera pointing toward -z, so the “line of sight” is along the z axis.

The camera could be rotated at any angle around this line, and that is what the “up” vector is for, to tell Codea which way the top of the camera is facing, while keeping the camera pointed along the z axis.

Since the line of sight is directly along the z axis, any rotation around this axis is at right angles to it, so the top of the camera is at right angles to z and cannot face it.

So setting z up in this case is an impossible request.

If it’s just a matter of changing which axis is up, I’m not clear why changing Z to up should cause a crash. Wouldn’t it be the same as X or Y being up and changing the axis labels.

EDIT:If I set both X and Y as up (1,1,0), the X and Y axis is rotated 45 degrees counterclockwise. Setting both X and Z or Y and Z as up has no affect. It’s the same as X up or Y up.

@dave1707 The camera can’t be looking in the same direction as its up value. OpenGL doesn’t know where to orientate the camera (specifically the yaw) so it just crashes.

@SkyTheCoder I think that makes sense. It will take time for me to try and visualize exactly what would be happening and see what’s wrong.

@dave1707 - imagine the camera has an arrow attached to the top, pointing up. Now aim the camera along the z axis, and at the same time, point the arrow back along z. Crash!

Thank you ignaz! I am new to codea but have coded In 2d elsewhere on khan academy. I tried to do 3D on khan academy but it was very hard because khan academy does not teach 3D much. On codea you teach the basics. Thank you