Project

General

Profile

« Previous | Next » 

Revision 2890c5df

Added by Leszek Koltunski almost 7 years ago

Further progress with Apps.

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
44 44
import org.distorted.library.main.MeshObject;
45 45
import org.distorted.library.main.DistortedTexture;
46 46
import org.distorted.library.main.DistortedEffects;
47
import org.distorted.library.EffectNames;
48
import org.distorted.library.EffectTypes;
49 47

  
50 48
import java.io.IOException;
51 49
import java.io.InputStream;
src/main/java/org/distorted/examples/flag/FlagRenderer.java
24 24
import android.opengl.GLSurfaceView;
25 25

  
26 26
import org.distorted.examples.R;
27
import org.distorted.library.effect.EffectName;
28
import org.distorted.library.effect.MatrixEffectMove;
29
import org.distorted.library.effect.MatrixEffectQuaternion;
30
import org.distorted.library.effect.MatrixEffectScale;
31
import org.distorted.library.effect.VertexEffectWave;
27 32
import org.distorted.library.main.Distorted;
28 33
import org.distorted.library.main.DistortedEffects;
29 34
import org.distorted.library.main.DistortedScreen;
30
import org.distorted.library.EffectNames;
31 35
import org.distorted.library.main.MeshCubes;
32 36
import org.distorted.library.main.DistortedTexture;
33
import org.distorted.library.EffectTypes;
34 37
import org.distorted.library.type.Dynamic;
35 38
import org.distorted.library.type.Dynamic5D;
36
import org.distorted.library.type.DynamicQuat;
37 39
import org.distorted.library.type.Static3D;
38 40
import org.distorted.library.type.Static4D;
39 41
import org.distorted.library.type.Static5D;
......
52 54
    private DistortedEffects mEffects;
53 55
    private DistortedTexture mTexture;
54 56
    private DistortedScreen mScreen;
55
    private DynamicQuat mQuatInt1, mQuatInt2;
56 57
    private Dynamic5D mWaveDyn;
57 58
    private Static5D mWaveSta1, mWaveSta2;
58 59
    private int mObjWidth, mObjHeight;
60
    private Static3D mMove, mScale, mCenter;
59 61

  
60 62
    Static4D mQuat1, mQuat2;
61 63
    int mScreenMin;
......
83 85
      mQuat1 = new Static4D(           0,         0,           0,          1);  // unity quaternion
84 86
      mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);  // something semi-random that looks good
85 87

  
86
      mQuatInt1 = new DynamicQuat(0,0.5f);
87
      mQuatInt2 = new DynamicQuat(0,0.5f);
88

  
89
      mQuatInt1.add(mQuat1);
90
      mQuatInt2.add(mQuat2);
91

  
92 88
      Static3D waveCenter = new Static3D(mObjWidth, mObjHeight/2, 0);  // middle of the right edge
93 89
      Static4D waveRegion = new Static4D(0,0,mObjWidth,mObjWidth);
94 90

  
95
      mEffects.wave(mWaveDyn, waveCenter, waveRegion);
91
      mEffects.apply( new VertexEffectWave(mWaveDyn, waveCenter, waveRegion) );
92

  
93
      mMove  = new Static3D(0,0,0);
94
      mScale = new Static3D(1,1,1);
95
      mCenter= new Static3D(0,0,0);
96

  
97
      mEffects.apply( new MatrixEffectMove(mMove));
98
      mEffects.apply( new MatrixEffectScale(mScale));
99
      mEffects.apply( new MatrixEffectQuaternion(mQuat1, mCenter) );
100
      mEffects.apply( new MatrixEffectQuaternion(mQuat2, mCenter) );
96 101

  
97 102
      mScreen = new DistortedScreen(mView);
98 103
      mScreen.attach(mTexture,mEffects, new MeshCubes(50,30,1) );
......
149 154
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
150 155
      {
151 156
      mScreenMin = width<height ? width:height;
152
    	
153
      mEffects.abortEffects(EffectTypes.MATRIX);
154
      float factor;
155

  
156
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
157
        {
158
        factor = (0.8f*height)/mObjHeight;
159
        }
160
      else
161
        {
162
        factor = (0.8f*width)/mObjWidth;
163
        }
164

  
165
      mEffects.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
166
      mEffects.scale(factor);
167
      Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0);
168

  
169
      mEffects.quaternion(mQuatInt1, center);
170
      mEffects.quaternion(mQuatInt2, center);
171
       
157
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.8f*height)/mObjHeight : (0.8f*width)/mObjWidth;
158
      mMove.set((width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
159
      mScale.set(factor,factor,factor);
160
      mCenter.set(mObjWidth/2,mObjHeight/2, 0);
172 161
      mScreen.resize(width, height);
173 162
      }
174 163

  
......
194 183
      
195 184
      mTexture.setTexture(bitmap);
196 185

  
197
      DistortedEffects.enableEffect(EffectNames.WAVE);
186
      DistortedEffects.enableEffect(EffectName.WAVE);
198 187

  
199 188
      try
200 189
        {
src/main/java/org/distorted/examples/girl/GirlRenderer.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.MatrixEffectMove;
32
import org.distorted.library.effect.MatrixEffectScale;
33
import org.distorted.library.effect.VertexEffectDistort;
34
import org.distorted.library.effect.VertexEffectSink;
35
import org.distorted.library.effect.VertexEffectSwirl;
30 36
import org.distorted.library.main.Distorted;
31 37
import org.distorted.library.main.DistortedScreen;
32
import org.distorted.library.EffectNames;
33 38
import org.distorted.library.main.MeshFlat;
34 39
import org.distorted.library.main.DistortedTexture;
35 40
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.EffectTypes;
37 41
import org.distorted.library.type.Dynamic1D;
38 42
import org.distorted.library.type.Dynamic3D;
39 43
import org.distorted.library.type.Static1D;
......
56 60
    private Static3D v0,v1,v2,v3;
57 61
    private Static1D dBegin, dMiddle, dEnd, s0;
58 62
    private int bmpHeight, bmpWidth;
63
    private Static3D mMove, mScale;
59 64

  
60 65
///////////////////////////////////////////////////////////////////////////////////////////////////
61 66

  
......
113 118

  
114 119
      mEffects = new DistortedEffects();
115 120

  
116
      mEffects.sink( diSink, pLeft, sinkRegion );
117
      mEffects.sink( diSink, pRight,sinkRegion );
121
      mEffects.apply( new VertexEffectSink(diSink, pLeft, sinkRegion) );
122
      mEffects.apply( new VertexEffectSink(diSink, pRight,sinkRegion) );
123
      mEffects.apply( new VertexEffectDistort(diL, pLeft , Region) );
124
      mEffects.apply( new VertexEffectDistort(diR, pRight, Region) );
125
      mEffects.apply( new VertexEffectSwirl(diHips, pHips, HipsRegion) );
118 126

  
119
      mEffects.distort(diL, pLeft , Region);
120
      mEffects.distort(diR, pRight, Region);
121

  
122
      mEffects.swirl(diHips, pHips, HipsRegion );
127
      mMove = new Static3D(0,0,0);
128
      mScale= new Static3D(1,1,1);
129
      mEffects.apply(new MatrixEffectMove(mMove));
130
      mEffects.apply(new MatrixEffectScale(mScale));
123 131

  
124 132
      mScreen = new DistortedScreen(mView);
125 133
      }
......
160 168
    
161 169
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
162 170
      { 
163
      mEffects.abortEffects(EffectTypes.MATRIX);
164
      
165 171
      if( (float)bmpHeight/bmpWidth > (float)height/width )
166 172
        {
167 173
        int w = (height*bmpWidth)/bmpHeight;
168 174
        float factor = (float)height/bmpHeight;
169 175

  
170
        mEffects.move( new Static3D((width-w)/2,0,0) );
171
        mEffects.scale(factor);
176
        mMove.set((width-w)/2,0,0);
177
        mScale.set(factor,factor,factor);
172 178
        }
173 179
      else
174 180
        {
175 181
        int h = (width*bmpHeight)/bmpWidth;
176 182
        float factor = (float)width/bmpWidth;
177 183

  
178
        mEffects.move( new Static3D(0,(height-h)/2,0) );
179
        mEffects.scale(factor);
184
        mMove.set(0,(height-h)/2,0);
185
        mScale.set(factor,factor,factor);
180 186
        }
181 187
      
182 188
      mScreen.resize(width, height);
......
213 219
      mScreen.detachAll();
214 220
      mScreen.attach(mTexture,mEffects,mMesh);
215 221

  
216
      DistortedEffects.enableEffect(EffectNames.DISTORT);
217
      DistortedEffects.enableEffect(EffectNames.SINK);
218
      DistortedEffects.enableEffect(EffectNames.SWIRL);
222
      DistortedEffects.enableEffect(EffectName.DISTORT);
223
      DistortedEffects.enableEffect(EffectName.SINK);
224
      DistortedEffects.enableEffect(EffectName.SWIRL);
219 225

  
220 226
      try
221 227
        {
src/main/java/org/distorted/examples/glow/GlowRenderer.java
24 24
import android.opengl.GLSurfaceView;
25 25

  
26 26
import org.distorted.examples.R;
27
import org.distorted.library.effect.EffectName;
28
import org.distorted.library.effect.FragmentEffectChroma;
29
import org.distorted.library.effect.MatrixEffectMove;
30
import org.distorted.library.effect.MatrixEffectRotate;
31
import org.distorted.library.effect.MatrixEffectScale;
32
import org.distorted.library.effect.PostprocessEffectGlow;
27 33
import org.distorted.library.main.Distorted;
28 34
import org.distorted.library.main.DistortedEffects;
29 35
import org.distorted.library.main.DistortedEffectsPostprocess;
30 36
import org.distorted.library.main.DistortedNode;
31 37
import org.distorted.library.main.DistortedScreen;
32 38
import org.distorted.library.main.DistortedTexture;
33
import org.distorted.library.EffectNames;
34
import org.distorted.library.EffectTypes;
35 39
import org.distorted.library.main.MeshFlat;
36 40
import org.distorted.library.main.MeshObject;
37 41
import org.distorted.library.message.EffectListener;
......
57 61
   private static final int NUM_LEAVES= colors.length/3;
58 62
   
59 63
   private GLSurfaceView mView;
60
   private DistortedNode mRoot;
61 64
   private DistortedTexture mLeaf;
62 65
   private DistortedScreen mScreen;
63 66
   private DistortedEffectsPostprocess[] mLeafGlow = new DistortedEffectsPostprocess[NUM_LEAVES];
67
   private PostprocessEffectGlow[] mGlow = new PostprocessEffectGlow[NUM_LEAVES];
64 68
   private int mRootW, mRootH;
65 69
   private int mGlowing;
70
   private Static3D mMove, mScale;
66 71

  
67 72
///////////////////////////////////////////////////////////////////////////////////////////////////
68 73

  
......
78 83
      MeshObject mesh = new MeshFlat(1,1);
79 84
      DistortedEffects[] leafEffects = new DistortedEffects[NUM_LEAVES];
80 85

  
81
      mRoot = new DistortedNode(surface, new DistortedEffects(), mesh);
86
      DistortedNode root = new DistortedNode(surface, new DistortedEffects(), mesh);
82 87
     
83 88
      Static3D moveVector = new Static3D(0,LEAF_SIZE,0);
84 89
      Static1D chromaLevel= new Static1D(0.5f);
85 90
      Static3D center     = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
86 91
      Static3D axis       = new Static3D(0,0,1);
87 92

  
93
      MatrixEffectMove leafMove = new MatrixEffectMove(moveVector);
94

  
88 95
      for(int j=0; j<NUM_LEAVES; j++)
89 96
        {
90 97
        mLeafGlow[j] = new DistortedEffectsPostprocess();
91 98
        mLeafGlow[j].registerForMessages(this);
92 99

  
93 100
        leafEffects[j] = new DistortedEffects();
94
        leafEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
95
        leafEffects[j].move(moveVector);
96
        leafEffects[j].chroma( chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2]) );
101
        leafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
102
        leafEffects[j].apply(leafMove);
103
        leafEffects[j].apply( new FragmentEffectChroma(chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2])) );
97 104
        DistortedNode node = new DistortedNode( mLeaf, leafEffects[j], mesh);
98 105
        node.setPostprocessEffects(mLeafGlow[j]);
99
        mRoot.attach(node);
106
        root.attach(node);
100 107
        }
101 108

  
102 109
      makeGlow(0);
103 110

  
104 111
      mScreen = new DistortedScreen(mView);
105
      mScreen.attach(mRoot);
112
      mScreen.attach(root);
113

  
114
      mMove = new Static3D(0,0,0);
115
      mScale= new Static3D(1,1,1);
116

  
117
      Dynamic1D rot = new Dynamic1D(5000,0.0f);
118
      rot.setMode(Dynamic1D.MODE_JUMP);
119
      rot.add(new Static1D(  0));
120
      rot.add(new Static1D(360));
121

  
122
      DistortedEffects effects = root.getEffects();
123
      effects.apply(new MatrixEffectMove(mMove));
124
      effects.apply(new MatrixEffectScale(mScale));
125
      effects.apply( new MatrixEffectRotate(rot, axis, center) );
126

  
127
      Dynamic1D radius = new Dynamic1D(5000,1.0f);
128
      Static1D startR  = new Static1D( 0);
129
      Static1D endR    = new Static1D(50);
130
      radius.add(startR);
131
      radius.add(endR);
132

  
133
      for(int leaf=0; leaf<NUM_LEAVES; leaf++)
134
        {
135
        Dynamic4D color  = new Dynamic4D(5000,1.0f);
136
        Static4D startC  = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 0);
137
        Static4D endC    = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 1);
138
        color.add(startC);
139
        color.add(endC);
140

  
141
        mGlow[leaf] = new PostprocessEffectGlow(radius,color);
142
        }
106 143
      }
107 144

  
108 145
///////////////////////////////////////////////////////////////////////////////////////////////////
......
112 149
     //android.util.Log.e("glow", "glowing: "+leaf);
113 150

  
114 151
     mGlowing = leaf;
115

  
116
     Dynamic1D radius = new Dynamic1D(5000,1.0f);
117
     Static1D startR  = new Static1D( 0);
118
     Static1D endR    = new Static1D(50);
119
     radius.add(startR);
120
     radius.add(endR);
121

  
122
     Dynamic4D color  = new Dynamic4D(5000,1.0f);
123
     Static4D startC  = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 0);
124
     Static4D endC    = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 1);
125
     color.add(startC);
126
     color.add(endC);
127

  
128
     mLeafGlow[leaf].glow( radius, color );
152
     mLeafGlow[leaf].apply(mGlow[leaf]);
129 153
     }
130 154

  
131 155
///////////////////////////////////////////////////////////////////////////////////////////////////
132 156
// Glow finished. Make the next Leaf glow.
133 157

  
134
   public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID)
158
   public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
135 159
     {
136 160
     switch(em)
137 161
       {
......
162 186
     int w = (int)(factor*mRootW);
163 187
     int h = (int)(factor*mRootH);
164 188

  
165
     Dynamic1D rot = new Dynamic1D(5000,0.0f);
166
     rot.setMode(Dynamic1D.MODE_JUMP);
167
     rot.add(new Static1D(  0));
168
     rot.add(new Static1D(360));
169

  
170
     Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
171
     Static3D axis   = new Static3D(0,0,1);
172

  
173
     DistortedEffects effects = mRoot.getEffects();
174
     effects.abortEffects(EffectTypes.MATRIX);
175
     effects.move( new Static3D((width-w)/2 ,(height-h)/2, 0) );
176
     effects.scale( factor );
177
     effects.rotate( rot, axis, center );
178

  
189
     mMove.set((width-w)/2 ,(height-h)/2, 0);
190
     mScale.set( factor,factor,factor );
179 191
     mScreen.resize(width, height);
180 192
     }
181 193

  
......
201 213
      
202 214
     mLeaf.setTexture(leaf);
203 215

  
204
     DistortedEffects.enableEffect(EffectNames.CHROMA);
205
     DistortedEffects.enableEffect(EffectNames.GLOW);
216
     DistortedEffects.enableEffect(EffectName.CHROMA);
217
     DistortedEffects.enableEffect(EffectName.GLOW);
206 218

  
207 219
     try
208 220
       {

Also available in: Unified diff