Ok, since it was rather painless port of my old code, I created an extended
class the Matrix4d, that basicly adds the compound transform functions
attached to this email as Matrix4dPipe.java. This should be a good solution
for now, until Java3D incorporates something similar.

But here is its usage in simplest form...

    Matrix4dPipe mat = new Matrix4dPipe();
    mat.setIdentity();
    mat.Translate(0,-0.5,0);
    mat.Rotate(1,0,0,1.571);
    mat.Scale(0.005,0.005,0.005);
    Transform3D trans = new Transform3D(mat);
    TransformGroup objTranslate = new TransformGroup(trans);

That is your typical matrix order transforms (scale first, rotate next, and
translate last), nothing special there, BUT here is what requires less code
then the Java3D equivalent...

    Matrix4dPipe mat = new Matrix4dPipe();
    mat.setIdentity();
    mat.Rotate(1,0,0,1.571);
    mat.Scale(0.005,0.005,0.005);
    mat.Translate(0,-0.5,0);
    Transform3D trans = new Transform3D(mat);
    TransformGroup objTranslate = new TransformGroup(trans);

Translating before you rotate, is not something easy to achieve in Java3D,
its not that its hard it just takes more lines of code (I posted early on
this mailing list) to achieve in Java3D, and requires matrix multiplication
while this code handles everything for you. Also included is an FastInverse
function, which does an Inverse for Orthogonal matrices but if there is any
sheering it will not do an inverse of that, I dont think Java3D does any or
function with Sheering anyway so dont worry. This is a nice function if for
example you need to add transformation to the other side of the pipeline or
you want to work backwards (the first transform applied is the first
transform applied to the object) you can reverse the matrix.

I have not done full testing of this port, but I did a test and it seems
fine, and there is no restrictions or license for the use of this code its
free as in completely free, if I ever get a chance I will create a small
website and toss it in there, if no one else does it.

Some things it needs, is maybe a JNI to take advantage of 3DNow and/or SSI. I
have 3DNow code for doing these functions some where, but I dont think I want
to spend the time creating a JNI for it right now. The other thing it needs,
is oposite functions, for applying the transforms on the other side of the
pipe with out having to call the FastInverse function, it should not be to
hard to create this (just copy paste and rename a number of things).

Anyway have fun.

MATRIX~1.ZIP

Reply via email to