// 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?
🔒 Locked
Matrix class syntax question...
Advertisement
Original Post
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?
I concur.
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
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
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?
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?
quote:
Original post by Glass_Knifequote:
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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement