Xith3d progress

[quote]its not heading in the direction of the new rotation tranform. it just keeps heading into z, with the object spining around itself without a care.

i would like it to move in the direction of the rotation. and then on the next update just tell the transform to move in z a little bit more. and because the rotation vector has changed - it heads off in that new changed direction.
[/quote]
But, looking at your example code you only have one translation followed by one rotation… If you only ever adjust the Z coordinate of the translation then rotate after that you will never move along anything but the Z axis.

To move the object in the direction of the heading. you will need to rotate the vector that you are adding to the translation vector.

E.g. the code way above always adds 0,0,-5 to the translation vector. that is assuming the heading is always 0,0,-1 (normalized vector heading into the monitor along the z axis)

If you want to move the ship in the direction of the heading you must take the 0,0,-5 vector, rotate it by the same rotation as the ship heading, then add it to the translation. That way you will change the x,y coordinates of the object not just the z coordinate. E.g. don’t always move along the z axis, because unless you are also rotating before your transform that will appear as the object following a straight line, regardless of how the object is oriented.

Draw the movements on a piece of graph paper…

if you have


-z
|              b
|
|
|                              c
|
|
| a
--------------------------+x

and you want the object to travel from a to b, then from b to c,
your translation can’t add just to the z coordinate… you are moving along the +ve x axis as well. You need to rotate the 0,0,-1 vector so that it points toward ‘b’ before adding it to the current translation that got you to point ‘a’. then when you reach point ‘b’ you would need to change the 0,0,-1 vector to point parallel to the line bc before adding it to the current translation.

If you want to keep your translation as holding the world coordinates of the object, you must rotate the velocity vector
that you are adding to the position (translation) vector. It sounds as if you are mixing polar coordinates in with this and getting into a messy chain of translations and rotations

 Transform3D tempTrans = new Transform3D();
  Transform3D ourTrans = new Transform3D();
  hellcat_group_trans.getTransform(ourTrans);
  tempTrans.rotXYZ(updown, 0f, leftright);
  // tempTrans.rotZ(leftright);
  tempTrans.setTranslation(new Vector3f(0.0f, 0.0f, -1f));
  ourTrans.mul(tempTrans);
  hellcat_group_trans.setTransform(ourTrans);

done it… only need one group… and u need to get and add to the transtation :).

Well, yes and no :slight_smile:

You basically worked around what could be a bug. You are concatonating the rotation and translation matrix yourself. What you did there should be identical to having a nested transform.

I am still going to investigate the possibility of a bug in Xith3d here.

nice one dude :slight_smile:

ok how do i set the near far clipping plane of the view?

<- doing more action…

[quote]it seems to reset evey time
[/quote]
In six words, I think that describes my exact problem too :slight_smile:

[quote] You basically worked around what could be a bug. You are concatonating the rotation and translation matrix yourself. What you did there should be identical to having a nested transform.
[/quote]
David, thanks for looking into it I shall boil my code down to a small test case and get it to you today hopefully.

If it’s a bug i’m quite surprised you wouldn’t have found it when porting Cosm. Is that game up and running yet?

Cheers,

Will.

I have emailed David, but for anyone else who is interested, my test case is here:

http://tanksoftware.com/dev/xith-test-case01.zip

here is the problem code:


       public void turn (float angle) {
             
            // convert to radians
            angle = (float)((angle) * Math.PI / 180.0);
            
            // angle of rotation
            Transform3D angleTrans = new Transform3D();
            angleTrans.setIdentity();
            angleTrans.rotAxis(new Vector3f(0f,0f,1f), angle);

            //distances to origin
            float xDis = -10;
            float yDis = -10;
            float zDis = 0;
            
            // move transform moves to origin
            Transform3D move = new Transform3D();
            move.setIdentity();
            move.setTranslation(new Vector3f(xDis,yDis,zDis));
            
            // move back transform - oppsotie of move transform
            Transform3D back = new Transform3D();
            back.setIdentity();
            back.setTranslation(new Vector3f(-1 * xDis,-1 * yDis,-1 * zDis));

            
            
            Transform3D t3 = new Transform3D();
            geomRoot.getTransform(t3);
            
            t3.mul(move); //move cube to origin
            t3.mul(angleTrans); //rotate
            t3.mul(back); //move back in it's rotated state
            
            geomRoot.setTransform(t3);
            

            
      }

geomRoot is a TransformGroup containing said cube loaded from the ASE loader.

Cheers,

Will.

As far as I understand transforms, rotating and then multiplying by reverse translation will not get you back to origin, because translation will be already applied to turned transform. I think that you need to transform reverse translation by 2nd stage matrix and then apply it as third stage - this way, you should be back at zero.
But I don’t think you will get what you want - I do not think it is possible at all. To achieve what you want, you would need few stage transform, which is applied to every point in order, at each stage using already x,y,z from this stage (not from original point as it is with multiplied transforms).

My suggestion - center you shapes around 0 :slight_smile:

view.setBackClipDistance(10000f);

dont seem to do anything…

I will take a look at the file you sent me. Also, the clips are not being set from the view settings, that is a bug.

I have almost completed the terrain system for Xith3d. I will be posting it within a couple of days.

sweet!!!

abies,

What I am trying to achieve is definitally possible. I have done it both in OpenGL (GL4Java) and j3d. Centering the object before loading it is the work around which I can do however it should be possible not to have to do it that way and since I have sunk so much time into trying I will not quit untill I have found how to do it in Xith3d.

Here is code that worked in j3d. If you don’t believe me I can send you the entire source.


            /**
             * Rotate around the X and Y axies
             */
            public void tiltXYAxis (float angleXAxis, float angleYAxis) {
                  
                  Transform3D angle = new Transform3D();
                  Transform3D orig = new Transform3D();
                  Transform3D back = new Transform3D();
                  Vector3d tmpVector = new Vector3d (3.6,3.5,0); //set rotation reference point

                  Transform3D t3d = new Transform3D();
                  geomRoot.getTransform(t3d);
                  
                  orig.setTranslation(tmpVector); // reference point translation
                  back.invert(orig); // inverse reference point
                  
                  // angle rotation
                  angle.setRotation(new AxisAngle4f (1f,0f,0f,(float)((angleXAxis) * Math.PI / 180.0)));
                  angle.setRotation(new AxisAngle4f (0f,0f,1f,(float)((angleYAxis) * Math.PI / 180.0)));
                  
                  t3d.set(initt); // move to starting location (which is not (0,0,0)
                  t3d.mul(orig); // apply move to origin
                  t3d.mul(angle); //rotate
                  t3d.mul(back); // move back
                  geomRoot.setTransform(t3d);
                  
            }

geomRoot is a TransformGroup. A note that in this program I use x,y,z from a top down perspective - ie. substituting z and y. This makes more sense for this app as it is a top down view and z is best suited for height. Just personal preference however it doesn’t effect the actuall code at all.

Xith3d doens’t have a setRotation(AxisAngle4f) method however I found a way to substitute that using the methods it does have.

Perhaps my test case is not 100% correct but it should be possible.

Cheers,

Will.

Well, I have checked it at home and it indeed seems to be possible to rotate around arbitrary point. Mea culpa.

In your second example
angle.setRotation(new AxisAngle4f (1f,0f,0f,(float)((angleXAxis) * Math.PI / 180.0)));
angle.setRotation(new AxisAngle4f (0f,0f,1f,(float)((angleYAxis) * Math.PI / 180.0)));

First line has no effect ? AFAIK setRotation replaces transform rotation component instead of multiplying it ?

abies,

I think you are right about the first line - it probably does squat. Since i never actually rotated anything around the X axis in this particular program I never noticed the bug. Thanks :).

David,

Thank you for looking at my test case.

Incidentally is there any reason why setRotation(AxisAngle4f) was removed from the API?

For anyone that did use it - here is a little static method that I have used to replace it:


      // replacement for Transform3D.setRotation(AxisAngle4f)
      // t.setRotation(new AxisAngle4f (1f,0f,0f,angle));
      // becomes
      // Object3D.setRotation(t, new Vector3f(1f,0f,0f), angle);
        //
      public static void setRotation(Transform3D trans, Vector3f axis, float angle) {
            
            // Gets the rotation matrix
            Transform3D rotation = new Transform3D();
            rotation.rotAxis(axis, angle);
            Matrix3f rotationMatrix = new Matrix3f();
            rotation.getRotation(rotationMatrix);
            
            // Applies rotation matrix to passed Transform3D  in a non destructive manner
            trans.setRotation(rotationMatrix);      
            
      }

new cvs - all complied and stuff.

but still Background dont seem to work :(. or maybe i am using it wrong… also view.setBackClipDistance(50000f); dont seem to do anything :)…

maybe i is testing updates to fast - hehehe…

keep on rolling the rock dudes

also i seem to find the shading is abit FLAT. As u can see from my screen shot. my Hellcat is compleatly blue at some angles:

http://www.topresultmate.com/jogl/hellcolor.jpg

can i change this someplace?

Could it be the normals? I’m not sure how Xith3d deals with them but I know that the shading can go haywire using OpenGL if all the normals are pointing in the same direction which could be one reason for that effect. What format is the model in?

Will.

Or it could be the total lack of supports for lights :slight_smile: Looks like I better get that done!

I think I found that pesky rotation bug :smiley:

From the Xith3d source:


    /**
     * Sets the rotation by replacing the upper 3x3 matrix values of
     * this transform with the values in the Matrix3f m. The other
     * elements of this transform are unchanged.
     */
    public final void setRotation(Matrix3f m) {
        matrix.set(m);
    }

From the javax.vecmath.Matrix4f javadocs:


set(Matrix3f m1)
          Sets the rotational component (upper 3x3) of this matrix to the matrix values in the single precision Matrix3f argument; the other elements of this matrix are initialized as if this were an identity matrix (i.e., affine matrix with no translational component).

The conflict is that Xith3d claims NOT to be reseting the other elements but the javax.vecmath IS reseting it.

I tried various things to correct this problem in com.xith3d.scenegraph.Transform3D - but then saw this in the docs: again from javax.vecmath.Matrix4f


setRotation(Matrix3f m1)
          Sets the rotational component (upper 3x3) of this matrix to the matrix values in the single precision Matrix3f argument; the other elements of this matrix are unchanged; a singular value decomposition is performed on this object's upper 3x3 matrix to factor out the scale, then this object's upper 3x3 matrix components are replaced by the passed rotation components, and then the scale is reapplied to the rotational components.

Using setRotation instead of plain set - I changed the method in com.xith3d.scenegraph.Transform3D:


    /**
     * Sets the rotation by replacing the upper 3x3 matrix values of
     * this transform with the values in the Matrix3f m. The other
     * elements of this transform are unchanged.
     */
    public final void setRotation(Matrix3f m) {
        matrix.setRotation(m);
      
    }

And that seemed to fix the problem :smiley:

This explains why aNt had to have a tree of TransformGroups to do his rotation stuff - and why I had to do the same with my scaling (which I wanted only to set once). The reason it would work with the nested TransformGroups - is that how the scenegraph works out the final single matrix is it multiplies them all up nullifying the effect that setRotation had by setting the identity.

With the fix applied you don’t need these extra TransformGroups. I tested this on my code and could successfully remove the nested TG in question, and it still worked exactally the same (which is better - as I didn’t think nested TG’s were nessesary, afterall OpenGL doesn’t have this concept and only has a single transform matrix). Basically anything you can do with a TransformGroup inside a TransformGroup you should be able to do with just the one I think - not that that changes the fact that TransformGroups are still very usefull.

David - if you are happy with the bug fix, could you please patch the CVS source (I havn’t faxed my agreement yet).

Cheers,

Will.

Here is a method I have coded to mimmick the Transform3D.setRotation(AxisAngle3f) from Java3d. Technically it is redundant to have so many setRotation methods - but since Xith3d follows the j3d API I think it should be included for completeness.

In Transform3D.java :-


    /**
     * Rotates the matrix around the passed axis by the passed angle.
     * Non rotational elements are unchanged.
     * @param a1 Rotation amount and axis of rotation 
     */
    public final void setRotation(AxisAngle4f a1) {
      
      // Extracts the axis
      Vector3f axis = new Vector3f(a1.x, a1.y, a1.z);
      
      // Extracts the angle
      float angle = a1.angle;
      
      // Calculates the rotation matrix by rotating a Transform
      Transform3D rotation = new Transform3D();
      Matrix3f rotationMatrix = new Matrix3f();
      rotation.rotAxis(axis, angle);  //performs the rotation
      rotation.getRotation(rotationMatrix); //extracts the rotation
      
      // Applies rotation matrix to the current Transform3D
      setRotation(rotationMatrix);      
    }

I have tested it and it worked as expected (so long as my fix from my previous post in this thread is also applied).

It is similar to the static method I posted earlier - but this one is in the Transform3D class and I believe is true to the original counterpart method from Java3D.

Cheers,

Will.

View works now - nice one :slight_smile:

is there any docs or info on the ‘xith_utilities.jar’ stuff. it looks intresting dude!

oh and just messing with the Terrain stuff. what sort of file duss it exspect? grayscale? jpg/png? oh and how do u add the Terrain to a say ‘BranchGroup’. so to render it.

top stuff. any news on lights? :wink: - keeping it going…