| |
---|
| | |
---|
| | 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(); |
---|
| | Material m = new Material(); |
---|
| |
---|
| | camera.setViewPoint(actor.getPosition().add(0.0, 1.5, 0.0)); |
---|
| | camera.setViewLine(actor.getDirection()); |
---|
| | camera.setFieldOfView(1.5); |
---|
| | camera.setBackClipDistance(10000.0); |
---|
| | updateCamera(); |
---|
| | } |
---|
| | |
---|
| | public void setPlayerId(String id) { |
---|
| | playerId = id; |
---|
| | } |
---|
| | |
---|
| | public void updateCamera() { |
---|
| | Vector3d charaVector3d = actor.getDirection(); |
---|
| | charaVector3d.normalize();//キャラの向きを単位ベクトルに |
---|
| | camera.setViewPoint(actor.getPosition() |
---|
| | .add(-5.0 * charaVector3d.getX(), charaVector3d.getY() + 5.0, -5.0 * charaVector3d.getZ()));//視点 |
---|
| | 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) { |
---|
| |
---|
| | isTouched = false; |
---|
| | } |
---|
| | 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) { |
---|
| | |
---|
| | } |
---|
| | } |
---|
| | |
カメラ回転とジャンプが動作しないのは,PlayerFragmentを戻したときに該当コードが消えているので仕様です.
PlayerFragmentFix
9a9a385
intomaster
fromPlayerFragmentFix
on 18 Oct 2018