OSDN Git Service

control speed
authoronuxy <n.nanatunoko@gmail.com>
Fri, 16 Nov 2012 05:00:18 +0000 (14:00 +0900)
committeronuxy <n.nanatunoko@gmail.com>
Fri, 16 Nov 2012 05:00:18 +0000 (14:00 +0900)
Polychoron/src/jp/ac/titech/sharp4k/cuten/sampletask/PolychoronTask.java
Polychoron/src/jp/ac/titech/sharp4k/cuten/sampletask/polychoron/GameRender.java
Polychoron/src/jp/ac/titech/sharp4k/cuten/sampletask/polychoron/ModelController.java
Polychoron/src/jp/ac/titech/sharp4k/cuten/sampletask/polychoron/PolychoronObj.java
Polychoron/src/jp/ac/titech/sharp4k/cuten/sampletask/polychoron/PolychoronVertex.java

index fe68bb8..f5ddc7f 100644 (file)
@@ -1,5 +1,7 @@
 package jp.ac.titech.sharp4k.cuten.sampletask;
 
+import java.util.Timer;
+import java.util.TimerTask;
 
 import jp.ac.titech.sharp4k.cuten.BaseApp;
 import jp.ac.titech.sharp4k.cuten.R;
@@ -10,12 +12,12 @@ import jp.ac.titech.sharp4k.cuten.sampletask.polychoron.PolychoronObj;
 import jp.ac.titech.sharp4k.cuten.sampletask.polychoron.ScreenInfo;
 import android.content.Context;
 import android.content.res.Resources;
+import android.os.Handler;
 import android.util.Log;
 import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
-import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 public class PolychoronTask extends BaseApp {
@@ -25,9 +27,16 @@ public class PolychoronTask extends BaseApp {
        private GameSurfaceView view;
        private GameRender renderer;
        private PolychoronObj obj;
-       enum Problem{VERTEX_NUMBER,EDGE_NUMBER,PLANE_NUMBER};
-       private static final Problem prob=Problem.VERTEX_NUMBER;//問題種類指定
+
+       enum Problem {
+               VERTEX_NUMBER, EDGE_NUMBER, PLANE_NUMBER
+       };
+
+       private static final Problem prob = Problem.VERTEX_NUMBER;// 問題種類指定
        RadioGroup radioGroupChoice;
+       Handler handler = new Handler();
+       Timer timer;
+
        @Override
        protected View createView(Context ctx, Resources res) {
                this.ctx = ctx;
@@ -44,13 +53,13 @@ public class PolychoronTask extends BaseApp {
                ScreenInfo screen = new ScreenInfo();
                renderer = new GameRender(view, screen, obj);
                renderer.resouce = res;
-               //ビット深度(RGB=5,6,5),ステンシルバッファ1
-               //デバイスにより異なる可能性あり
+               // ビット深度(RGB=5,6,5),ステンシルバッファ1
+               // デバイスにより異なる可能性あり
                view.setEGLConfigChooser(5, 6, 5, 0, 0, 1);
                view.setRenderer(renderer);
                //
                String question;
-               switch(prob){
+               switch (prob) {
                case VERTEX_NUMBER:
                        question = res.getString(R.string.first_vertex);
                        break;
@@ -61,17 +70,17 @@ public class PolychoronTask extends BaseApp {
                        question = res.getString(R.string.first_plane);
                        break;
                default:
-                       question="";
-                       Log.d(TAG,"no question error");
+                       question = "";
+                       Log.d(TAG, "no question error");
                }
                TextView text = new TextView(ctx);
                text.setText(question);
                questionArea.addView(text);
-               
+
                radioGroupChoice = new RadioGroup(ctx);
                radioGroupChoice.setOrientation(LinearLayout.HORIZONTAL);
 
-               int[] choice=res.getIntArray(R.array.octa_v_choice);
+               int[] choice = res.getIntArray(R.array.octa_v_choice);
                for (int i = 0; i < choice.length; i++) {
                        RadioButton btn = new RadioButton(ctx);
                        btn.setText(String.valueOf(choice[i]));
@@ -81,14 +90,28 @@ public class PolychoronTask extends BaseApp {
                questionArea.addView(radioGroupChoice);
                body.addView(questionArea);
                body.addView(view);
+               //
+               TimerTask task = new TimerTask() {
+                       @Override
+                       public void run() {
+                               handler.post(new Runnable() {
+                                       public void run() {
+                                               renderer.update();
+                                       }
+                               });
+                       }
+               };
+               timer = new Timer(true);
+               timer.schedule(task, 0, 16);//~60fps
                return body;
        }
 
        @Override
        protected void onClose() {
-               int n=radioGroupChoice.getCheckedRadioButtonId();
+               timer.cancel();
+               int n = radioGroupChoice.getCheckedRadioButtonId();
                int ans;
-               switch(prob){
+               switch (prob) {
                case VERTEX_NUMBER:
                        ans = obj.getVertexNum();
                        break;
@@ -99,10 +122,10 @@ public class PolychoronTask extends BaseApp {
                        ans = obj.getPlaneNum();
                        break;
                default:
-                       ans=0;
-                       Log.d(TAG,"no answer error");
+                       ans = 0;
+                       Log.d(TAG, "no answer error");
                }
-               int res=(ans==n)?100:0;
+               int res = (ans == n) ? 100 : 0;
                int[] result = { res };
                sendResult(result);
                super.onClose();
index ccead70..bc1b139 100644 (file)
@@ -3,6 +3,7 @@ package jp.ac.titech.sharp4k.cuten.sampletask.polychoron;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.FloatBuffer;
+import java.util.concurrent.TimeUnit;
 
 import javax.microedition.khronos.egl.EGLConfig;
 import javax.microedition.khronos.opengles.GL10;
@@ -98,7 +99,11 @@ public class GameRender implements Renderer {
        float[] tempVec = new float[3];
        float[] axisA = new float[3];
        float[] axisB = new float[3];
-       
+
+       public void update() {
+               // 表示位置決定
+               obj.nextStep();
+       }
        @Override
        // ここで描画
        public void onDrawFrame(GL10 gl) {
@@ -111,11 +116,11 @@ public class GameRender implements Renderer {
                // 画像の透過の有効化
                GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
                GLES20.glEnable(GLES20.GL_BLEND);
-               // 表示位置決定
                Matrix.setIdentityM(modelMatrix, 0);
                Matrix.rotateM(modelMatrix, 0, 0.2f, 0, 1, 0);
                obj.update();
                obj.sort();
+               
                // 辺
                for (int i = 0; i < obj.getEdgeNum() / 2; i++) {
                        obj.getEdge(drawEdge, i);
@@ -286,6 +291,8 @@ public class GameRender implements Renderer {
                //
                lineBuffer = makeFloatBuffer(ballPosition);
                elPositionBuffer = makeFloatBuffer(elPosition);
+               //
+               
        }
 
        // フロートの配列からフロートバッファを返す
index bcf8576..a1f8110 100644 (file)
@@ -23,6 +23,7 @@ public class ModelController implements OnDoubleTapListener, OnGestureListener,
        // 回転動作中の回転行列
        private float[] rm = new float[16];
        private float scalingSensitivity=5.0f;
+       public float rotSpeed=0.002f;
        
        public ModelController(Context context, PolychoronObj o) {
                obj = o;
@@ -96,7 +97,15 @@ public class ModelController implements OnDoubleTapListener, OnGestureListener,
 
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
-               // TODO Auto-generated method stub
+               if (mode==ModeD4.STOP) {
+                       PolychoronVertex.rotateUX(rot,rotSpeed);
+                       obj.transpose4u(rot);
+                       mode = ModeD4.ZU;
+                       obj.transpose4u(rot);
+               }else{
+                       obj.transpose4u(uniM);
+                       mode = ModeD4.STOP;
+               }
                return false;
        }
 
@@ -108,27 +117,6 @@ public class ModelController implements OnDoubleTapListener, OnGestureListener,
 
        @Override
        public boolean onDoubleTap(MotionEvent e) {
-               switch (mode) {
-               case STOP:
-                       PolychoronVertex.rotateUX(rot,0.05f);
-                       obj.transpose4u(rot);
-                       mode = ModeD4.XU;
-               case XU:
-                       PolychoronVertex.rotateUY(rot,0.05f);
-                       obj.transpose4u(rot);
-                       mode = ModeD4.YU;
-                       break;
-               case YU:
-                       PolychoronVertex.rotateUZ(rot,0.05f);
-                       obj.transpose4u(rot);
-                       mode = ModeD4.ZU;
-                       break;
-               case ZU:
-                       obj.transpose4u(uniM);
-                       mode = ModeD4.STOP;
-                       break;
-               }
-               obj.transpose4u(rot);
                return false;
        }
 
index 0d56567..313abd0 100644 (file)
@@ -70,10 +70,14 @@ public abstract class PolychoronObj {
        PolychoronVertex getVetex(int i) {
                return vertexList[i];
        }
-
+       
+       void nextStep(){
+               for (PolychoronVertex v : vertexList) {
+                       v.nextStep();
+               }
+       }
        void update() {
                for (PolychoronVertex v : vertexList) {
-                       v.update();
                        v.convert1();
                        v.convert2();
                }
index 2c88de1..c082fe9 100644 (file)
@@ -17,7 +17,7 @@ public class PolychoronVertex {
                Matrix.setIdentityM(ms, 0);
        }
 
-       public void update() {
+       public void nextStep() {
                addConvert1(m1u);
        }