Rotating TransformGroups

Ok, so in my current project, I have several different subclasses of TG’s that represent different vehicles. At this point, they can move around in a bounded environment enclosed by a primitive skybox. Unfortunately in the rotate methods:


  public void rotateHoriz(int right){
    horizAngle += (float)(right*Math.PI/8);
    Transform3D t = new Transform3D();
    t.lookAt(location,                  
             new Vector3f(location.x + (float)Math.sin(horizAngle), location.y + (float)Math.sin(horizAngle), location.z + (float)Math.cos(horizAngle) ),
             new Vector3f(0, 1f, 0));
    t.set(location);
    setTransform(t);
  }

  public void rotateVert(int up){
    vertAngle += (float)(up*Math.PI/8);
    Transform3D t = new Transform3D();
    t.lookAt(location,                  
             new Vector3f(location.x + (float)Math.sin(horizAngle), location.y + (float)Math.sin(horizAngle), location.z + (float)Math.cos(horizAngle) ),
             new Vector3f(0, 1f, 0));
    t.set(location);
    setTransform(t);
  }

which look like that, the transformgroups fail to rotate in the right direction. I’ve tried rotY(horizAngle) and rotX(vertAngle), but the groups face the same direction anyway. Any suggestions?

when I rotate suff I use this method I wrote


public static final void rotate(TransformGroup tg, float y, float x, float z){

        AxisAngle4f yRot = new AxisAngle4f(0,1,0,y);
        AxisAngle4f xRot = new AxisAngle4f(1,0,0,x);
        AxisAngle4f zRot = new AxisAngle4f(0,0,1,z);


        Matrix4f rot = new Matrix4f(Matrix.IDENTITY_4);
        Matrix4f tmp = new Matrix4f(Matrix.IDENTITY_4);

        rot.set(yRot);
        tmp.set(xRot);
        rot.mul(tmp);
        tmp.set(zRot);
        rot.mul(tmp);

        tg.getTransform().get(tmp);
        System.out.println("tmp = " + tmp);
        tmp.mul(rot);
        System.out.println("tmp = " + tmp);
        tg.getTransform().set(tmp);
        tg.setTransform(tg.getTransform());
    }

I call the pointless setTransform at the end becuase it jogs Xith3D to update the view, otherwise it doesn’t notice.

3D buffs will no doubtly scoff at the amount of garbage collection that flows out of this method but its rapid development baby, sort it in the profiling step!

Hope this helps

Where is Matrix.IDENTITY_4?

I searched the j3d javadoc for it and it doesn’t appear in the x3d docs. I can’t compile it w/o finding the class Matrix.

Never mind, I got it. The method works well, thanks!