diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MovableObjectModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MovableObjectModel.java index 9744d40..4a96abf 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MovableObjectModel.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/MovableObjectModel.java @@ -26,6 +26,8 @@ private Universe universe; private RealTime3DFragment fragment; private ObjectsConnection con; + private int nextConnectRenaimdTime = 0; + private int connectInterval = 300; private String instanceId; private String objectId; private Map visibleobject = new HashMap<>(); @@ -52,9 +54,13 @@ */ @Override public void update(double interval) { - con = new ObjectsConnection(instanceId); - con.setCallBack(this); - con.doGet(); + nextConnectRenaimdTime -= interval; + if (nextConnectRenaimdTime <= 0) { + nextConnectRenaimdTime = connectInterval; + con = new ObjectsConnection(instanceId); + con.setCallBack(this); + con.doGet(); + } } @@ -78,7 +84,7 @@ properties.add(object.getPosition()); properties.add(object.getAngle()); - if (!universe.doHaveObj(entry.getKey())){ + if (!universe.doHaveObj(entry.getKey())) { Appearance ap1 = new Appearance(); Material mat = new Material(); mat.setDiffuseColor(0.0f, 0.3f, 1.0f); @@ -90,29 +96,25 @@ Object3D objBody = null; try { - objBody = ModelFactory.loadModel(fragment.getResources(),"cube-ascii.stl",ap1).createObject(); - }catch (Exception e){ + objBody = ModelFactory.loadModel(fragment.getResources(), "cube-ascii.stl", ap1).createObject(); + } catch (Exception e) { e.printStackTrace(); } - MovableObject object1 =new MovableObject(objBody); - universe.place(entry.getKey(),object1); + MovableObject object1 = new MovableObject(objBody); + universe.place(entry.getKey(), object1); universe.place(object1); } - universe.apply(entry.getKey(),properties); + universe.apply(entry.getKey(), properties); } - for (String key :lastvisibleobject.keySet()){ - if (visibleobject.get(key) == null){ + for (String key : lastvisibleobject.keySet()) { + if (visibleobject.get(key) == null) { universe.displace(key); } } - - - - } }