diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java index aa4b816..31d9e40 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OtherPlayerCharactersModel.java @@ -1,12 +1,24 @@ package org.ntlab.radishforandroidstudio.cactusClient.models; +import net.arnx.jsonic.JSON; + import org.ntlab.radishforandroidstudio.cactusClient.connections.CharactersConnection; +import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; import org.ntlab.radishforandroidstudio.framework.gameMain.Actor; import org.ntlab.radishforandroidstudio.framework.gameMain.GameBaseModel; +import org.ntlab.radishforandroidstudio.framework.gameMain.OvergroundActor; import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; +import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D; import org.ntlab.radishforandroidstudio.framework.model3D.Universe; import org.ntlab.radishforandroidstudio.framework.network.CallBack; +import org.ntlab.radishforandroidstudio.java3d.Appearance; +import org.ntlab.radishforandroidstudio.java3d.Material; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -53,56 +65,56 @@ @Override public void onResponse(String response) { -// Map lastVisibleCharacters = new HashMap<>(visibleCharacters); -// visibleCharacters.clear(); -// -// JSON json = new JSON(); -// Map m = json.decode(response); -// for (Map.Entry entry: m.entrySet()) { -// visibleCharacters.put(entry.getKey(), 1); -// -// ArrayList properties = new ArrayList<>(); -// Map player = entry.getValue(); -// -// // 情報の取得 -// Map position = (Map)player.get("position"); -// Map angle = (Map)player.get("angle"); -// Position3D positionProp = new Position3D(((BigDecimal)position.get("x")).doubleValue(), ((BigDecimal)position.get("y")).doubleValue(), ((BigDecimal)position.get("z")).doubleValue()); -// Quaternion3D quaProp = new Quaternion3D(((BigDecimal)angle.get("x")).doubleValue(), ((BigDecimal)angle.get("y")).doubleValue(), ((BigDecimal)angle.get("z")).doubleValue(), ((BigDecimal)angle.get("w")).doubleValue()); -// properties.add(positionProp); -// properties.add(quaProp); -// -// if (!universe.doHaveObj(entry.getKey())) { -// OvergroundActor pocha; -// Appearance ap1 = new Appearance(); -// Material mat = new Material(); -// mat.setDiffuseColor(0.0f, 0.3f, 1.0f); -// mat.setAmbientColor(0.0f, 0.0f, 0.0f); -// mat.setEmissiveColor(0.0f, 0.0f, 0.0f); -// mat.setSpecularColor(0.0f, 0.0f, 0.0f); -// mat.setShininess(5.0f); -// ap1.setMaterial(mat); -// -// Object3D pochaBody = null; -// Animation3D pochaAnimation = null; -// try { -// pochaBody = ModelFactory.loadModel(fragment.getResources(), "pocha.stl", ap1).createObject(); -// pochaBody.scale(10.0); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// OtherPlayerCharacter chara = new OtherPlayerCharacter(pochaBody); -// universe.place(entry.getKey(), chara); -// universe.place(chara); -// } -// universe.apply(entry.getKey(), properties); -// } -// -// // 見えなくなったキャラクターの削除 -// for (String key : lastVisibleCharacters.keySet()) { -// if (visibleCharacters.get(key) == null) { -// universe.displace(key); -// } -// } + Map lastVisibleCharacters = new HashMap<>(visibleCharacters); + visibleCharacters.clear(); + + JSON json = new JSON(); + Map m = json.decode(response); + for (Map.Entry entry: m.entrySet()) { + visibleCharacters.put(entry.getKey(), 1); + + ArrayList properties = new ArrayList<>(); + Map player = entry.getValue(); + + // 情報の取得 + Map position = (Map)player.get("position"); + Map angle = (Map)player.get("angle"); + Position3D positionProp = new Position3D(((BigDecimal)position.get("x")).doubleValue(), ((BigDecimal)position.get("y")).doubleValue(), ((BigDecimal)position.get("z")).doubleValue()); + Quaternion3D quaProp = new Quaternion3D(((BigDecimal)angle.get("x")).doubleValue(), ((BigDecimal)angle.get("y")).doubleValue(), ((BigDecimal)angle.get("z")).doubleValue(), ((BigDecimal)angle.get("w")).doubleValue()); + properties.add(positionProp); + properties.add(quaProp); + + if (!universe.doHaveObj(entry.getKey())) { + OvergroundActor pocha; + Appearance ap1 = new Appearance(); + Material mat = new Material(); + mat.setDiffuseColor(0.0f, 0.3f, 1.0f); + mat.setAmbientColor(0.0f, 0.0f, 0.0f); + mat.setEmissiveColor(0.0f, 0.0f, 0.0f); + mat.setSpecularColor(0.0f, 0.0f, 0.0f); + mat.setShininess(5.0f); + ap1.setMaterial(mat); + + Object3D pochaBody = null; + Animation3D pochaAnimation = null; + try { + pochaBody = ModelFactory.loadModel(fragment.getResources(), "pocha.stl", ap1).createObject(); + pochaBody.scale(10.0); + } catch (Exception e) { + e.printStackTrace(); + } + OtherPlayerCharacter chara = new OtherPlayerCharacter(pochaBody); + universe.place(entry.getKey(), chara); + universe.place(chara); + } + universe.apply(entry.getKey(), properties); + } + + // 見えなくなったキャラクターの削除 + for (String key : lastVisibleCharacters.keySet()) { + if (visibleCharacters.get(key) == null) { + universe.displace(key); + } + } } }