[Solved] Skybox Movement Laggy

I know I've raised this issue before, and I've seen a few threads about fixes (ie: http://www.jmonkeyengine.com/jmeforum/index.php?topic=2093.0 ), but even using the fixes in there I can't seem to get my skybox to work without this lag when I move the camera.



Currently, it seems to work OK, as long as I'm not using my BUI GUI.  After looking back at this code after a while, the update() and render() methods seem a bit circular, but I'm not fully sure as to which I can skip out on.  The updateWorldVectors  fixed the problem, until I added my BUI back in.



This is my only real noticable problem that I've been working with, and seeing it has been driving me crazy.  Thanks in advance!



EDIT: So, I solved it, as noted in the next post, but am still curious as to if the shown code seems correct.


   public void update(float tpf)
   {
      super.update(tpf);
      skybox.getLocalTranslation().set(
            DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation());
   }

   public void render(float tpf)
   {
      update(tpf);
      super.render(tpf);
   }

I don't think I absolutely need it, from what I remember I had done that just for the heck of it.



I do, however, seem to need to call the methods inside there when I both do rendering and updating.  I guess I might misunderstand GameStates, but I thought the calling of update, then rendering was a part of the magic it does.

Well in StandardGame they are called simply called after each other, first update, then render.

if you call update inside the render method,  updateGeometricState() will get called twice, resulting in controllers acting twice as fast as they should.



Try to remove the update() call in the render() method and change the update() method to the following:


    super.update(tpf);
    skybox.getLocalTranslation().set(DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation());
    rootNode.updateGeometricState(tpf);



This should react the same as your version right now.
But its obviously 'wrong' to call updateGeometricState(tpf) twice on the rootNode.
You could try with tpf set to 0 in the 2nd call, or call super.update() only once at the end of your update method.

But i also had problems updating the SkyBox and couldn't figure it out, so i removed it and went for fog hehe :)

Well…I moved the creation of the skybox and attachment to after the GUI creation+attachment…I guess irrisor's fix in that thread did indeed work, I just needed to pay more attention to the right area (what creates all of my states, rather than the skybox itself).



The laggy movement is fixed, however I'm still curious as to whether the render and update methods are correct in the above code.

Do you need the doUpdate() call inside the render() method ?

I actually had the call in there for update() in the render() method because of a suggestion from someone else who had the same issue.



When I remove it and change the code to this, it seems to work fine, as well (worked before, but I was kinda iffy about that render calling update - sounded like overhead).


   public void update(float tpf)
   {
      super.update(tpf);
      skybox.getLocalTranslation().set(
            DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation());
      rootNode.updateGeometricState(0.0f, true);
   }

   public void render(float tpf)
   {
      //update(tpf);
      super.render(tpf);
   }



Thank you!