Project

General

Profile

« Previous | Next » 

Revision 37b324c4

Added by Leszek Koltunski almost 7 years ago

Further progress with Apps.

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java
51 51
   private MeshFlat mMesh;
52 52
   private AroundTheWorldEffectsManager mManager;
53 53
   private int mObjWidth, mObjHeight;
54

  
55 54
   private Static3D mMove, mScale;
56 55

  
57 56
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/check/CheckRenderer.java
27 27

  
28 28
import org.distorted.examples.R;
29 29

  
30
import org.distorted.library.effect.EffectName;
31
import org.distorted.library.effect.FragmentEffectChroma;
32
import org.distorted.library.effect.MatrixEffectMove;
33
import org.distorted.library.effect.MatrixEffectScale;
34
import org.distorted.library.effect.VertexEffectDeform;
35
import org.distorted.library.effect.VertexEffectSwirl;
30 36
import org.distorted.library.main.Distorted;
31 37
import org.distorted.library.main.DistortedEffects;
32 38
import org.distorted.library.main.DistortedScreen;
33 39
import org.distorted.library.main.DistortedTexture;
34
import org.distorted.library.EffectNames;
35 40
import org.distorted.library.main.MeshFlat;
36
import org.distorted.library.EffectTypes;
37 41
import org.distorted.library.type.Dynamic3D;
38 42
import org.distorted.library.type.Static1D;
39 43
import org.distorted.library.type.Static3D;
......
61 65
    private DistortedTexture mTexture;
62 66
    private MeshFlat mMesh;
63 67
    private DistortedScreen mScreen;
64
    private int bmpHeight, bmpWidth;
68
    private int mObjHeight, mObjWidth;
69
    private Static3D mMove, mScale;
70
    private Static3D mSwirl1, mSwirl2, mDeform1, mDeform2;
65 71

  
66 72
///////////////////////////////////////////////////////////////////////////////////////////////////
67 73

  
68 74
    CheckRenderer(GLSurfaceView view)
69 75
      { 
70 76
      mView = view;
71
      mEffects = new DistortedEffects();
72 77

  
73 78
      CheckActivity act = (CheckActivity)mView.getContext();
74 79

  
75 80
      DistortedEffects.setMaxVertex(act.getMaxV());
76 81
      DistortedEffects.setMaxFragment(act.getMaxF());
82
      DistortedEffects.enableEffect(EffectName.SWIRL);
83
      DistortedEffects.enableEffect(EffectName.DEFORM);
84
      DistortedEffects.enableEffect(EffectName.CHROMA);
85

  
86
      mSwirl1 = new Static3D(0,0,0);
87
      mSwirl2 = new Static3D(0,0,0);
88
      mDeform1= new Static3D(0,0,0);
89
      mDeform2= new Static3D(0,0,0);
90

  
91
      mMove = new Static3D(0,0,0);
92
      mScale= new Static3D(1,1,1);
93
      mEffects = new DistortedEffects();
94
      mEffects.apply(new MatrixEffectMove(mMove));
95
      mEffects.apply(new MatrixEffectScale(mScale));
96

  
97
      // Try adding 2 Vertex Effects to the Bitmap.
98
      // This will fail if we have set maxVertexEffects to something < 2.
99
      //
100
      // Even if adding some of the Effects fails, the App will still start - you just won't see
101
      // the effects that failed to add.
102

  
103
      Dynamic3D dSwirl = new Dynamic3D(2000,0.0f);
104
      dSwirl.add(mSwirl1);
105
      dSwirl.add(mSwirl2);
106

  
107
      if( !mEffects.apply( new VertexEffectSwirl(new Static1D(30), dSwirl, new Static4D( 0,0,40,40)) ) )
108
        {
109
        Log.e("Check", "Failed to add Swirl effect!");
110
        }
111

  
112
      Dynamic3D dDeform = new Dynamic3D(2000,0.0f);
113
      dDeform.add(mDeform1);
114
      dDeform.add(mDeform2);
115

  
116
      if( !mEffects.apply( new VertexEffectDeform(dDeform, new Static3D(mObjWidth/2,0,0)) ) )
117
        {
118
        Log.e("Check", "Failed to add Deform effect!");
119
        }
120

  
121
      // Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
122
      Static3D color = new Static3D(1,0,0);
123
      Dynamic1D inter = new Dynamic1D(2000,0.0f);
124
      inter.add(new Static1D(0));
125
      inter.add(new Static1D(1));
126

  
127
      if( !mEffects.apply( new FragmentEffectChroma(inter, color) ) )
128
        {
129
        Log.e("Check", "Failed to add Chroma effect!");
130
        }
77 131

  
78 132
      mScreen = new DistortedScreen(mView);
79 133
      }
......
89 143
    
90 144
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
91 145
      { 
92
      mEffects.abortEffects(EffectTypes.MATRIX);
93
      
94
      if( (float)bmpHeight/bmpWidth > (float)height/width )
146
      if( (float)mObjHeight/mObjWidth > (float)height/width )
95 147
        {
96
        int w = (height*bmpWidth)/bmpHeight;
97
        float factor = (float)height/bmpHeight;
98

  
99
        mEffects.move( new Static3D((width-w)/2,0,0) );
100
        mEffects.scale(factor);
148
        int w = (height*mObjWidth)/mObjHeight;
149
        float factor = (float)height/mObjHeight;
150
        mMove.set((width-w)/2,0,0);
151
        mScale.set(factor,factor,factor);
101 152
        }
102 153
      else
103 154
        {
104
        int h = (width*bmpHeight)/bmpWidth;
105
        float factor = (float)width/bmpWidth;
106

  
107
        mEffects.move( new Static3D(0,(height-h)/2,0) );
108
        mEffects.scale(factor);
155
        int h = (width*mObjHeight)/mObjWidth;
156
        float factor = (float)width/mObjWidth;
157
        mMove.set(0,(height-h)/2,0);
158
        mScale.set(factor,factor,factor);
109 159
        }
110
      
111
      mScreen.resize(width, height);
160

  
161
      mScreen.resize(width,height);
112 162
      }
113 163

  
114 164
///////////////////////////////////////////////////////////////////////////////////////////////////
......
131 181
        catch(IOException e) { }
132 182
        }
133 183

  
134
      bmpHeight = bitmap.getHeight();
135
      bmpWidth  = bitmap.getWidth();
184
      mObjHeight = bitmap.getHeight();
185
      mObjWidth  = bitmap.getWidth();
136 186

  
137
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
187
      if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
138 188
      mTexture.setTexture(bitmap);
139 189

  
140
      if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
190
      if( mMesh==null ) mMesh = new MeshFlat(30,30*mObjHeight/mObjWidth);
141 191

  
142 192
      mScreen.detachAll();
143 193
      mScreen.attach(mTexture,mEffects,mMesh);
144 194

  
145
      mEffects.abortEffects(EffectTypes.VERTEX);
146
      mEffects.abortEffects(EffectTypes.FRAGMENT);
147

  
148
      // Try adding 2 Vertex Effects to the Bitmap.
149
      // This will fail if we have set maxVertexEffects to something < 2.
150
      //
151
      // Even if adding some of the Effects fails, the App will still start - you just won't see
152
      // the effects that failed to add.
153

  
154
      Dynamic3D dSwirl = new Dynamic3D(2000,0.0f);
155
      dSwirl.add(new Static3D(        0, bmpHeight/2, 0));
156
      dSwirl.add(new Static3D( bmpWidth, bmpHeight/2, 0));
157

  
158
      long swirlEffectID = mEffects.swirl( new Static1D(30), dSwirl, new Static4D( 0,0,40,40) );
159

  
160
      if( swirlEffectID<0 )
161
        {
162
        Log.e("Check", "Failed to add Swirl effect!");
163
        }
164

  
165
      Dynamic3D dDeform = new Dynamic3D(2000,0.0f);
166
      dDeform.add(new Static3D( 0,         0,0));
167
      dDeform.add(new Static3D( 0,-bmpHeight,0));
168

  
169
      long deformEffectID = mEffects.deform(dDeform, new Static3D(bmpWidth/2,0,0) );
170

  
171
      if( deformEffectID<0 )
172
        {
173
        Log.e("Check", "Failed to add Deform effect!");
174
        }
175

  
176
      // Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
177
      Static3D color = new Static3D(1,0,0);
178
      Dynamic1D inter = new Dynamic1D(2000,0.0f);
179
      inter.add(new Static1D(0));
180
      inter.add(new Static1D(1));
181

  
182
      long chromaEffectID = mEffects.chroma(inter, color);
183

  
184
      if( chromaEffectID<0 )
185
        {
186
        Log.e("Check", "Failed to add Chroma effect!");
187
        }
188

  
189
      DistortedEffects.enableEffect(EffectNames.SWIRL);
190
      DistortedEffects.enableEffect(EffectNames.DEFORM);
191
      DistortedEffects.enableEffect(EffectNames.CHROMA);
195
      mSwirl1.set (        0, mObjHeight/2, 0);
196
      mSwirl2.set (mObjWidth, mObjHeight/2, 0);
197
      mDeform1.set(        0,         0   , 0);
198
      mDeform2.set(        0,-mObjHeight  , 0);
192 199

  
193 200
      try
194 201
        {
src/main/java/org/distorted/examples/cubes/CubesRenderer.java
27 27

  
28 28
import org.distorted.examples.R;
29 29

  
30
import org.distorted.library.effect.MatrixEffectMove;
31
import org.distorted.library.effect.MatrixEffectQuaternion;
32
import org.distorted.library.effect.MatrixEffectScale;
30 33
import org.distorted.library.main.DistortedEffects;
31 34
import org.distorted.library.main.DistortedScreen;
32 35
import org.distorted.library.main.DistortedTexture;
33 36
import org.distorted.library.main.MeshObject;
34
import org.distorted.library.EffectTypes;
35 37
import org.distorted.library.type.DynamicQuat;
36 38
import org.distorted.library.type.Static4D;
37 39
import org.distorted.library.type.Static3D;
......
50 52
    private DistortedEffects mEffects;
51 53
    private MeshObject mMesh;
52 54
    private DistortedScreen mScreen;
53
    private DynamicQuat mQuatInt1, mQuatInt2;
54 55
    private int mObjWidth, mObjHeight, mObjDepth;
56
    private Static3D mMove, mScale, mCenter;
55 57

  
56 58
    Static4D mQuat1, mQuat2;
57 59
    int mScreenMin;
......
62 64
      {
63 65
      mView = v;
64 66

  
67
      mMove = new Static3D(0,0,0);
68
      mScale= new Static3D(1,1,1);
69
      mCenter=new Static3D(0,0,0);
70

  
65 71
      CubesActivity act = (CubesActivity)v.getContext();
66 72

  
67
      mEffects = new DistortedEffects();
68 73
      mTexture = act.getTexture();
69 74
      mMesh = act.getMesh();
70 75

  
......
75 80
      mQuat1 = new Static4D(0,0,0,1);  // unity
76 81
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
77 82
      
78
      mQuatInt1 = new DynamicQuat(0,0.5f);
79
      mQuatInt2 = new DynamicQuat(0,0.5f);
83
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
84
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
85

  
86
      quatInt1.add(mQuat1);
87
      quatInt2.add(mQuat2);
80 88

  
81
      mQuatInt1.add(mQuat1);
82
      mQuatInt2.add(mQuat2);
89
      mEffects = new DistortedEffects();
90
      mEffects.apply( new MatrixEffectMove(mMove) );
91
      mEffects.apply( new MatrixEffectScale(mScale));
92
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
93
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
83 94

  
84 95
      mScreen = new DistortedScreen(mView);
85 96
      }
......
96 107
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
97 108
      {
98 109
      mScreenMin = width<height ? width:height;
99
    	
100
      mEffects.abortEffects(EffectTypes.MATRIX);
101
      float factor;
102

  
103
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
104
        {
105
        factor = (0.75f*height)/mObjHeight;
106
        }
107
      else
108
        {
109
        factor = (0.75f*width)/mObjWidth;
110
        }
111

  
112
      mEffects.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
113
      mEffects.scale(factor);
114
      Static3D center = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
115

  
116
      mEffects.quaternion(mQuatInt1, center);
117
      mEffects.quaternion(mQuatInt2, center);
118
       
110
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.75f*height)/mObjHeight :  (0.75f*width)/mObjWidth;
111
      mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
112
      mScale.set(factor,factor,factor);
113
      mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
119 114
      mScreen.resize(width, height);
120 115
      }
121 116

  

Also available in: Unified diff