diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 4c5bc7b..d8704b8 100644 --- a/.idea/caches/build_file_checksums.ser +++ b/.idea/caches/build_file_checksums.ser Binary files differ 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 6ce0c2d..f7133fa 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,42 +3,30 @@ 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, GameBaseModel, CallBack { +public class OwnPlayer implements PadListener { 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, String playerId) { + public OwnPlayer(Player player, Resources resources, Universe universe, Camera3D camera) { this.player = player; - setPlayerId(playerId); // キャラクタの作成 Appearance ap1 = new Appearance(); @@ -65,11 +53,6 @@ camera.setViewLine(actor.getDirection()); camera.setFieldOfView(1.5); camera.setBackClipDistance(10000.0); - updateCamera(); - } - - public void setPlayerId(String id) { - playerId = id; } public void updateCamera() { @@ -80,6 +63,17 @@ 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(); @@ -101,45 +95,4 @@ } 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 diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java index 8a269d2..00ca820 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java @@ -9,9 +9,10 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import org.ntlab.radishforandroidstudio.R; +import org.ntlab.radishforandroidstudio.cactusClient.models.OwnPlayer; +import org.ntlab.radishforandroidstudio.cactusClient.models.Player; import org.ntlab.radishforandroidstudio.framework.RWT.RWTPad; import org.ntlab.radishforandroidstudio.framework.RWT.RWTUIFragment; import org.ntlab.radishforandroidstudio.framework.animation.Animation3D; @@ -19,6 +20,7 @@ import org.ntlab.radishforandroidstudio.framework.gameMain.OvergroundActor; import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; import org.ntlab.radishforandroidstudio.framework.listener.PadListener; +import org.ntlab.radishforandroidstudio.framework.model3D.BaseObject3D; import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; @@ -28,19 +30,16 @@ import org.ntlab.radishforandroidstudio.java3d.Appearance; import org.ntlab.radishforandroidstudio.java3d.Color3f; import org.ntlab.radishforandroidstudio.java3d.DirectionalLight; +import org.ntlab.radishforandroidstudio.java3d.IndexedTriangleArray; import org.ntlab.radishforandroidstudio.java3d.Material; +import org.ntlab.radishforandroidstudio.java3d.Point3d; import org.ntlab.radishforandroidstudio.java3d.Vector3d; import org.ntlab.radishforandroidstudio.java3d.Vector3f; -public class PlayerFragment extends RealTime3DFragment implements PadListener { +public class PlayerFragment extends RealTime3DFragment { private OvergroundActor pocha; - private Ground stage; - private boolean isTouched = false; - private boolean isPadTouched = false; - private float touchX = 0.0f; - private float touchY = 0.0f; RWTPad pad = null; - double n=1.0; + private OwnPlayer player; public PlayerFragment() { // Required empty public constructor @@ -52,6 +51,8 @@ super.onCreate(savedInstanceState); //環境光 AmbientLight amblight = new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f)); + +// amblight.setInfluencingBounds(new BoundingSphere(new Point3d(), 10000.0)); universe.placeLight(amblight); //平行光源 @@ -59,52 +60,28 @@ new Color3f(1.0f, 1.0f, 1.0f), //光の色 new Vector3f(0.0f, -1.0f, -0.5f) //光の方向ベクトル ); - +// dirlight.setInfluencingBounds(new BoundingSphere(new Point3d(), 10000.0)); universe.placeLight(dirlight); - Appearance ap1 = new Appearance(); - Material m = new Material(); - m.setDiffuseColor(0.0f, 0.3f, 1.0f); - m.setAmbientColor(0.0f, 0.0f, 0.0f); - m.setEmissiveColor(0.0f, 0.0f, 0.0f); - m.setSpecularColor(0.0f, 0.0f, 0.0f); - m.setShininess(5.0f); - ap1.setMaterial(m); - - /*キャラクターの作成*/ - Object3D pochaBody = null; - try { - pochaBody = ModelFactory.loadModel(getResources(), "pocha.stl", ap1).createObject(); - Animation3D pochaAnimation = null; //AnimationFactory.loadAnimation("data\\pocha\\walk.wrl"); - pocha = new OvergroundActor(pochaBody, pochaAnimation); - pocha.setPosition(new Position3D(0.0, -100.0, 250.0)); - universe.place(pocha); - } catch (Exception e) { - e.printStackTrace(); - } - + // 地面の作成 + IndexedTriangleArray groundGeometry = new IndexedTriangleArray(4, + IndexedTriangleArray.COORDINATES | IndexedTriangleArray.NORMALS, 6); + groundGeometry.setCoordinate(0, new Point3d(-20.0, -1.0, -20.0)); + groundGeometry.setCoordinate(1, new Point3d(20.0, -1.0, -20.0)); + groundGeometry.setCoordinate(2, new Point3d(20.0, -1.0, 20.0)); + groundGeometry.setCoordinate(3, new Point3d(-20.0, -1.0, 20.0)); + groundGeometry.setNormal(0, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setNormal(1, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setNormal(2, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setNormal(3, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setCoordinateIndices(0, new int[]{0, 3, 2}); + groundGeometry.setCoordinateIndices(3, new int[]{0, 2, 1}); Appearance ap2 = new Appearance(); Material m2 = new Material(); - m2.setDiffuseColor(0.1f, 0.0f, 0.02f); - m2.setAmbientColor(0.1f, 0.1f, 0.1f); - m2.setEmissiveColor(0.0f, 0.0f, 0.0f); - m2.setSpecularColor(0.2f, 0.2f, 0.2f); - m2.setShininess(5.0f); + m2.setDiffuseColor(0.5f, 1.0f, 0.2f); ap2.setMaterial(m2); - - Object3D stageObj = null; - try { - stageObj = ModelFactory.loadModel(getResources(), "konan/konan.obj").createObject(); - stage = new Ground(stageObj); - universe.place(stage); - } catch (Exception e) { - e.printStackTrace(); - } - - camera.setViewPoint(pocha.getPosition().add(0.0, 1.5, 0.0)); - camera.setViewLine(pocha.getDirection()); - camera.setFieldOfView(1.5); - camera.setBackClipDistance(10000.0); + Ground ground = new Ground(new BaseObject3D(groundGeometry, ap2)); + universe.place(ground); start(1000L, 50L, true); } @@ -113,89 +90,20 @@ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); - //画面生成 + Bundle bundle = getArguments(); + + // プレイヤーの作成 + player = new OwnPlayer((Player)bundle.getSerializable("player"), getResources(), universe, camera); + initGameWindowView(); - - parentView.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { - isTouched = true; - //画面をどこタッチしたか - float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax(); - float minX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMin(); - float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax(); - float minY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMin(); - touchX = (event.getX() - minX) / (maxX - minX); - touchY = (event.getY() - minY) / (maxY - minY); - - } else if (event.getAction() == MotionEvent.ACTION_UP) { - isTouched = false; - } - return true; - } - }); - return parentView; } - //追跡 @Override protected void progress(long interval) { - Velocity3D curV = pocha.getVelocity(); - Vector3d charaVector3d = pocha.getDirection(); - Vector3d up = new Vector3d(0,1,0); - Vector3d total = new Vector3d(); - Vector3d right = new Vector3d(); + player.progress(interval); + } - if (isPadTouched) { - - right.cross(charaVector3d,up); - Vector3d touchX3d = right.clone(); - Vector3d touchY3d = charaVector3d.clone(); - touchX3d.scale(touchX * -20); - touchY3d.scale(touchY * 20); -// Vector3d touchX3d = new Vector3d(0.0,0.0,pocha.getDirection().getX() * touchX * -20); -// Vector3d touchY3d = new Vector3d(pocha.getDirection().getX() * touchY* 20,0.0,0.0); - total.add(touchX3d); - total.add(touchY3d); - total.y = curV.getY(); //Yをもとどおりに! - curV.setVector3d(total); - pocha.setVelocity(curV);//pochaの追跡 - - Button button = (Button) getActivity().findViewById(R.id.JumpButton); - button.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - if(pocha.isOnGround()) { - total.y = curV.getY() + 15; //Yをもとどおりに! - curV.setVector3d(total); - pocha.setVelocity(curV);//pochaの追跡 - } - } - }); - - } else if (isTouched) { - pocha.rotY(0.1 * (0.5f - touchX)); - if(n <= 5 && n >= 0){ - n += (0.5f - touchY); - }else if (n >5){ - n = 5; - }else if (n < 0){ - n = 0; - } - - } else { - curV.setX(0.0); - curV.setZ(0.0); - pocha.setVelocity(curV); - } - charaVector3d.normalize();//キャラの向きを単位ベクトルに - // 向き設定 - camera.setViewPoint(pocha.getPosition().add(5.0 * charaVector3d.getX(), charaVector3d.getY() + 5.5 - n, 5.0 * charaVector3d.getZ()));//視点 - camera.setViewLine(new Vector3d(-5.0 * charaVector3d.getX(), charaVector3d.getY() - 2.5 + n, -5.0 * charaVector3d.getZ()));//視線 -} //sampleUiFragmentからそのまま持ってきた public void initGameWindowView() { @@ -212,23 +120,6 @@ public void onCreateFragmentEvent(RWTUIFragment f) { pad = (RWTPad) f.findViewById(org.ntlab.radishforandroidstudio.R.id.pad); - pad.addListener((PadListener) this); + pad.addListener(player); } - - //タッチパッドのonEvent - @Override - public boolean onEvent(PadEvent event) { - MotionEvent motionEvent = event.getMotionEvent(); - if (motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_MOVE) { - isPadTouched = true; - //前後ろ動き - touchX = (float) (Math.cos(event.getAngle()) * event.getLength()); - touchY = (float) (Math.sin(event.getAngle()) * event.getLength()); - } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { - isPadTouched = false; - } - - return false; - - } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java index df08e52..9d42402 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/SignUpFragment.java @@ -79,7 +79,7 @@ public void onResponse(String response) { //通信した時の処理を書くのだよ // URIAddressedAccount ac = JSON.decode(response,URIAddressedAccount.class); -// System.out.println("JSON.decode(response, URIAddressedAccount.class);\n"+ac.getUri()); +// System.out.println("JSON.decode(response, URIAddressedAccount.class);\viewPoint"+ac.getUri()); URIAddressedAccount ac2 = JSON.decode(response, new TypeReference(){}); System.out.println("JSON.decode(response, new TypeReference(){});\n"+ac2.getUri()); System.out.println(response);