Author Topic: Y-Axis - Up-Vector - Confusion  (Read 3940 times)

Offline 3-S-E

  • byte
  • *
  • Posts: 6
    • View Profile
Y-Axis - Up-Vector - Confusion
« on: October 02, 2011, 04:56:01 pm »
Hi folks,

I have a big problem understanding the decision of making the pos. y-axis pointing downwards. This makes the whole thing totally counterintuitive for me even if this is a correct right-hand system. I've never used a 3D-creating app that turns the Y-axis this way and I think this makes the jpct engine unnecessary complicated.

Nevertheless...

I used the "Box-Primitive" code snipped from the wiki and applied a texture to it. The texture is placed upside-down. A texture applied to the bottom-part of the Box appears on the top of the box. So the "lower"-points are the upper ones, or what? Okay, so I tried to rotate my cam around the direction-axis by setting the up-vector from (0.0f, -1.0f, 0.0f) to (0.0f, +1.0f, 0.0f), but nothing happend.

I'm really confused... Can someone please give me a hint, what I don't understand at this topic?

Ciao

Edit: Setting the Y-axis pointing downwards is like climbing a 2 miles high mountain by digging a 2 miles deep hole!
« Last Edit: October 02, 2011, 05:14:07 pm by 3-S-E »

Offline 3-S-E

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Y-Axis - Up-Vector - Confusion
« Reply #1 on: October 02, 2011, 06:31:22 pm »
Okay, I figured it out by myself now.

My confusion is based on the modification I've made to the cube code-snippet:

Code: [Select]
public static Object3D getBox(float x, float y, float z) {
Object3D box = new Object3D(12);

SimpleVector upperLeftFront = new SimpleVector(-x, -y, -z);
SimpleVector upperRightFront = new SimpleVector(x, -y, -z);
SimpleVector lowerLeftFront = new SimpleVector(-x, y, -z);
SimpleVector lowerRightFront = new SimpleVector(x, y, -z);

SimpleVector upperLeftBack = new SimpleVector(-x, -y, z);
SimpleVector upperRightBack = new SimpleVector(x, -y, z);
SimpleVector lowerLeftBack = new SimpleVector(-x, y, z);
SimpleVector lowerRightBack = new SimpleVector(x, y, z);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1, upperRightFront, 1, 0);
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1, lowerRightFront, 1, 1);

// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0, lowerLeftBack, 0, 1);
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1, lowerLeftBack, 0, 1);

// Upper
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1, upperRightBack, 1, 0);
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1, upperRightFront, 1, 1);

// Lower
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0, lowerLeftFront, 0, 1);
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1, lowerLeftFront, 0, 1);

// Left
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0, lowerLeftFront, 0, 1);
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1, lowerLeftFront, 0, 1);

// Right
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1, upperRightBack, 1, 0);
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1, lowerRightBack, 1, 1);

// box.setTexture("base");
box.build();

return box;
}

My function takes three arguments and creates a box around the world-origin.
Because of the counterintuitive direction of the Y-axis and the need to insert a negativ value for the up-direction, I've used a negativ y-value as argument and flipped it inside the function...  :o

My question to the functionality of the cam-orientation function is still valid... :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Y-Axis - Up-Vector - Confusion
« Reply #2 on: October 02, 2011, 09:19:58 pm »
I agree that it's not a common coordinate system, but i never saw it causing real confusion. After all, it's much more intuitive than the (pretty common) z-axis goes up-system IMHO. jPCT's coordinate system is a right handed system, it's just rotated 180° around X to make the positive z-axis pointing into the screen. That's a decision that i made ages ago, when there was only the software renderer, which could benefit from this. After all, it's just wording and numbers...it really doesn't matter as long as you know how it is.

What exactly do you mean with

Quote
...by setting the up-vector from (0.0f, -1.0f, 0.0f) to (0.0f, +1.0f, 0.0f)

? Have you tried to assign new values to the vector that getUpVector() returned? In that case, this won't work. It's just a getter that returns a copy of the camera's internal state...you can't modify the vector to make the camera do something.

Offline stownshend

  • byte
  • *
  • Posts: 25
    • View Profile
Re: Y-Axis - Up-Vector - Confusion
« Reply #3 on: October 03, 2011, 04:32:36 am »
I too found it a little frustrating at first - but the reality is that modelling programs like 3DS Max have the +z axis pointing up as Egon mentioned before, so translating between different co-ordinate systems is just part of the business.

If you do have objects which exist in the +y up co-ordinate system you can rotate every object by PI / -2.0 along the X axis (Object3D.rotateX()) as you import it then it adjust it correctly (that's what I've been doing). This, of course, relies on object origins being in the "centre" of each object and only really makes sense if you're importing model files.

Offline 3-S-E

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Y-Axis - Up-Vector - Confusion
« Reply #4 on: October 03, 2011, 10:39:04 pm »
@Egon:

I've written my own CameraControl-Class, that aggregates the jpct-Cam and do all the translation- / rotation-tracking, storing, modifying fun. But that all starts with initializing the jpct-Cam, that goes something like this:

Code: [Select]
// Initialize camera object
this.cam = cam;
this.camPosition = camPosition;
this.cam.setOrientation(new SimpleVector(0.0f, 0.0f, 1.0f), new SimpleVector(0.0f, 1.0f, 0.0f));
this.cam.setPosition(this.camPosition);

... where "this.cam" is the jpct-Cam.
Point is: "setOrientation" does not have any effect at the "up-Vector" argument.
I could also write:

Code: [Select]
this.cam.setOrientation(new SimpleVector(0.0f, 0.0f, 1.0f), new SimpleVector(0.0f, 0.0f, 0.0f));
or

Code: [Select]
this.cam.setOrientation(new SimpleVector(0.0f, 0.0f, 1.0f), new SimpleVector(0.0f, -1.0f, 0.0f));
or

Code: [Select]
this.cam.setOrientation(new SimpleVector(0.0f, 0.0f, 1.0f), new SimpleVector(1.0f, 0.0f, 0.0f));
or whatever without any behavior-changes to the camera. What do I misunderstand here?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Y-Axis - Up-Vector - Confusion
« Reply #5 on: October 03, 2011, 10:59:52 pm »
No idea...it works just fine in my tests. Are you sure that you have this camera assigned to your World-instance?