# OpenGL glMulMatrix Question

This topic is 3679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello Friends. i am confused with glMulMatrix argument. I know opengl uses column major oriented matrix. So if i have matrix like float A[16] = { xx , yx , zx , tx xy , yy , zy , ty xz , yz , zz , tz, 0 , 0 , 0 , 1 }; Is it ok to call like glMulMatrix(A) , or is i need to transpose ? Please help if anyone knows. Thanks KD

##### Share on other sites
That ordering looks correct.

##### Share on other sites
That looks right. There's more info here.

##### Share on other sites
Thanks all for the quick reply..

So in this case first rotation is applied and next is translation right ?
Is the order of mulitplication insided opengl is like following ?
MatrixCurrent = MatrixCurrent * A

where A is float A[16] = { xx , yx , zx , tx
xy , yy , zy , ty
xz , yz , zz , tz,
0 , 0 , 0 , 1 };

##### Share on other sites
Quote:
 Original post by kdworldSo in this case first rotation is applied and next is translation right ?

If you're considering transformations to be world-local as opposed to object-local, yes. Viewing that transformation as an object-local transformation, however, it would be seen in the other order.

##### Share on other sites
Quote:
 Original post by SneftelViewing that transformation as an object-local transformation, however, it would be seen in the other order.

I'm not sure what you mean. Could you please clarify?

##### Share on other sites
Okeydoke. This is important, so read it a couple of times and tell me if you don't fully understand it.

The key issue is what we mean when we say "transformation A followed by transformation B". That's not as unambiguous a phrase as you might think. For instance, suppose it was "Turn ninety degrees clockwise, then three units forward". But in whose frame of reference? If you told this to a driver of a car placed at the origin facing north, he'd first turn to face east, then head east a few units because that was "forwards" to him. If, however, you told it to a kid playing with a Hot Wheels car on the floor, he might instead turn the car east, but then push it forwards of him (so it ended up northwards of where it started, facing east). (This is the "grand, fixed coordinate system" from the book excerpt you posted.) These are both valid ways of describing an order of transformations, but they produce more or less opposite results. Therefore, it's important to say which convention you're using.

##### Share on other sites
Thank you for the detailed reply (I guess you thought I was the OP but that doesn't matter).

Actually I already understand all that stuff. What confused me (and still confuses me) was that your first reply suggests that in object-space, the translation will be performed before the rotation, while in world-space it will be in the reverse order.

In your second reply, however, you suggest that the difference is that the transformations will be performed with negative units (i.e., tranlate left instead of right, rotate clockwise instead of counter-clockwise), but in the same order.

So your replies seem to contradict themselves. Unless I misunderstood you?

##### Share on other sites
Quote:
 Original post by Gage64Thank you for the detailed reply (I guess you thought I was the OP but that doesn't matter).
Erm. Yes. Well. Oops.

Quote:
 Actually I already understand all that stuff. What confused me (and still confuses me) was that your first reply suggests that in object-space, the translation will be performed before the rotation, while in world-space it will be in the reverse order.
Correct.

Quote:
 In your second reply, however, you suggest that the difference is that the transformations will be performed with negative units (i.e., tranlate left instead of right, rotate clockwise instead of counter-clockwise), but in the same order.
Perhaps I used the word "opposite" too hastily. Note that the car always ends up pointing east, and forwards always at starts out being north. The "opposite" is ordering, not CW/CCW or positive/negative.

##### Share on other sites
Quote:
 Perhaps I used the word "opposite" too hastily. Note that the car always ends up pointing east, and forwards always at starts out being north. The "opposite" is ordering, not CW/CCW or positive/negative.

I just reread your example. Apparently I missed the most important part [smile] - the part about the car always facing in the same direction.

I think I understand what you mean. I think it is the same idea that is discussed in the red book, chapter 3, in the section "Thinking About Transformations". As far as I understand, your description is the conceptual way to think about it, but either way you think about it, the resulting transformation matrix is always the same.

For example, let's say I define two matrices, one for rotation and one for translation:

float R[] = {    r1, r2, 0, 0,    r3, r4, 0, 0,    0, 0, 1, 0,    0, 0, 0, 1,};float T[] = {    1, 0, 0, 0,    0, 1, 0, 0,    0, 0, 1, 0,    tx, ty, tz, 1,};

Then the OP's matrix is R*T. Because OpenGL uses column vectors, the transformed vertex is (R*T)v, which means that translation is applied first.

If you imagine that the transformations are occuring in world-space (that is, a "global" coordinate system that is fixed and is unaffected by any transformation), that's indeed how it works. But if you imagine that they are in object-space (that is, in a coordinate system that's local to the object and undergoes the same transformations as the object), then rotation is applied first, but obviously the matrix is the same matrix.

I guess what I don't understand is why you can interpret the resulting transformation in two different ways and it "works" either way you look at it.

EDIT: Another way to say this is that in both interpretations, the object conceptually undergoes different "steps" but the final position and orientation are the same, so how can one matrix represent two different sequences of transformations (even if they have the same end-result).

I'm also not sure how it will work with scaling, but that's a discussion for another day...

Sorry for the long post. I hope at least some of it makes sense. [smile]

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 10
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999987
×