Plz help with positions

hello jME community!!!



can u help me with a liitle prob?



public void repaintDynamicObjects(){
      
      //get dynamicObjects set from server
      //dynamic objects are abstract objects which are
      //compiled by 'comp'-object into geometries
      try {
         dynamicObjects = worldRemote.getDynamicObjects(100, new Vector3f(0,0,0));
      } catch (RemoteException re) {
         System.out.println("! (get dynamic objects): " + re);
      }
      
      //update positions of all dynamic objects      
      Iterator<_DynamicWorldObject> iterator = dynamicObjects.iterator();
      while (iterator.hasNext()){
         _DynamicWorldObject dwo = iterator.next();
         
      //debug output 1   
         System.out.println(dwo.getObjectName() + " 1- " + dwo.getPositionInWorld());
      
         //compile and attach object if it is 'new'
         if (rootNode.getChild(dwo.getObjectName())==null)
            rootNode.attachChild(comp.compileObject(dwo));
         
         //get geometry by name         
         Spatial geo = rootNode.getChild(dwo.getObjectName());
      
      //debug output 2   
         System.out.println(geo.getName() + " 2- " + geo.getLocalTranslation());
         
         //set position from abstract world object
         geo.setLocalTranslation(dwo.getPositionInWorld());
         
      }
            
   }



on debug output 1 i get the correct position but on debug output 2 i get position [0.0 , 0.0 , 0.0]
can u help me plz
tell me if u need more detailed description

Thank u a lot

Are you looking for the world translation perhaps?

getWorldTranslation  returns the same value

i think getLocalTranslation returns the position relativ to its parent node

and i attach all spatials to the rootNode

What server are you getting the nodes from? Is it JGN based or a custom RMI or Socket stuff? Maybe the client is not getting the vectors and matrices correctly from the server.

i get the set of '_DynamicWorldObject' from an RMI server…

a _DynamicWorldObject has nothing to do with jME except it has a Vector3f 'position in world'

a _DynamicWorldObject is compiled on the client into a 'Geometry'

the RMI stuff works well … the error must be somewhere after  //get geometry by name

cuz debug output 1 gives me the correct position but debug output 2 gives me always position [0,0,0]



but thank u guys anyway cuz im a newbee

I don't see the problem necessarily. My guess is that there is something with the API that make dwo and geo different. Maybe your comp object does not what you think it does, or maybe the geometry is correctly set up locally, (in (0,0,0)) while the dwo is not, and this is not an error. Who knows, but it can only be in those places, since that is the only calls you have in your code.

//compile and attach object if it is 'new'
if (rootNode.getChild(dwo.getObjectName())==null)
rootNode.attachChild(comp.compileObject(dwo));


Did you check if this IF statement is really detecting that there's no object with this name already on the rootNode?

Maybe the object gets there at start up, with 0 0 0 position an never gets compiled again. No sure... But i'd give it a try.

i got my mistake ^^



public Geometry compileObject(_ObjectInWorld object){
   Geometry geo = null;
         
   if ("world.dynamicObjects.testMovingBall".matches(object.getClass().getName())){
         
      geo = new Sphere(object.getObjectName(),
                                 //(here was my mistake)  object.getPositionInWorld(),
                                 10, 10, 1);
      
      geo.setSolidColor(ColorRGBA.blue);
   }
      
   //System.out.println("comp: " + geo.getName() + " - " + geo.getLocalTranslation());
      
   return geo;
}



@here was my mistake -  i constructed the sphere (testMovingBall^^)  with a location vector
i dont know what was wrong with that ... maybe someone can help me to understand

anyway:
thanks a lot for your help!!!

The reason is because the constructor Sphere(name, center, …) creates a Sphere at location (0,0,0), but the geometry is a set of points centered at center. This might seem weird, but is useful when trying to rotate a sphere on something that is not its center (like an orbiting planet and more)