Math error in getWorldTranslation

Well after I treid several hours to debug my stuff to see why it just does not make sense, I think I have located the error:



testcode, returns sometimes localTranslation instead of WorldTranslation!!!


   @Override
   public Vector3f getPosition() {
      System.out.println("Parent:" + this.visiblenode.getParent()); //players parent, rootnode or car
      System.out.println("Parentrelation:" + this.visiblenode.getLocalTranslation());
      if(this.visiblenode.getParent() != null){
         System.out.println("Parent's-Parent:" + this.visiblenode.getParent().getParent()); //null or the rootnode wher the car is
         System.out.println("Parent's-Parentrelation:" + this.visiblenode.getParent().getLocalTranslation());
      }
      System.out.println("My world position:"+this.visiblenode.getWorldTranslation());
      return this.visiblenode.getWorldTranslation();
   }


in the upper of couse the rootnode is the same as in the other, I just made a mistake labeling.

Uh, when in the update loop do you read those values?

In the beginning, but there really shouldn't be any problem related with this, as they are really just Nodes, without physic or anything. Also in the lower one on the picture, there clearly is a math error.



extends Application!


      if (speed == 0 || paused)
         return;

      super.update();
      float tpf = timer.getTimePerFrame() * speed;

      rootNode.updateLogicalState(tpf);
      guiNode.updateLogicalState(tpf);
      rootNode.updateGeometricState();
      guiNode.updateGeometricState();
      
      if(client!=null){
         clientUpdate(tpf); //HEREHEREHERE
      }

      Vector3f dir = new Vector3f();
      cam.getDirection(dir);
      Vector3f up = cam.getUp();
      Vector3f pos = cam.getLocation();
//      SSystem.setListenerPosition(pos.x, pos.y, pos.z);
//      SSystem.setListenerOrientation(dir.x, dir.y, dir.z, up.x, up.y, up.z);
      TimedInvocation.Update();
      renderManager.render(tpf);

normen said:

Uh, when in the update loop do you read those values?

If you change the local transform, and don't call updateGeometricState(), then world transform will return the last local transform set. This is obviously incorrect.
Maybe we should throw an exception if you try to retrieve the world transform when the refresh flag is set?

This seems to work btw:


      this.visiblenode.getParent().localToWorld(pos, pos);
      if(this.visiblenode.getParent().getParent() != null){
         this.visiblenode.getParent().getParent().localToWorld(pos, pos);
      }



But a warning would be rally good here, yes.

Yeah, it works because essentially you're manually converting the position from local space to world space using the every parents local transform (which is incorrectly stored in the world transform). A very similar process is done in the engine itself to derive the world transform.