Merge branch 'master' into model
commit 2d3a096562a51ec9e3ee89e7504c1f379c377384
2 parents 8d47467 + deef17d
s-iwatani authored on 27 Sep 2018
Showing 8 changed files
View
.idea/caches/build_file_checksums.ser
Not supported
View
2
■■■
app/build.gradle
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
buildToolsVersion '28.0.2'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
View
99
app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/OwnPlayer.java 0 → 100644
package org.ntlab.radishforandroidstudio.cactusClient.models;
 
import android.content.res.Resources;
import android.view.MotionEvent;
 
import org.ntlab.radishforandroidstudio.framework.animation.Animation3D;
import org.ntlab.radishforandroidstudio.framework.event.PadEvent;
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.Universe;
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 {
private boolean isTouched = false;
private float touchX = 0.0f;
private float touchY = 0.0f;
private OvergroundActor actor;
private Camera3D camera;
private Player player;
 
public OwnPlayer(Player player, Resources resources, Universe universe, Camera3D camera) {
this.player = player;
 
// キャラクタの作成
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(resources, "pocha.stl", ap1).createObject();
Animation3D pochaAnimation = null; //AnimationFactory.loadAnimation("data\\pocha\\walk.wrl");
actor = new OvergroundActor(pochaBody, pochaAnimation);
actor.setPosition(new Position3D(0.0, 1.0, 0.0));
universe.place(actor);
} catch (Exception e) {
e.printStackTrace();
}
 
this.camera = camera;
camera.setViewPoint(actor.getPosition().add(0.0, 1.5, 0.0));
camera.setViewLine(actor.getDirection());
camera.setFieldOfView(1.5);
camera.setBackClipDistance(10000.0);
}
 
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) {
Vector3d charaVector3d = actor.getDirection();
charaVector3d.normalize();//キャラの向きを単位ベクトルに
MotionEvent motionEvent = event.getMotionEvent();
 
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
isTouched = true;
touchX = (float) (Math.cos(event.getAngle()) * event.getLength());
touchY = (float) (Math.sin(event.getAngle()) * event.getLength());
 
 
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
Velocity3D vel = actor.getVelocity();
vel.setX(0);
vel.setY(0);
actor.setVelocity(vel);
isTouched = false;
}
return false;
}
}
View
6
app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/Player.java
import org.ntlab.radishforandroidstudio.framework.model3D.Quaternion3D;
 
import net.arnx.jsonic.JSONHint;
 
public class Player extends Entity3D {
import java.io.Serializable;
 
public class Player extends Entity3D implements Serializable {
private String instanceID;
private String characterID;
private String areaURI;
private Position3D position;
View
12
app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/CharactersFragment.java
con.setCallBack(new CallBack() {
@Override
public void onResponse(String response) {
Map<String, Player> player = JSON.decode(response, new TypeReference<HashMap<String, Player>>(){});
// Player character = JSON.decode(response, Player.class);
// TODO: 複数帰ってきた,もしくは帰ってこなかったときの処理
 
// プレイ画面へ
Bundle bundle = new Bundle();
bundle.putSerializable("characterId", characterIds.get(position));
PlayerFragmentLight fragment = new PlayerFragmentLight();
bundle.putSerializable("player", (Player)player.values().toArray()[0]);
PlayerFragment fragment = new PlayerFragment();
 
fragment.setArguments(bundle);
// TODO: 型を上のMAPのやつを渡すようにする
fragment.setPlayer(player.values().iterator().next());
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fragment_place, fragment);
transaction.addToBackStack(null);
View
201
app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/views/PlayerFragment.java
import android.view.View;
import android.view.ViewGroup;
 
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;
import org.ntlab.radishforandroidstudio.framework.event.PadEvent;
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;
import org.ntlab.radishforandroidstudio.framework.physics.Ground;
import org.ntlab.radishforandroidstudio.java3d.AmbientLight;
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 float touchX = 0.0f;
private float touchY = 0.0f;
RWTPad pad = null;
private Player player;
private OwnPlayer player;
 
public PlayerFragment() {
// Required empty public constructor
}
);
// 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);
}
 
 
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
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();
return parentView;
}
 
@Override
protected void progress(long interval) {
Velocity3D curV = pocha.getVelocity();
if (isTouched) {
pocha.rotY(0.001 * (0.5f - touchX) * (double) (interval / 15.0));
curV.setX(pocha.getDirection().getX() * 200.0 * (0.5f - touchY));
curV.setZ(pocha.getDirection().getZ() * 200.0 * (0.5f - touchX));
pocha.setVelocity(curV);
 
} else {
curV.setX(0.0);
curV.setZ(0.0);
pocha.setVelocity(curV);
}
 
Vector3d charaVector3d = pocha.getDirection();
charaVector3d.normalize();//キャラの向きを単位ベクトルに
camera.setViewPoint(pocha.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));//視線
player.progress(interval);
}
 
 
//sampleUiFragmentからそのまま持ってきた
}
 
public void onCreateFragmentEvent(RWTUIFragment f) {
pad = (RWTPad) f.findViewById(org.ntlab.radishforandroidstudio.R.id.pad);
pad.addListener((PadListener) this);
}
 
/**
* TODO: 座標等はcharacter変数を使用するようにする
*
* @param event イベントの情報
* @return
*/
@Override
public boolean onEvent(PadEvent event) {
Vector3d charaVector3d = pocha.getDirection();
charaVector3d.normalize();//キャラの向きを単位ベクトルに
MotionEvent motionEvent = event.getMotionEvent();
 
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
isTouched = true;
touchX = (float) (Math.cos(event.getAngle()) * event.getLength());
touchY = (float) (Math.sin(event.getAngle()) * event.getLength());
 
//motion.eventをevent.getLengthみたいに変えればいい?
//touchYのもとは(motionEvent.getY() - minY) / (maxY - minY),X (motionEvent.getX() - minX) / (maxX - minX)
camera.setViewPoint(pocha.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));//視線
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
isTouched = false;
}
return false;
}
 
public void setPlayer(Player player) {
this.player = player;
pad.addListener(player);
}
}
 
View
2
■■■
build.gradle
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.2.0'
 
 
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
View
4
gradle/wrapper/gradle-wrapper.properties
#Fri May 11 18:21:39 JST 2018
#Tue Sep 25 13:40:41 JST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip