Y-Axis - Up-Vector - Confusion

Started by 3-S-E, October 02, 2011, 04:56:01 PM

Previous topic - Next topic

3-S-E

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!

3-S-E

Okay, I figured it out by myself now.

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

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... :)

EgonOlsen

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.

stownshend

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.

3-S-E

@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:


// 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:

this.cam.setOrientation(new SimpleVector(0.0f, 0.0f, 1.0f), new SimpleVector(0.0f, 0.0f, 0.0f));

or

this.cam.setOrientation(new SimpleVector(0.0f, 0.0f, 1.0f), new SimpleVector(0.0f, -1.0f, 0.0f));

or

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?

EgonOlsen

No idea...it works just fine in my tests. Are you sure that you have this camera assigned to your World-instance?