Skip to main content
gamedev.net
🔒 Locked

[java] Possible non array matrix

Started by Lucidquiet 5 replies 450+ views
Original Post
Lucidquiet
Lucidquiet
I'm thinking about making a few matrix classes in Java. The thing I was contemplating was making the matrix representation nothing but public member variables in the class. So for instance:

public Matrix4D
{
   public float m11, m12, m13, m21, m22, m23, m31, m32, m33;
}//  And that's pretty much all she wrote

public Matrix3D
{
   public float m11, m12, m21, m22, m31, m32;
}

I don't know if the AffineTransformation already implements a matrix this way, I'm geussing it doesn't, for 2 reasons. 1 being that it might assume the last column to be [0 0 0 1]' And it might use an array for the variable storage. I have to admit that I haven't done too much 2D or 3D programming, so I can't think of a reason right now not to do it the way I just mentioned. But I'm writing this to get some one else's ideas and comment, if they have experience programming 2D and 3D stuff. Thanks, L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
capn_midnight
capn_midnight
AffineTransform is only a 3x3 matrix, which is only suitable for 2D graphics.

Yes, it assumes the last ROW is [0 0 1]

As for what it uses for storage, most probably an array.

With an array, all of the elements of the matrix will be in contiguous memory locations. Not necissarily true for just member variables, and becomes less likely the longer the program runs.
Lucidquiet
Lucidquiet
Thanks Capn', I'm reading a book on 3D math -- sort of math primer, and there is code in their for how the C++ matrix class (of their design) is implemented. I didn't know this when I posted, but they did do it the way I put in the above code. And for 3D I would need to extend the matrix to a 4x4, I forgot to add that. It surprised me, but then again as a Primer who can say if it's as good as production code?

Thanks,
L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Lucidquiet
Lucidquiet
I just looked, and the affine transformation does hold the data as above in the original code. Except it starts with m01, and not m11. Also the member variables are double, not float? Go figure?

Thought I would pass that along,
L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
capn_midnight
capn_midnight
Quote:
Original post by Lucidquiet
I just looked, and the affine transformation does hold the data as above in the original code. Except it starts with m01, and not m11. Also the member variables are double, not float? Go figure?

Thought I would pass that along,
L-
you really shouldn't ever use float. In fact, you have to explicitly say that you are trying to use float. "float f = 2.0;" won't work, you have to append an 'f' at the end of the number. Doubles are pretty much the only way to go. You have no idea how many times I have fixed MAJOR problems in code by just switching to doubles instead of floats.
Lucidquiet
Lucidquiet
I don't get it. What is the problem with floats?

L-

Other than having to explicitly initialize floats with the 0.0f or whatever -- is it that literal floats are causing miss compilation or something like that?
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Raghar
Raghar
My lastest experience with floats was 10 slower code for some reasons. Doubles are SSE2 accelerated, and MUCH more precise, and I like them more. If you are not bandwith limited you should use doubles. (It's not as big difference with speed) If you are really speed limited, you might use integers. Happy rounding.

One person said, if you could make circle with floats...
(I made a circle with up to 1 ulp precision of sin and doubles so he should send me a bridge, but I didn't told him about that. ^_^)

Topic Locked

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

Sign in to reply to this topic.