Padでとりあえず動く
1 parent a1ca5fa commit 99912cbd748a3c62d8e1cf21b6217a81c3eaf87a
s-bekki authored on 19 Jun 2018
Showing 4 changed files
View
.idea/caches/build_file_checksums.ser
Not supported
View
95
app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/PlayerActivity.java
import org.ntlab.radishforandroidstudio.java3d.Vector3f;
import org.ntlab.radishforandroidstudio.java3d.View;
 
 
public class PlayerActivity extends RealTime3DActivity {
public class PlayerActivity extends RealTime3DActivity implements PadListener{
private OvergroundActor pocha;
private Ground stage;
private boolean isTouched = false;
private float touchX = 0.0f;
private float touchY = 0.0f;
// RWTPad pad = findViewById(org.ntlab.radishforandroidstudio.R.id.button3);
RWTPad pad = null;
 
 
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 
 
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
Fragment f = new RWTUIFragment();
RWTUIFragment f = new RWTUIFragment();
f.setListener(this);
android.view.View uiLayout = (android.view.View)findViewById(org.ntlab.radishforandroidstudio.R.id.ui_layout);
uiLayout.setOnTouchListener((RWTUIFragment)f);
transaction.add(org.ntlab.radishforandroidstudio.R.id.ui_layout, f);
transaction.commit();
 
 
 
 
/*camera.setViewPoint(pocha.getPosition().add(0.0, 1.5, 0.0));
 
@Override
public void progress(long interval) {
Velocity3D curV = pocha.getVelocity();
if (isTouched) {
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 - touchY));
pocha.setVelocity(curV);
 
 
@SuppressLint("NewApi")
@Override
public boolean onTouchEvent(MotionEvent event){
public boolean onTouchEvent (MotionEvent event){
Vector3d charaVector3d = pocha.getDirection();
charaVector3d.normalize();//キャラの向きを単位ベクトルに
super.onTouchEvent(event);
 
touchY = (event.getY() - minY) / (maxY - minY);
 
camera.setViewPoint(pocha.getPosition()
.add( -5.0 * charaVector3d.getX(), charaVector3d.getY() + 5.0, -5.0 * charaVector3d.getZ()));//視点
 
 
/* //タッチしたとこからの処理
 
double deg = 180;
double ret;
 
 
// 現在の水平の視点の角度を極座標で求める
double thetaH = Math.atan2(touchX - (5.0 *charaVector3d.getX()) , touchY - (charaVector3d.getY() - 2.5));
ret = Math.toRadians(thetaH);
// eyeからlookまでの水平の距離
double rH = Math.sqrt(Math.pow(touchX - 5.0 *charaVector3d.getX(), 2) + Math.pow(touchY - charaVector3d.getY() - 2.5, 2));
 
// 角度を加算
thetaH += Math.toRadians(deg);
 
// lookのX座標とY座標を求める
double eye_x = rH * Math.cos(thetaH) + 5.0 *charaVector3d.getX();
double eye_y = rH * Math.sin(thetaH) + charaVector3d.getY() - 2.5;
*/
 
 
 
camera.setViewLine(new Vector3d(5.0 *charaVector3d.getX() , charaVector3d.getY() - 2.5, 5.0 *charaVector3d.getZ()+touchX));//視線
} else if (event.getAction() == MotionEvent.ACTION_UP) {
isTouched = false;
}
return true;
}
 
 
public void onCreateFragmentEvent(RWTUIFragment f) {
pad = (RWTPad) f.findViewById(org.ntlab.radishforandroidstudio.R.id.button3);
pad.addListener(this);
}
 
@Override
public boolean onEvent(PadEvent event) {
Vector3d charaVector3d = pocha.getDirection();
charaVector3d.normalize();//キャラの向きを単位ベクトルに
MotionEvent motionEvent = event.getMotionEvent();
super.onTouchEvent(motionEvent);
 
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
isTouched = true;
float maxX = motionEvent.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax() / 2.0f;
float minX = motionEvent.getDevice().getMotionRange(MotionEvent.AXIS_X).getMin();
float maxY = motionEvent.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax();
float minY = motionEvent.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMin();
touchX = (motionEvent.getX() - minX) / (maxX - minX);
touchY = (motionEvent.getY() - minY) / (maxY - minY);
 
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;
}
}
View
20
app/src/main/java/org/ntlab/radishforandroidstudio/framework/RWT/RWTUIFragment.java
package org.ntlab.radishforandroidstudio.framework.RWT;
 
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.widget.Button;
 
import org.ntlab.radishforandroidstudio.R;
import org.ntlab.radishforandroidstudio.cactusClient.PlayerActivity;
import org.ntlab.radishforandroidstudio.framework.event.PadEvent;
import org.ntlab.radishforandroidstudio.framework.listener.PadListener;
import org.ntlab.radishforandroidstudio.sample.SampleGameActivity;
 
import static android.view.View.*;
 
public class RWTUIFragment extends Fragment implements OnTouchListener,PadListener {
PlayerActivity listener = null;
View v = null;
public RWTUIFragment() {}
 
@Override
public void onCreate(Bundle savedInstanceState) {
 
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.ui_fragment, container, false);
v = inflater.inflate(R.layout.ui_fragment, container, false);
RWTPad pad = v.findViewById(org.ntlab.radishforandroidstudio.R.id.button3);
pad.addListener(this);
 
if (listener != null) {
listener.onCreateFragmentEvent(this);
}
return inflater.inflate(R.layout.ui_fragment, null);
}
 
@Override
@Override
public boolean onEvent(PadEvent event) {
return false;
}
 
public void setListener(PlayerActivity activity) {
listener = activity;
}
 
public View findViewById(int id) {
return v.findViewById(id);
}
 
}
View
8
app/src/main/java/org/ntlab/radishforandroidstudio/sample/SampleGameActivity.java
package org.ntlab.radishforandroidstudio.sample;
 
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.view.MotionEvent;
 
import org.ntlab.radishforandroidstudio.R;
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.RealTime3DActivity;
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.physics.Ground;
import org.ntlab.radishforandroidstudio.java3d.Material;
import org.ntlab.radishforandroidstudio.java3d.Vector3f;
 
 
public class SampleGameActivity extends RealTime3DActivity {
public class SampleGameActivity extends RealTime3DActivity{
private OvergroundActor pocha;
private Ground stage;
private boolean isTouched = false;
private float touchX = 0.0f;