| |
---|
| | 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; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |