Isn’t Z up?

X and Y have always represented the axis in a plane. To me, when you added a third dimension, it was like stacking planes on top of each other. As you stack more and more planes upon each other, they grow in height. Therefore, it was natural for me to view Z as pointing upward.

Turns out, Z represents depth. In other words, if you imagine your screen as representing the X,Y plane, then Z extends into or out of your screen. It always has, and I always knew it did, but I still thought of Z as pointing upward in a 3D environment – it just made more sense to me.

This was never a problem until I went to program a camera class for the volume rendering I’m working on. A camera is pretty simple – you need three vectors – the camera’s location, the target’s location and a vector representing up (so you can orient the screen properly). Usually you store two angles and a radius instead of (or in addition to) the target’s location so you can easily change them. I figured, “this problem has already been solved plenty of times – I’ll just find some code to guide me so I don’t make any stupid math mistakes when translating from math to code.”

That was the start of the problem. I found a nice solution, and it was in C# for XNA too, but when I hooked it into my code, it didn’t show anything. Oh, I had a nice CornflowerBlue screen, but that was it. After some hunting, I found out that my camera thought that Y pointed up. So did XNA’s Vector3.Up.  Weird.  So, I tried to fix it.

I emphasize that because of what I did: I tried to fix code that I didn’t fully understand.  I knew how a camera worked, but I thought this code would save me some time, so I didn’t bother to figure out exactly how this code was doing it.  I ended up wasting a few hours messing around until I finally just recoded the whole thing myself.

So, lesson learned: if you’re going to use code someone else has written, make sure it fits your requirements, and if it doesn’t, make sure you understand what’s going on so you can fix it.  I still think Z should be up, and it is in my camera, but it makes it hard to use others’ code.  That’s good for me though – I’m still learning a lot, and I should be making things myself for the time being.

One Response to “Isn’t Z up?”

  1. bazawitryn Says:

    Articulately maintained and respected trap directory. Rid admittance and moderation. Enlarge your relation and you wish caress the power of our directory. do gazu!

Leave a Reply