Project

General

Profile

« Previous | Next » 

Revision 4d5b37fe

Added by Leszek Koltunski over 7 years ago

Unify Effects3D and Matrix3D (still incomplete!)

View differences:

src/main/java/org/distorted/examples/matrix3d/Matrix3DRenderer.java
19 19

  
20 20
package org.distorted.examples.matrix3d;
21 21

  
22
import java.io.IOException;
23
import java.io.InputStream;
24

  
25
import javax.microedition.khronos.egl.EGLConfig;
26
import javax.microedition.khronos.opengles.GL10;
27

  
28
import org.distorted.examples.R;
22
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
29 24

  
30
import org.distorted.library.DistortedCubes;
31
import org.distorted.library.EffectNames;
32
import org.distorted.library.EffectTypes;
33
import org.distorted.library.type.Dynamic3D;
34
import org.distorted.library.type.Static3D;
35
import org.distorted.library.type.Static4D;
36
import org.distorted.library.type.Dynamic4D;
37 25
import org.distorted.library.Distorted;
26
import org.distorted.library.DistortedObject;
27
import org.distorted.library.EffectTypes;
38 28

  
39
import android.graphics.Bitmap;
40
import android.graphics.BitmapFactory;
41
import android.opengl.GLES20;
42
import android.opengl.GLSurfaceView;
29
import javax.microedition.khronos.egl.EGLConfig;
30
import javax.microedition.khronos.opengles.GL10;
43 31

  
44 32
///////////////////////////////////////////////////////////////////////////////////////////////////
45 33

  
46 34
class Matrix3DRenderer implements GLSurfaceView.Renderer
47 35
{
48
    private static final int SIZE = 100;
49
	
50 36
    private GLSurfaceView mView;
51
    private DistortedCubes mCube;
52
    private EffectNames[] order;
53
    
54
    private Dynamic3D mMoveInter, mScaleInter, mShearInter;
55
    private Dynamic4D mDynamicRotate;
56
    private Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint;
57
    private Static4D mRotatePoint;
37
    private DistortedObject mObject;
58 38

  
59 39
///////////////////////////////////////////////////////////////////////////////////////////////////
60 40

  
61
    void setMove(float x, float y, float z)
41
    Matrix3DRenderer(GLSurfaceView v)
62 42
      {
63
      mMovePoint.set(x, y, z);
64
      }
65
    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
43
      mView = v;
67 44

  
68
    void setScale(float x, float y, float z)
69
      {
70
      mScalePoint.set(x, y, z);
45
      mObject= ((Matrix3DActivity)v.getContext()).getObject();
71 46
      }
72
     
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74 47

  
75
    void setRotate(float a, float x, float y, float z)
76
      {
77
      mRotatePoint.set(a,x,y,z);
78
      }
79
    
80 48
///////////////////////////////////////////////////////////////////////////////////////////////////
81 49

  
82
    void setShear(float x, float y, float z)
50
    public void onDrawFrame(GL10 glUnused)
83 51
      {
84
      mShearPoint.set(x, y, z);
85
      }
52
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
86 53

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
54
      long time = System.currentTimeMillis();
88 55

  
89
    void setOrder(EffectNames[] effects)
90
      {
91
      order = effects;
92
      setMatrixEffects();
56
      mObject.draw(time);
93 57
      }
94
      
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96 58

  
97
    private void setMatrixEffects()
98
      {
99
      mCube.abortEffects(EffectTypes.MATRIX);
100
	
101
      for( int i=0; i<=order.length-1 ; i++ )
102
        {
103
        switch(order[i])
104
          {
105
          case MOVE  : mCube.move(mMoveInter)                 ; break;
106
          case SCALE : mCube.scale(mScaleInter)               ; break;
107
          case ROTATE: mCube.rotate(mDynamicRotate,mZeroPoint); break;
108
          case SHEAR : mCube.shear(mShearInter, mZeroPoint)   ; break;
109
          }
110
        }
111
      }
112
    
113 59
///////////////////////////////////////////////////////////////////////////////////////////////////
114 60

  
115
    Matrix3DRenderer(GLSurfaceView v)
61
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
116 62
      {
117
      mView = v;
118
      mCube = new DistortedCubes( 1, "1", SIZE);
119
      
120
      mZeroPoint   = new Static3D(0,0,0);
121
      mMovePoint   = new Static3D(0,0,0);
122
      mScalePoint  = new Static3D(1,1,1);
123
      mShearPoint  = new Static3D(0,0,0);
124
      mRotatePoint = new Static4D(0,1,0,0);
125

  
126
      mMoveInter    = new Dynamic3D();
127
      mScaleInter   = new Dynamic3D();
128
      mShearInter   = new Dynamic3D();
129
      mDynamicRotate= new Dynamic4D();
130

  
131
      mMoveInter.add(mMovePoint);
132
      mScaleInter.add(mScalePoint);
133
      mShearInter.add(mShearPoint);
134
      mDynamicRotate.add(mRotatePoint);
135
      }
63
      mObject.abortEffects(EffectTypes.MATRIX);
136 64

  
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
   
139
    public void onDrawFrame(GL10 glUnused) 
140
      {
141
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
142
      mCube.draw(System.currentTimeMillis());
65
      Distorted.onSurfaceChanged(width, height);
143 66
      }
144 67

  
145 68
///////////////////////////////////////////////////////////////////////////////////////////////////
146
    
147
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
148
      {
149
      setMatrixEffects();
150

  
151
      Distorted.onSurfaceChanged(width, height); 
152
      }
153 69

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
    
156
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
70
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
157 71
      {
158 72
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
159 73

  
160
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.grid);
161
      Bitmap bitmap;
162
        
163
      try 
164
        {
165
        bitmap = BitmapFactory.decodeStream(is);
166
        } 
167
      finally 
168
        {
169
        try 
170
          {
171
          is.close();
172
          } 
173
        catch(IOException e) { }
174
        }  
175
      
176
      mCube.setBitmap(bitmap);
177
      
74
      Matrix3DActivity act = (Matrix3DActivity)mView.getContext();
75

  
76
      mObject.setBitmap( act.getBitmap() );
77

  
178 78
      try
179 79
        {
180 80
        Distorted.onSurfaceCreated(mView.getContext());
......
184 84
        android.util.Log.e("Matrix3D", ex.getMessage() );
185 85
        }
186 86
      }
187
}
87
}

Also available in: Unified diff