diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OwnPlayer.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OwnPlayer.java index f7133fa..17f0e89 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OwnPlayer.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OwnPlayer.java @@ -3,30 +3,42 @@ import android.content.res.Resources; import android.view.MotionEvent; +import net.arnx.jsonic.JSON; + +import org.ntlab.radishforandroidstudio.cactusClient.connections.CharacterConnection; import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; import org.ntlab.radishforandroidstudio.framework.event.PadEvent; +import org.ntlab.radishforandroidstudio.framework.gameMain.GameBaseModel; import org.ntlab.radishforandroidstudio.framework.gameMain.OvergroundActor; import org.ntlab.radishforandroidstudio.framework.listener.PadListener; 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.Quaternion3D; import org.ntlab.radishforandroidstudio.framework.model3D.Universe; +import org.ntlab.radishforandroidstudio.framework.network.CallBack; +import org.ntlab.radishforandroidstudio.framework.physics.Solid3D; import org.ntlab.radishforandroidstudio.framework.physics.Velocity3D; import org.ntlab.radishforandroidstudio.framework.view3D.Camera3D; import org.ntlab.radishforandroidstudio.java3d.Appearance; import org.ntlab.radishforandroidstudio.java3d.Material; import org.ntlab.radishforandroidstudio.java3d.Vector3d; -public class OwnPlayer implements PadListener { +public class OwnPlayer implements PadListener, GameBaseModel, CallBack { private boolean isTouched = false; private float touchX = 0.0f; private float touchY = 0.0f; private OvergroundActor actor; private Camera3D camera; private Player player; + private CharacterConnection con; + private int nextConnectRenaimdTime = 0; + private int connectInterval = 300; + private String playerId; - public OwnPlayer(Player player, Resources resources, Universe universe, Camera3D camera) { + public OwnPlayer(Player player, Resources resources, Universe universe, Camera3D camera, String playerId) { this.player = player; + setPlayerId(playerId); // キャラクタの作成 Appearance ap1 = new Appearance(); @@ -53,6 +65,11 @@ camera.setViewLine(actor.getDirection()); camera.setFieldOfView(1.5); camera.setBackClipDistance(10000.0); + updateCamera(); + } + + public void setPlayerId(String id) { + playerId = id; } public void updateCamera() { @@ -63,17 +80,6 @@ camera.setViewLine(new Vector3d(5.0 * charaVector3d.getX(), charaVector3d.getY() - 2.5, 5.0 * charaVector3d.getZ() + touchX));//視線 } - public void progress(long interval) { - updateCamera(); - - if (isTouched) { - Velocity3D vel = actor.getVelocity(); - vel.setX(touchX); - vel.setY(touchY); - actor.setVelocity(vel); - } - } - @Override public boolean onEvent(PadEvent event) { Vector3d charaVector3d = actor.getDirection(); @@ -95,4 +101,45 @@ } return false; } + + @Override + public void update(double interval) { + updateCamera(); + + if (isTouched) { + Velocity3D vel = actor.getVelocity(); + vel.setX(touchX); + vel.setY(touchY); + actor.setVelocity(vel); + } + + nextConnectRenaimdTime -= interval; + if (nextConnectRenaimdTime <= 0) { + nextConnectRenaimdTime = connectInterval; + con = new CharacterConnection(playerId); + con.setCallBack(this); + + Quaternion3D q = ((Solid3D)(actor.getBody())).getQuaternion(); + player.setPosition(actor.getPosition()); + player.setAngle(q); + + JSON json = new JSON(); + con.addFormParam("characterID", json.encode(player.getCharacterID())); + con.addFormParam("cameraState", json.encode(player.getCameraState())); + con.addFormParam("position", json.encode(player.getPosition())); + con.addFormParam("animationClassToStart", json.encode(player.getEmoteState())); + con.addFormParam("angle", "{ \"x\":" + q.getX() + ", \"y\":" + q.getY() + ", \"z\":" + q.getZ() + ", \"w\":" + q.getW() + "}"); + con.doPut(); + } + } + + @Override + public void setInstanceId(String id) { + player.setInstanceID(id); + } + + @Override + public void onResponse(String response) { + + } } \ No newline at end of file