Skip to main content
gamedev.net
🔒 Locked

Matrix class syntax question...

Started by Glass_Knife 8 replies 700+ views
Original Post
Glass_Knife
Glass_Knife
I was wondering if there is a certain way an experienced graphics programmer would expect a Matrix class to work. I have been working on one, but I''m stuck on the syntax of the class. What would you expect the folowing line to do?

   // matrix1 and matrix2 are some kind of Matrix
   matrix1.mul( matrix2 );
 
If I saw code like this, I would not be sure which matrix is altered. If you saw this same code, is matrix1 being multilied by matrix 2, or the other way around? Is there even an expected way, or is it API dependent? Glass_Knife I think, therfore I am. I think?
Fruny
Fruny
matrix1 *= matrix2 would be unambiguous.

Make sure that matrix1.mul(matrix1); is handled correctly.

[edited by - Fruny on January 2, 2004 11:42:06 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Palidine
Palidine
overload the * and *= operators so you can do things like

Matrix m3 = m1 * m2;

or

m1 *= m2;

that''s the way I do it and have most often seen it done. the good thing about that way is that the order of operations is very clear. for function type multiplies of the form m1.mul(m2) is is _always_ understood that m1 is being post multiplied by m2 and the result stored in either m1 or a return from that function call like:
( Matrix m3 = m1.mul(m2) ). all in all, i''d go with overloaded operators as i find them much more clear.

-me
Glass_Knife
Glass_Knife
quote:
Original post by Fruny
matrix1 *= matrix2 would be unambiguous.



I am sorry, but I didn''t mention that this is a Java thing, and not a c++ thing. I would love to overload stuff, but alas... I cannot



Glass_Knife
I think, therfore I am.
I think?
Fruny
Fruny
In that case you should use the same conventions as the java numeric types do.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
hplus0603
hplus0603
Arguments to functions are typically const references. Thus, the left matrix would be affected.

The next question is whether you''re using pre-multiply or post-multiply. And whether you''re row-major or column-major. :-)
enum Bool { True, False, FileNotFound };
Glass_Knife
Glass_Knife
quote:
Original post by hplus0603
Arguments to functions are typically const references. Thus, the left matrix would be affected.

The next question is whether you''re using pre-multiply or post-multiply. And whether you''re row-major or column-major. :-)


I have no idea what pre-multiply or post-multiply are? As for the row-major or column-major, I''m assuming you mean are my vectors a 3x1 or a 1x3. My vectors are a 1x3, so I am doing it like this...

vertor = matrix( vector );

So i have 1x3 * 3x3 = 1x3... at least I think this is right. It is amazing to me how complex this stuff get when you peel away a layer or two and look at it a little more closly...



Glass_Knife
I think, therfore I am.
I think?
owl
owl
quote:
Original post by Glass_Knife
quote:
Original post by Fruny
matrix1 *= matrix2 would be unambiguous.



I am sorry, but I didn't mention that this is a Java thing, and not a c++ thing. I would love to overload stuff, but alas... I cannot




What do you mean? You can do that in c++ as well.

EDIT: Oh, I see, "your" thing is in java. never mind then.

[edited by - owl on January 2, 2004 12:07:58 AM]
[size="2"]I like the Walrus best.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.