Revision 16b22aab
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java | ||
---|---|---|
27 | 27 |
import org.distorted.library.effect.EffectType; |
28 | 28 |
import org.distorted.library.effect.FragmentEffectChroma; |
29 | 29 |
import org.distorted.library.effect.FragmentEffectContrast; |
30 |
import org.distorted.library.effect.MatrixEffectMove; |
|
31 | 30 |
import org.distorted.library.effect.MatrixEffectScale; |
32 | 31 |
import org.distorted.library.effect.VertexEffectDistort; |
33 | 32 |
import org.distorted.library.effect.VertexEffectPinch; |
... | ... | |
56 | 55 |
private DistortedScreen mScreen; |
57 | 56 |
private MeshFlat mMesh; |
58 | 57 |
private AroundTheWorldEffectsManager mManager; |
59 |
private int mObjWidth, mObjHeight; |
|
60 |
private Static3D mMove, mScale; |
|
58 |
private Static3D mScale; |
|
61 | 59 |
|
62 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 61 |
|
64 | 62 |
AroundTheWorldRenderer(GLSurfaceView view) |
65 | 63 |
{ |
66 |
mMove = new Static3D(0,0,0); |
|
67 | 64 |
mScale= new Static3D(1,1,1); |
68 | 65 |
|
69 | 66 |
mView = view; |
70 | 67 |
mManager = new AroundTheWorldEffectsManager(); |
71 | 68 |
mEffects = new DistortedEffects(); |
72 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
73 | 69 |
mEffects.apply(new MatrixEffectScale(mScale)); |
74 | 70 |
|
75 | 71 |
mManager.apply(mEffects); |
... | ... | |
95 | 91 |
|
96 | 92 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
97 | 93 |
{ |
98 |
if( (float)mObjHeight/mObjWidth > (float)height/width ) |
|
99 |
{ |
|
100 |
int w = (height*mObjWidth)/mObjHeight; |
|
101 |
float factor = (float)height/mObjHeight; |
|
102 |
mMove.set((width-w)/2,0,0); |
|
103 |
mScale.set(factor,factor,factor); |
|
104 |
} |
|
105 |
else |
|
106 |
{ |
|
107 |
int h = (width*mObjHeight)/mObjWidth; |
|
108 |
float factor = (float)width/mObjWidth; |
|
109 |
mMove.set(0,(height-h)/2,0); |
|
110 |
mScale.set(factor,factor,factor); |
|
111 |
} |
|
94 |
float horiRatio = (float)width / mTexture.getWidth(); |
|
95 |
float vertRatio = (float)height/ mTexture.getHeight(); |
|
96 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
112 | 97 |
|
98 |
mScale.set( factor,factor,factor ); |
|
113 | 99 |
mScreen.resize(width,height); |
114 | 100 |
} |
115 | 101 |
|
... | ... | |
133 | 119 |
catch(IOException e) { } |
134 | 120 |
} |
135 | 121 |
|
136 |
mObjWidth = bitmap.getWidth();
|
|
137 |
mObjHeight= bitmap.getHeight();
|
|
122 |
int objWidth = bitmap.getWidth();
|
|
123 |
int objHeight= bitmap.getHeight();
|
|
138 | 124 |
|
139 |
if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
|
|
125 |
if( mTexture==null ) mTexture = new DistortedTexture(objWidth,objHeight);
|
|
140 | 126 |
mTexture.setTexture(bitmap); |
141 | 127 |
|
142 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*mObjHeight/mObjWidth);
|
|
128 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*objHeight/objWidth);
|
|
143 | 129 |
|
144 | 130 |
mScreen.detachAll(); |
145 | 131 |
mScreen.attach(mTexture, mEffects, mMesh); |
src/main/java/org/distorted/examples/blur/BlurRenderer.java | ||
---|---|---|
58 | 58 |
private MeshFlat mMesh; |
59 | 59 |
private Static1D mRadiusSta; |
60 | 60 |
private int mObjHeight, mObjWidth; |
61 |
private Static3D mMove, mScale, mBufferMove, mBufferScale;
|
|
61 |
private Static3D mScale, mBufferScale;
|
|
62 | 62 |
|
63 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 64 |
|
... | ... | |
73 | 73 |
Dynamic1D radiusDyn = new Dynamic1D(); |
74 | 74 |
radiusDyn.add(mRadiusSta); |
75 | 75 |
|
76 |
mMove = new Static3D(0,0,0); |
|
77 | 76 |
mScale= new Static3D(1,1,1); |
78 |
mBufferMove = new Static3D(0,0,0); |
|
79 | 77 |
mBufferScale= new Static3D(1,1,1); |
80 | 78 |
|
81 | 79 |
mBufferEffects = new DistortedEffects(); |
82 |
mBufferEffects.apply(new MatrixEffectMove(mBufferMove)); |
|
83 | 80 |
mBufferEffects.apply(new MatrixEffectScale(mBufferScale)); |
84 | 81 |
|
85 | 82 |
mEffects = new DistortedEffects(); |
86 | 83 |
mEffects.apply( new PostprocessEffectBlur(radiusDyn) ); |
87 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
88 | 84 |
mEffects.apply(new MatrixEffectScale(mScale)); |
89 | 85 |
} |
90 | 86 |
|
... | ... | |
114 | 110 |
float qw1 = (float)width /SIZE; |
115 | 111 |
float qh1 = (float)height/SIZE; |
116 | 112 |
float factor1 = 0.8f* (qw1<qh1 ? qw1:qh1); |
117 |
int w1 = (int)(factor1*SIZE); |
|
118 |
int h1 = (int)(factor1*SIZE); |
|
119 | 113 |
|
120 |
mBufferMove.set((width-w1)/2 ,(height-h1)/2, 0); |
|
121 | 114 |
mBufferScale.set( factor1,factor1,factor1 ); |
122 | 115 |
|
123 | 116 |
float qw2 = (float)SIZE/mObjWidth; |
124 | 117 |
float qh2 = (float)SIZE/mObjHeight; |
125 | 118 |
float factor2 = 0.9f* (qw2<qh2 ? qw2:qh2); |
126 |
int w2 = (int)(factor2*mObjWidth); |
|
127 |
int h2 = (int)(factor2*mObjHeight); |
|
128 | 119 |
|
129 |
mMove.set((SIZE-w2)/2 ,(SIZE-h2)/2, 0); |
|
130 | 120 |
mScale.set( factor2,factor2,factor2 ); |
131 | 121 |
|
132 | 122 |
mScreen.resize(width, height); |
src/main/java/org/distorted/examples/check/CheckRenderer.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import org.distorted.library.effect.EffectType; |
31 | 31 |
import org.distorted.library.effect.FragmentEffectChroma; |
32 |
import org.distorted.library.effect.MatrixEffectMove; |
|
33 | 32 |
import org.distorted.library.effect.MatrixEffectScale; |
34 | 33 |
import org.distorted.library.effect.VertexEffectDeform; |
35 | 34 |
import org.distorted.library.effect.VertexEffectSwirl; |
... | ... | |
66 | 65 |
private MeshFlat mMesh; |
67 | 66 |
private DistortedScreen mScreen; |
68 | 67 |
private int mObjHeight, mObjWidth; |
69 |
private Static3D mMove, mScale, mCenter;
|
|
68 |
private Static3D mScale, mCenter; |
|
70 | 69 |
private Static3D mSwirl1, mSwirl2, mDeform1, mDeform2; |
71 | 70 |
|
72 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
88 | 87 |
mSwirl2 = new Static3D(0,0,0); |
89 | 88 |
mDeform1= new Static3D(0,0,0); |
90 | 89 |
mDeform2= new Static3D(0,0,0); |
91 |
mMove = new Static3D(0,0,0); |
|
92 | 90 |
mScale = new Static3D(1,1,1); |
93 | 91 |
mCenter = new Static3D(0,0,0); |
94 | 92 |
|
95 | 93 |
mEffects = new DistortedEffects(); |
96 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
97 | 94 |
mEffects.apply(new MatrixEffectScale(mScale)); |
98 | 95 |
|
99 | 96 |
// Try adding 2 Vertex Effects to the Bitmap. |
... | ... | |
152 | 149 |
|
153 | 150 |
float factor = xW>xH ? SCALE*xH : SCALE*xW; |
154 | 151 |
|
155 |
mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0); |
|
156 | 152 |
mScale.set(factor,factor,factor); |
157 | 153 |
|
158 | 154 |
mScreen.resize(width,height); |
src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
---|---|---|
63 | 63 |
|
64 | 64 |
private Static4D mRegion; |
65 | 65 |
private int scrHeight, scrWidth; |
66 |
private int textureWidth, textureHeight; |
|
66 | 67 |
private float mRadius; |
67 | 68 |
|
68 | 69 |
private EffectName mMode = EffectName.DISTORT; |
... | ... | |
173 | 174 |
mRegion.set4(mRadius*scrWidth); |
174 | 175 |
|
175 | 176 |
Canvas stretchCanvas; |
176 |
int w=width/2;
|
|
177 |
int h=height/2;
|
|
177 |
textureWidth = (int)(0.6f*width);
|
|
178 |
textureHeight= (int)(0.6f*height);
|
|
178 | 179 |
|
179 | 180 |
if( stretchMesh!=null ) stretchMesh.markForDeletion(); |
180 | 181 |
|
181 |
stretchMesh = new MeshFlat(50,50*h/w);
|
|
182 |
Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
|
|
182 |
stretchMesh = new MeshFlat(50,50*textureHeight/textureWidth);
|
|
183 |
Bitmap stretchBitmap = Bitmap.createBitmap(textureWidth,textureHeight, Bitmap.Config.ARGB_8888);
|
|
183 | 184 |
stretchCanvas = new Canvas(stretchBitmap); |
184 | 185 |
|
185 | 186 |
Paint paint = new Paint(); |
186 | 187 |
paint.setColor(0xff008800); |
187 | 188 |
paint.setStyle(Style.FILL); |
188 |
stretchCanvas.drawRect(0, 0, w, h, paint);
|
|
189 |
stretchCanvas.drawRect(0, 0, textureWidth, textureHeight, paint);
|
|
189 | 190 |
paint.setColor(0xffffffff); |
190 | 191 |
|
191 | 192 |
for(int i=0; i<=NUM_LINES ; i++ ) |
192 | 193 |
{ |
193 |
stretchCanvas.drawRect(w*i/NUM_LINES-1, 0, w*i/NUM_LINES+1, h , paint);
|
|
194 |
stretchCanvas.drawRect( 0, h*i/NUM_LINES-1, w , h*i/NUM_LINES+1, paint);
|
|
194 |
stretchCanvas.drawRect(textureWidth*i/NUM_LINES-1, 0, textureWidth*i/NUM_LINES+1, textureHeight , paint);
|
|
195 |
stretchCanvas.drawRect( 0, textureHeight*i/NUM_LINES-1, textureWidth , textureHeight*i/NUM_LINES+1, paint);
|
|
195 | 196 |
} |
196 | 197 |
|
197 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h);
|
|
198 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(textureWidth,textureHeight);
|
|
198 | 199 |
stretchTexture.setTexture(stretchBitmap); |
199 | 200 |
|
200 | 201 |
mScreen.detachAll(); |
... | ... | |
223 | 224 |
|
224 | 225 |
void down(int x, int y) |
225 | 226 |
{ |
226 |
int xt = x-scrWidth /4; |
|
227 |
int yt = y-scrHeight/4; |
|
228 |
|
|
229 |
if( xt<0 ) xt=0; |
|
230 |
if( xt>scrWidth /2 ) xt=scrWidth/2; |
|
231 |
if( yt<0 ) yt=0; |
|
232 |
if( yt>scrHeight/2 ) yt=scrHeight/2; |
|
233 |
|
|
234 |
mTouchPoint.set(xt, scrHeight/2-yt,0); // OpenGL coord system and 2D coords have inverted Y axis |
|
227 |
int xt = x-(scrWidth -textureWidth )/2; |
|
228 |
int yt = y-(scrHeight-textureHeight)/2; |
|
229 |
|
|
230 |
yt = textureHeight - yt; // OpenGL coord system and 2D coords have inverted Y axis |
|
235 | 231 |
|
236 | 232 |
switch(mMode) |
237 | 233 |
{ |
238 | 234 |
case DISTORT: vDistort[0].set(0,0,0); |
239 | 235 |
stretchEffects.apply(mMovingDistort); |
240 | 236 |
mLastEffect = mMovingDistort.getID(); |
237 |
mTouchPoint.set(xt,yt,0); |
|
241 | 238 |
break; |
242 | 239 |
case DEFORM : vDeform[0].set(0,0,0); |
243 | 240 |
stretchEffects.apply(mMovingDeform); |
244 | 241 |
mLastEffect = mMovingDeform.getID(); |
242 |
mTouchPoint.set(xt,yt,0); |
|
245 | 243 |
break; |
246 | 244 |
case SHEAR : vShear[0].set(0,0,0); |
247 | 245 |
stretchEffects.apply(mMovingShear); |
248 | 246 |
mLastEffect = mMovingShear.getID(); |
247 |
mTouchPoint.set(xt-textureWidth/2,yt-textureHeight/2,0); |
|
249 | 248 |
break; |
250 | 249 |
} |
251 | 250 |
} |
... | ... | |
260 | 259 |
break; |
261 | 260 |
case DEFORM: vDeform[0].set(x,-y,0); |
262 | 261 |
break; |
263 |
case SHEAR: vShear[0].set( (float)x/(scrWidth/2), (float)(-y)/(scrHeight/2), 0);
|
|
262 |
case SHEAR: vShear[0].set( (float)x/textureWidth, (float)(-y)/textureHeight, 0);
|
|
264 | 263 |
break; |
265 | 264 |
} |
266 | 265 |
} |
src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java | ||
---|---|---|
49 | 49 |
|
50 | 50 |
class DifferentBitmapsRenderer implements GLSurfaceView.Renderer |
51 | 51 |
{ |
52 |
private static final int NUM = 3; |
|
52 |
private static final int[] bitmap = { R.raw.dog, R.raw.face, R.raw.cat }; |
|
53 |
private static final int NUM = bitmap.length; |
|
53 | 54 |
|
54 | 55 |
private GLSurfaceView mView; |
55 | 56 |
private DistortedEffects[] mEffects; |
56 | 57 |
private DistortedTexture[] mTexture; |
57 | 58 |
private MeshFlat mMesh; |
58 | 59 |
private DistortedScreen mScreen; |
59 |
private int bmpHeight, bmpWidth; |
|
60 | 60 |
private Static3D mScale; |
61 | 61 |
private Static3D[] mMove; |
62 | 62 |
|
... | ... | |
101 | 101 |
mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
102 | 102 |
} |
103 | 103 |
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
private Bitmap readBitmap(int id) |
|
107 |
{ |
|
108 |
InputStream is = mView.getContext().getResources().openRawResource(id); |
|
109 |
Bitmap bitmap; |
|
110 |
|
|
111 |
try |
|
112 |
{ |
|
113 |
bitmap = BitmapFactory.decodeStream(is); |
|
114 |
} |
|
115 |
finally |
|
116 |
{ |
|
117 |
try |
|
118 |
{ |
|
119 |
is.close(); |
|
120 |
} |
|
121 |
catch(IOException e) { } |
|
122 |
} |
|
123 |
|
|
124 |
return bitmap; |
|
125 |
} |
|
126 |
|
|
127 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
128 | 105 |
|
129 | 106 |
public void onDrawFrame(GL10 glUnused) |
... | ... | |
135 | 112 |
|
136 | 113 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
137 | 114 |
{ |
138 |
if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width ) |
|
139 |
{ |
|
140 |
int w = (height*bmpWidth)/bmpHeight; |
|
141 |
float factor = (float)height/bmpHeight; |
|
142 |
mScale.set(factor,factor,factor); |
|
115 |
float horiRatio = (float)width / (NUM*mTexture[0].getWidth()); |
|
116 |
float vertRatio = (float)height/ ( mTexture[0].getHeight()); |
|
117 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
143 | 118 |
|
144 |
for(int i=NUM-1; i>=0; i--) |
|
145 |
{ |
|
146 |
mMove[i].set((width-NUM*w)/2 +i*w ,0,0); |
|
147 |
} |
|
148 |
} |
|
149 |
else |
|
150 |
{ |
|
151 |
int w = width/NUM; |
|
152 |
int h = (width*bmpHeight)/(bmpWidth*NUM); |
|
153 |
float factor = (float)width/(bmpWidth*NUM); |
|
154 |
mScale.set(factor,factor,factor); |
|
155 |
|
|
156 |
for(int i=NUM-1; i>=0; i--) |
|
157 |
{ |
|
158 |
mMove[i].set(i*w,(height-h)/2,0); |
|
159 |
} |
|
160 |
} |
|
119 |
mScale.set( factor,factor,factor ); |
|
161 | 120 |
|
121 |
for(int i=NUM-1; i>=0; i--) mMove[i].set((i-(NUM-1)/2.0f)*(width/NUM), 0, 0); |
|
162 | 122 |
|
163 | 123 |
mScreen.resize(width, height); |
164 | 124 |
} |
... | ... | |
167 | 127 |
|
168 | 128 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
169 | 129 |
{ |
170 |
Bitmap bitmap0= readBitmap(R.raw.dog); |
|
171 |
Bitmap bitmap1= readBitmap(R.raw.face); |
|
172 |
Bitmap bitmap2= readBitmap(R.raw.cat); |
|
173 |
|
|
174 |
bmpHeight = bitmap0.getHeight(); |
|
175 |
bmpWidth = bitmap0.getWidth(); |
|
130 |
Bitmap[] bmp = new Bitmap[NUM]; |
|
131 |
|
|
132 |
for(int i=0; i<NUM; i++) |
|
133 |
{ |
|
134 |
bmp[i] = readBitmap(bitmap[i]); |
|
135 |
} |
|
136 |
|
|
137 |
int bmpHeight = bmp[0].getHeight(); |
|
138 |
int bmpWidth = bmp[0].getWidth(); |
|
176 | 139 |
|
177 | 140 |
if( mTexture==null ) |
178 | 141 |
{ |
... | ... | |
182 | 145 |
mTexture[i] = new DistortedTexture(bmpWidth,bmpHeight); |
183 | 146 |
} |
184 | 147 |
|
185 |
mTexture[0].setTexture(bitmap0); |
|
186 |
mTexture[1].setTexture(bitmap1); |
|
187 |
mTexture[2].setTexture(bitmap2); |
|
148 |
for(int i=0; i<NUM; i++) |
|
149 |
{ |
|
150 |
mTexture[i].setTexture(bmp[i]); |
|
151 |
} |
|
188 | 152 |
|
189 | 153 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth); |
190 | 154 |
|
... | ... | |
203 | 167 |
android.util.Log.e("Renderer", ex.getMessage() ); |
204 | 168 |
} |
205 | 169 |
} |
170 |
|
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
|
|
173 |
private Bitmap readBitmap(int id) |
|
174 |
{ |
|
175 |
InputStream is = mView.getContext().getResources().openRawResource(id); |
|
176 |
Bitmap bitmap; |
|
177 |
|
|
178 |
try |
|
179 |
{ |
|
180 |
bitmap = BitmapFactory.decodeStream(is); |
|
181 |
} |
|
182 |
finally |
|
183 |
{ |
|
184 |
try |
|
185 |
{ |
|
186 |
is.close(); |
|
187 |
} |
|
188 |
catch(IOException e) { } |
|
189 |
} |
|
190 |
|
|
191 |
return bitmap; |
|
192 |
} |
|
193 |
|
|
206 | 194 |
} |
src/main/java/org/distorted/examples/differenteffects/DifferentEffectsRenderer.java | ||
---|---|---|
58 | 58 |
private DistortedTexture mTexture; |
59 | 59 |
private MeshFlat mMesh; |
60 | 60 |
private DistortedScreen mScreen; |
61 |
private int bmpHeight, bmpWidth; |
|
62 | 61 |
private Static3D mScale; |
63 | 62 |
private Static3D[] mMove; |
64 | 63 |
|
... | ... | |
131 | 130 |
|
132 | 131 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
133 | 132 |
{ |
134 |
if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width ) |
|
135 |
{ |
|
136 |
int w = (height*bmpWidth)/bmpHeight; |
|
137 |
float factor = (float)height/bmpHeight; |
|
138 |
mScale.set(factor,factor,factor); |
|
139 |
for(int i=NUM-1; i>=0; i--) mMove[i].set((width-NUM*w)/2 +i*w , 0, 0); |
|
140 |
} |
|
141 |
else |
|
142 |
{ |
|
143 |
int w = width/NUM; |
|
144 |
int h = (width*bmpHeight)/(bmpWidth*NUM); |
|
145 |
float factor = (float)width/(bmpWidth*NUM); |
|
146 |
mScale.set(factor,factor,factor); |
|
147 |
for(int i=NUM-1; i>=0; i--) mMove[i].set(i*w, (height-h)/2, 0); |
|
148 |
} |
|
149 |
|
|
133 |
float horiRatio = (float)width / (NUM*mTexture.getWidth()); |
|
134 |
float vertRatio = (float)height/ ( mTexture.getHeight()); |
|
135 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
136 |
|
|
137 |
mScale.set( factor,factor,factor ); |
|
138 |
|
|
139 |
for(int i=NUM-1; i>=0; i--) mMove[i].set((i-(NUM-1)/2.0f)*(width/NUM), 0, 0); |
|
140 |
|
|
150 | 141 |
mScreen.resize(width, height); |
151 | 142 |
} |
152 | 143 |
|
... | ... | |
170 | 161 |
catch(IOException e) { } |
171 | 162 |
} |
172 | 163 |
|
173 |
bmpHeight = bitmap.getHeight(); |
|
174 |
bmpWidth = bitmap.getWidth(); |
|
164 |
int bmpHeight = bitmap.getHeight();
|
|
165 |
int bmpWidth = bitmap.getWidth();
|
|
175 | 166 |
|
176 | 167 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth); |
177 | 168 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight); |
src/main/java/org/distorted/examples/earth/EarthRenderer.java | ||
---|---|---|
70 | 70 |
private static final int RADIUS_F= SIZE/15; |
71 | 71 |
private static final int LEVEL = 40; |
72 | 72 |
private static final float FOV = 30.0f; |
73 |
private static final float NEAR = 0.1f;
|
|
73 |
private static final float NEAR = 0.01f;
|
|
74 | 74 |
private static final int MAX_EFF = 20; |
75 | 75 |
private static final float SCALE = 1.10f; |
76 | 76 |
|
... | ... | |
80 | 80 |
private MeshBase mMesh; |
81 | 81 |
private DistortedScreen mScreen; |
82 | 82 |
private int mObjWidth, mObjHeight, mObjDepth; |
83 |
private Static3D mMove, mScaleFactor, mCenter;
|
|
83 |
private Static3D mMove, mScaleFactor; |
|
84 | 84 |
|
85 | 85 |
private int mScrWidth, mScrHeight; |
86 | 86 |
private float mLevel; |
... | ... | |
109 | 109 |
mRegionV = new Static4D(0,0,0,RADIUS_V); |
110 | 110 |
mMove = new Static3D(0,0,0); |
111 | 111 |
mScaleFactor= new Static3D(1,1,1); |
112 |
mCenter = new Static3D(0,0,0); |
|
113 | 112 |
mPinch = new Static2D(0.5f,0.0f); |
114 | 113 |
mSwirl = new Static1D(45.0f); |
115 | 114 |
|
115 |
Static3D center = new Static3D(0,0,0); |
|
116 |
|
|
116 | 117 |
Dynamic3D scale = new Dynamic3D(0,0.5f); |
117 | 118 |
scale.add(mScaleFactor); |
118 | 119 |
|
... | ... | |
135 | 136 |
mEffects = new DistortedEffects(); |
136 | 137 |
mEffects.apply( new MatrixEffectMove(mMove) ); |
137 | 138 |
mEffects.apply( new MatrixEffectScale(scale)); |
138 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
|
|
139 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
|
|
139 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
|
|
140 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
|
|
140 | 141 |
|
141 | 142 |
mScreen = new DistortedScreen(); |
142 | 143 |
mScreen.setProjection(FOV, NEAR); |
... | ... | |
159 | 160 |
|
160 | 161 |
adjustFactor(); |
161 | 162 |
|
162 |
mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, (float)mObjDepth/2 ); |
|
163 | 163 |
mScreen.resize(width, height); |
164 | 164 |
} |
165 | 165 |
|
... | ... | |
167 | 167 |
|
168 | 168 |
void setLevel(int level) |
169 | 169 |
{ |
170 |
float N=3.0f;
|
|
170 |
final float N=2.2f;
|
|
171 | 171 |
|
172 | 172 |
// MAP: 0--> SCALE/N 50-->SCALE 100->SCALE*N |
173 | 173 |
mLevel = SCALE* (1.0f+ (level>=50 ? N-1 : (N-1)/N) * (level-50)/50.0f); |
... | ... | |
184 | 184 |
|
185 | 185 |
float factor = xW>xH ? mLevel*xH : mLevel*xW; |
186 | 186 |
|
187 |
mMove.set( (mScrWidth-factor*mObjWidth)/2 , (mScrHeight-factor*mObjHeight)/2 , -factor*mObjDepth );
|
|
187 |
mMove.set( 0, 0, -factor*mObjDepth );
|
|
188 | 188 |
mScaleFactor.set(factor,factor,factor); |
189 | 189 |
} |
190 | 190 |
|
src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java | ||
---|---|---|
198 | 198 |
{ |
199 | 199 |
tr = (TableRow)mLay.getChildAt(row); |
200 | 200 |
|
201 |
for(int col=0; col<mNumCols; col++)
|
|
201 |
if( tr!=null )
|
|
202 | 202 |
{ |
203 |
butt = (Button)tr.getVirtualChildAt(col); |
|
204 |
butt.setBackgroundColor(mObjectType==0 ? COLOR_ON : COLOR_INAC); |
|
205 |
mShape[row*mNumCols+col] = true; |
|
203 |
for(int col=0; col<mNumCols; col++) |
|
204 |
{ |
|
205 |
butt = (Button)tr.getVirtualChildAt(col); |
|
206 |
butt.setBackgroundColor(mObjectType==0 ? COLOR_ON : COLOR_INAC); |
|
207 |
mShape[row*mNumCols+col] = true; |
|
208 |
} |
|
206 | 209 |
} |
207 | 210 |
} |
208 | 211 |
} |
src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java | ||
---|---|---|
57 | 57 |
private DistortedTexture mObjectTexture, mBackgroundTexture, mCenterTexture, mRegionTexture; |
58 | 58 |
private DistortedScreen mScreen; |
59 | 59 |
private DistortedNode mCenterNode, mRegionNode; |
60 |
private int mObjWidth, mObjHeight, mObjDepth;
|
|
60 |
private int mObjWidth, mObjHeight; |
|
61 | 61 |
private Static3D mCenterPoint, mRegionPoint, mRegionScalePoint; |
62 | 62 |
private Static3D mRotateCen, mMoveObject, mScaleObject, mMoveCenter, mScaleCenter, mMoveRegion, mMoveBackground, mScaleBackground; |
63 | 63 |
private boolean mShowingCenter=false; |
... | ... | |
103 | 103 |
|
104 | 104 |
mObjWidth = mObjectTexture.getWidth(); |
105 | 105 |
mObjHeight= mObjectTexture.getHeight(); |
106 |
mObjDepth = mObjectTexture.getDepth(mesh); |
|
107 | 106 |
|
108 | 107 |
mQuat1 = new Static4D(0,0,0,1); // unity |
109 | 108 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
... | ... | |
143 | 142 |
|
144 | 143 |
resetMatrixEffects(); |
145 | 144 |
|
146 |
// quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() ) |
|
147 | 145 |
backgroundEffects.apply(new MatrixEffectMove(mMoveBackground) ); |
148 | 146 |
backgroundEffects.apply(new MatrixEffectScale(mScaleBackground) ); |
149 | 147 |
} |
... | ... | |
154 | 152 |
{ |
155 | 153 |
Effects3DActivity2 act = (Effects3DActivity2)mView.getContext(); |
156 | 154 |
DistortedEffects objectEffects= act.getEffects(); |
157 |
Static3D rotateObj = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, (float)mObjDepth/2 );
|
|
155 |
Static3D rotateObj = new Static3D( 0,0,0 );
|
|
158 | 156 |
|
159 | 157 |
MatrixEffectQuaternion quat1obj = new MatrixEffectQuaternion(mQuat1, rotateObj); |
160 | 158 |
MatrixEffectQuaternion quat2obj = new MatrixEffectQuaternion(mQuat2, rotateObj); |
... | ... | |
253 | 251 |
mRegionPoint.set(mFactorObj*act.getRegionX(),-mFactorObj*act.getRegionY(),0); |
254 | 252 |
mFactorReg = 2*mFactorObj*act.getRegionR()/regionSize; |
255 | 253 |
mRegionScalePoint.set(mFactorReg,mFactorReg,mFactorReg); |
256 |
mMoveObject.set( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , -mFactorObj*mObjDepth ); |
|
257 | 254 |
mRotateCen.set(width/2,height/2, 0); |
258 | 255 |
mScaleObject.set(mFactorObj,mFactorObj,mFactorObj); |
259 |
mMoveCenter.set( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 , |
|
260 |
(height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , 15 ); |
|
256 |
mMoveCenter.set( 0,0,15);//(width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
|
|
257 |
// (height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , 15 );
|
|
261 | 258 |
mScaleCenter.set(factorCen,factorCen,factorCen); |
262 | 259 |
mMoveRegion.set( (width -mFactorObj*mObjWidth )/2 ,(height-mFactorObj*mObjHeight)/2 , 12 ); |
263 | 260 |
|
... | ... | |
266 | 263 |
float factorBackY = ((float)height)/backgroundSize; |
267 | 264 |
|
268 | 265 |
// quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() ) |
269 |
mMoveBackground.set( -width/2, -height/2, -0.9f*height*(1.0f-NEAR)/(2.0f*(float)Math.tan(FOV*Math.PI/360)) );
|
|
266 |
mMoveBackground.set( 0, 0, -0.9f*height*(1.0f-NEAR)/(2.0f*(float)Math.tan(FOV*Math.PI/360)) );
|
|
270 | 267 |
mScaleBackground.set( 2*factorBackX, 2*factorBackY, 1.0f ); |
271 | 268 |
|
272 | 269 |
mScreen.resize(width, height); |
src/main/java/org/distorted/examples/glow/GlowRenderer.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.distorted.examples.R; |
27 | 27 |
import org.distorted.library.effect.EffectQuality; |
28 |
import org.distorted.library.effect.MatrixEffectMove; |
|
29 | 28 |
import org.distorted.library.effect.MatrixEffectScale; |
30 | 29 |
import org.distorted.library.effect.PostprocessEffectGlow; |
31 | 30 |
import org.distorted.library.main.Distorted; |
... | ... | |
54 | 53 |
private DistortedScreen mScreen; |
55 | 54 |
private PostprocessEffectGlow mGlow; |
56 | 55 |
private int mRootW, mRootH; |
57 |
private Static3D mMove, mScale;
|
|
56 |
private Static3D mScale; |
|
58 | 57 |
private Static1D mRadius; |
59 | 58 |
private Static4D mColor; |
60 | 59 |
|
... | ... | |
67 | 66 |
mRootW = LEAF_SIZE; |
68 | 67 |
mRootH = LEAF_SIZE; |
69 | 68 |
mLeaf = new DistortedTexture(mRootW,mRootH); |
70 |
mMove = new Static3D(0,0,0); |
|
71 | 69 |
mScale = new Static3D(1,1,1); |
72 | 70 |
mRadius= new Static1D(25); |
73 | 71 |
mColor = new Static4D(1.0f,0.0f,0.0f,0.5f); // half-transparent red |
... | ... | |
75 | 73 |
mGlow = new PostprocessEffectGlow(mRadius,mColor); |
76 | 74 |
|
77 | 75 |
DistortedEffects effects = new DistortedEffects(); |
78 |
effects.apply(new MatrixEffectMove(mMove)); |
|
79 | 76 |
effects.apply(new MatrixEffectScale(mScale)); |
80 | 77 |
effects.apply(mGlow); |
81 | 78 |
|
... | ... | |
124 | 121 |
float qw = (float)width /mRootW; |
125 | 122 |
float qh = (float)height/mRootH; |
126 | 123 |
float factor = 0.8f* (qw<qh ? qw:qh); |
127 |
int w = (int)(factor*mRootW); |
|
128 |
int h = (int)(factor*mRootH); |
|
129 | 124 |
|
130 |
mMove.set((width-w)/2 ,(height-h)/2, 0); |
|
131 | 125 |
mScale.set( factor,factor,factor ); |
132 | 126 |
mScreen.resize(width, height); |
133 | 127 |
} |
src/main/java/org/distorted/examples/inflate/InflateRenderer.java | ||
---|---|---|
23 | 23 |
import javax.microedition.khronos.opengles.GL10; |
24 | 24 |
|
25 | 25 |
import org.distorted.library.effect.FragmentEffectAlpha; |
26 |
import org.distorted.library.effect.MatrixEffectMove; |
|
27 | 26 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
28 | 27 |
import org.distorted.library.effect.MatrixEffectScale; |
29 | 28 |
import org.distorted.library.main.DistortedEffects; |
... | ... | |
50 | 49 |
private DistortedEffects mEffects; |
51 | 50 |
private MeshBase mMesh; |
52 | 51 |
private DistortedScreen mScreen; |
53 |
private int mObjWidth, mObjHeight, mObjDepth;
|
|
54 |
private Static3D mMove, mScale, mCenter;
|
|
52 |
private int mObjWidth, mObjHeight; |
|
53 |
private Static3D mScale;
|
|
55 | 54 |
private Static1D mAlpha; |
56 | 55 |
|
57 | 56 |
Static4D mQuat1, mQuat2; |
... | ... | |
65 | 64 |
|
66 | 65 |
mAlpha = new Static1D(1.0f); |
67 | 66 |
|
68 |
mMove = new Static3D(0,0,0); |
|
69 | 67 |
mScale= new Static3D(1,1,1); |
70 |
mCenter=new Static3D(0,0,0); |
|
68 |
|
|
69 |
Static3D center=new Static3D(0,0,0); |
|
71 | 70 |
|
72 | 71 |
InflateActivity2 act = (InflateActivity2)v.getContext(); |
73 | 72 |
|
... | ... | |
76 | 75 |
|
77 | 76 |
mObjWidth = mTexture.getWidth(); |
78 | 77 |
mObjHeight= mTexture.getHeight(); |
79 |
mObjDepth = mTexture.getDepth(mMesh); |
|
80 | 78 |
|
81 | 79 |
mQuat1 = new Static4D(0,0,0,1); // unity |
82 | 80 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
... | ... | |
88 | 86 |
quatInt2.add(mQuat2); |
89 | 87 |
|
90 | 88 |
mEffects = new DistortedEffects(); |
91 |
mEffects.apply( new MatrixEffectMove(mMove) ); |
|
92 | 89 |
mEffects.apply( new MatrixEffectScale(mScale)); |
93 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
|
|
94 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
|
|
90 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
|
|
91 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
|
|
95 | 92 |
mEffects.apply( new FragmentEffectAlpha(mAlpha)); |
96 | 93 |
|
97 | 94 |
mScreen = new DistortedScreen(); |
... | ... | |
114 | 111 |
|
115 | 112 |
mScreenMin = width<height ? width:height; |
116 | 113 |
float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight : (SCALE*width)/mObjWidth; |
117 |
mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , -factor*mObjDepth/2 ); |
|
118 | 114 |
mScale.set(factor,factor,factor); |
119 |
mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, (float)mObjDepth/2 ); |
|
120 | 115 |
mScreen.resize(width, height); |
121 | 116 |
} |
122 | 117 |
|
src/main/java/org/distorted/examples/mirror/MirrorRenderer.java | ||
---|---|---|
102 | 102 |
{ |
103 | 103 |
mX = pos; |
104 | 104 |
|
105 |
float headW = (HEAD_SCALE *mScreenH* mHeadW) / (mScreenW* mHeadH); |
|
105 |
float headWdivScreenW = mScreenW >0 ? (float)mHeadW/mScreenW : 0.0f; |
|
106 |
float left = headWdivScreenW -0.5f + MIRROR_MARGIN; |
|
107 |
float right= -left; |
|
106 | 108 |
|
107 |
mHeadPosition.set1(mX*(1.0f-2*MIRROR_MARGIN-headW)*mScreenW / 100.0f + MIRROR_MARGIN*mScreenW);
|
|
109 |
mHeadPosition.set1( ((right-left)*(mX/100.0f) + left) * mScreenW );
|
|
108 | 110 |
} |
109 | 111 |
|
110 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
138 | 140 |
if( mOffScreen1!=null ) mOffScreen1.markForDeletion(); |
139 | 141 |
if( mOffScreen2!=null ) mOffScreen2.markForDeletion(); |
140 | 142 |
|
141 |
mOffScreen1 = new DistortedFramebuffer( mScreenW, mScreenH, 1, DistortedFramebuffer.NO_DEPTH_NO_STENCIL );
|
|
143 |
mOffScreen1 = new DistortedFramebuffer( mScreenW , mScreenH , 1, DistortedFramebuffer.NO_DEPTH_NO_STENCIL );
|
|
142 | 144 |
mOffScreen2 = new DistortedFramebuffer( (int)(MIRROR_SCALE*mScreenW), (int)(MIRROR_SCALE*mScreenH), 1, DistortedFramebuffer.NO_DEPTH_NO_STENCIL ); |
143 | 145 |
|
144 |
mScaleMirror.set( (float)mScreenW/mMirrorW, (float)mScreenH/mMirrorH, 1.0f); |
|
145 |
mMoveOffscreen2.set( MIRROR_MOVE_H*mScreenW, MIRROR_MOVE_V*mScreenH*mMirrorW/mMirrorH, 0); |
|
146 |
|
|
147 | 146 |
float headScale = HEAD_SCALE *mScreenH/ mHeadH; |
148 | 147 |
mScaleHead.set(headScale,headScale,headScale); |
149 |
mHeadPosition.set2( mScreenH*MIRROR_MARGIN*mMirrorW/mMirrorH ); |
|
148 |
|
|
149 |
float scaleW = (float)mScreenW/mMirrorW; |
|
150 |
float scaleH = (float)mScreenH/mMirrorH; |
|
151 |
|
|
152 |
mScaleMirror.set( scaleW, scaleH, 1.0f); |
|
153 |
|
|
154 |
mMoveOffscreen2.set( (MIRROR_MOVE_H-0.5f+0.5f*MIRROR_SCALE)*mScreenW, (MIRROR_MOVE_V-0.5f+0.5f*MIRROR_SCALE)*mScreenH*mMirrorW/mMirrorH, 0); |
|
155 |
mHeadPosition.set2( (0.5f*HEAD_SCALE - 0.5f + MIRROR_MARGIN*mMirrorW/mMirrorH)*mScreenH ); |
|
156 |
|
|
150 | 157 |
setPosition(mX); |
151 | 158 |
|
152 | 159 |
mOffScreen1.attach( mTextureMirror, mEffectsMirror , mQuad ); |
src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.java | ||
---|---|---|
66 | 66 |
private PostprocessEffectGlow[] mGlow = new PostprocessEffectGlow[NUM_LEAVES]; |
67 | 67 |
private int mRootW, mRootH; |
68 | 68 |
private int mGlowing; |
69 |
private Static3D mMove, mScale;
|
|
69 |
private Static3D mScale; |
|
70 | 70 |
|
71 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
72 | 72 |
|
... | ... | |
83 | 83 |
|
84 | 84 |
DistortedNode root = new DistortedNode(surface, new DistortedEffects(), mesh); |
85 | 85 |
|
86 |
Static3D moveVector = new Static3D(0.55f*LEAF_SIZE, (mRootH-LEAF_SIZE)/2, 0);
|
|
86 |
Static3D moveVector = new Static3D(-1.45f*LEAF_SIZE, 0, 0);
|
|
87 | 87 |
Static1D chromaLevel= new Static1D(0.5f); |
88 |
Static3D center = new Static3D(mRootW/2, mRootH/2, 0);
|
|
88 |
Static3D center = new Static3D(0,0,0);
|
|
89 | 89 |
Static3D axis = new Static3D(0,0,1); |
90 | 90 |
|
91 | 91 |
MatrixEffectMove leafMove = new MatrixEffectMove(moveVector); |
... | ... | |
101 | 101 |
root.attach(node); |
102 | 102 |
} |
103 | 103 |
|
104 |
mMove = new Static3D(0,0,0); |
|
105 | 104 |
mScale= new Static3D(1,1,1); |
106 | 105 |
|
107 | 106 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
... | ... | |
110 | 109 |
rot.add(new Static1D(360)); |
111 | 110 |
|
112 | 111 |
DistortedEffects effects = root.getEffects(); |
113 |
effects.apply(new MatrixEffectMove(mMove)); |
|
114 | 112 |
effects.apply(new MatrixEffectScale(mScale)); |
115 | 113 |
effects.apply( new MatrixEffectRotate(rot, axis, center) ); |
116 | 114 |
|
... | ... | |
176 | 174 |
float qw = (float)width /mRootW; |
177 | 175 |
float qh = (float)height/mRootH; |
178 | 176 |
float factor = 0.9f* (qw<qh ? qw:qh); |
179 |
int w = (int)(factor*mRootW); |
|
180 |
int h = (int)(factor*mRootH); |
|
181 | 177 |
|
182 |
mMove.set((width-w)/2 ,(height-h)/2, 0); |
|
183 | 178 |
mScale.set( factor,factor,factor ); |
184 | 179 |
mScreen.resize(width, height); |
185 | 180 |
} |
src/main/java/org/distorted/examples/multiblur/MultiblurRenderer.java | ||
---|---|---|
73 | 73 |
private PostprocessEffectBlur mBlur; |
74 | 74 |
private int mDistance; |
75 | 75 |
private boolean[] mBlurStatus; |
76 |
private Static3D mMove, mScale, mCenter;
|
|
76 |
private Static3D mScale;
|
|
77 | 77 |
|
78 | 78 |
Static4D mQuat1, mQuat2; |
79 | 79 |
int mScreenMin; |
... | ... | |
121 | 121 |
mBlurStatus[0] = true; |
122 | 122 |
effects[0].apply(mBlur); |
123 | 123 |
|
124 |
mMove = new Static3D(0,0,0); |
|
125 | 124 |
mScale = new Static3D(1,1,1); |
126 |
mCenter = new Static3D(0,0,0);
|
|
125 |
Static3D center = new Static3D(0,0,0);
|
|
127 | 126 |
|
128 |
MatrixEffectMove moveEffect = new MatrixEffectMove(mMove); |
|
129 | 127 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale); |
130 |
MatrixEffectQuaternion quatEffect1 = new MatrixEffectQuaternion(mQuat1, mCenter);
|
|
131 |
MatrixEffectQuaternion quatEffect2 = new MatrixEffectQuaternion(mQuat2, mCenter);
|
|
128 |
MatrixEffectQuaternion quatEffect1 = new MatrixEffectQuaternion(mQuat1, center);
|
|
129 |
MatrixEffectQuaternion quatEffect2 = new MatrixEffectQuaternion(mQuat2, center);
|
|
132 | 130 |
|
133 | 131 |
for(int i=0; i<NUM_OBJECTS; i++) |
134 | 132 |
{ |
135 |
effects[i].apply(moveEffect); |
|
136 | 133 |
effects[i].apply(scaleEffect); |
137 | 134 |
effects[i].apply(quatEffect1); |
138 | 135 |
effects[i].apply(quatEffect2); |
... | ... | |
165 | 162 |
|
166 | 163 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
167 | 164 |
{ |
168 |
mScreenMin = width<height ? width:height; |
|
169 |
|
|
170 |
float factor = 0.15f*mScreenMin/OBJ_SIZE; |
|
165 |
mScreenMin = width<height ? width:height; |
|
166 |
float factor= 0.15f*mScreenMin/OBJ_SIZE; |
|
171 | 167 |
mScale.set(factor,factor,factor); |
172 |
mCenter.set((float)OBJ_SIZE/2, (float)OBJ_SIZE/2, (float)OBJ_SIZE/2 ); |
|
173 |
mMove.set( (width -factor*OBJ_SIZE)/2 ,(height-factor*OBJ_SIZE)/2 , -factor*OBJ_SIZE); |
|
174 | 168 |
computeMoveVectors(); |
175 | 169 |
mScreen.resize(width, height); |
176 | 170 |
} |
... | ... | |
217 | 211 |
|
218 | 212 |
private void computeMoveVectors() |
219 | 213 |
{ |
220 |
float size= 0.026f*OBJ_SIZE*mDistance;
|
|
214 |
float size= 0.020f*OBJ_SIZE*mDistance;
|
|
221 | 215 |
|
222 | 216 |
for(int i=0; i<NUM_OBJECTS; i++) |
223 | 217 |
{ |
... | ... | |
268 | 262 |
{ |
269 | 263 |
android.util.Log.e("renderer", "Error, number: "+number+" checked: "+checked ); |
270 | 264 |
} |
271 |
|
|
272 |
//android.util.Log.d("renderer", "setting box "+number+" BLUR state to "+checked); |
|
273 | 265 |
} |
274 | 266 |
} |
src/main/java/org/distorted/examples/objecttree/ObjectTreeRenderer.java | ||
---|---|---|
28 | 28 |
import org.distorted.examples.R; |
29 | 29 |
|
30 | 30 |
import org.distorted.library.effect.FragmentEffectChroma; |
31 |
import org.distorted.library.effect.MatrixEffectMove; |
|
32 | 31 |
import org.distorted.library.effect.MatrixEffectRotate; |
33 | 32 |
import org.distorted.library.effect.MatrixEffectScale; |
34 | 33 |
import org.distorted.library.effect.VertexEffectSink; |
... | ... | |
62 | 61 |
private DistortedNode mRoot; |
63 | 62 |
private MeshFlat mMeshFlat; |
64 | 63 |
private MeshCubes mMeshCubes; |
65 |
private int lisaHeight, lisaWidth; |
|
66 | 64 |
private boolean mDepth; |
67 |
private Static3D mScale, mMove;
|
|
65 |
private Static3D mScale; |
|
68 | 66 |
|
69 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
70 | 68 |
|
... | ... | |
73 | 71 |
mView = v; |
74 | 72 |
mDepth = true; |
75 | 73 |
mScale = new Static3D(1,1,1); |
76 |
mMove = new Static3D(0,0,0); |
|
77 | 74 |
Dynamic1D chromaDyn = new Dynamic1D(5000,0.0f); |
78 | 75 |
chromaDyn.add(new Static1D(0.0f)); |
79 | 76 |
chromaDyn.add(new Static1D(0.8f)); |
80 | 77 |
|
81 | 78 |
mEffects= new DistortedEffects(); |
82 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
83 | 79 |
mEffects.apply(new MatrixEffectScale(mScale)); |
84 | 80 |
mEffects.apply(new FragmentEffectChroma(chromaDyn, new Static3D(0,0,1))); |
85 | 81 |
|
... | ... | |
118 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
119 | 115 |
|
120 | 116 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
121 |
{ |
|
122 |
if( (float)lisaHeight/lisaWidth > (float)height/width ) |
|
123 |
{ |
|
124 |
int w = (height*lisaWidth)/lisaHeight; |
|
125 |
float factor = (float)height/lisaHeight; |
|
126 |
|
|
127 |
mMove.set((width-w)/2,0,0); |
|
128 |
mScale.set(factor,factor,factor); |
|
129 |
} |
|
130 |
else |
|
131 |
{ |
|
132 |
int h = (width*lisaHeight)/lisaWidth; |
|
133 |
float factor = (float)width/lisaWidth; |
|
117 |
{ |
|
118 |
float horiRatio = (float)width / mLisaTexture.getWidth(); |
|
119 |
float vertRatio = (float)height/ mLisaTexture.getHeight(); |
|
120 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
134 | 121 |
|
135 |
mMove.set(0,(height-h)/2,0); |
|
136 |
mScale.set(factor,factor,factor); |
|
137 |
} |
|
138 |
|
|
122 |
mScale.set( factor,factor,factor ); |
|
139 | 123 |
mScreen.resize(width, height); |
140 | 124 |
} |
141 | 125 |
|
... | ... | |
170 | 154 |
catch(IOException e) { } |
171 | 155 |
} |
172 | 156 |
|
173 |
lisaWidth = bitmap1.getWidth(); |
|
174 |
lisaHeight = bitmap1.getHeight(); |
|
157 |
int lisaWidth = bitmap1.getWidth();
|
|
158 |
int lisaHeight = bitmap1.getHeight();
|
|
175 | 159 |
int gridWidth = bitmap2.getWidth(); |
176 | 160 |
int gridHeight= bitmap2.getHeight(); |
177 | 161 |
|
... | ... | |
200 | 184 |
mScreen.attach(mRoot); |
201 | 185 |
|
202 | 186 |
float factor = lisaWidth/(2.0f*gridWidth); |
203 |
MatrixEffectMove move = new MatrixEffectMove( new Static3D((lisaWidth-factor*gridWidth)/2,(lisaHeight-factor*gridHeight)/2, gridWidth/(2.0f*GRID))); |
|
204 | 187 |
MatrixEffectScale scale = new MatrixEffectScale( new Static3D(factor,factor,factor) ); |
205 |
gridEffects.apply(move); |
|
206 | 188 |
gridEffects.apply(scale); |
207 | 189 |
|
208 | 190 |
Dynamic1D rotDyn = new Dynamic1D(12000,0.0f); |
209 | 191 |
rotDyn.add(new Static1D( 0)); |
210 | 192 |
rotDyn.add(new Static1D(360)); |
211 | 193 |
rotDyn.setMode(Dynamic.MODE_JUMP); |
212 |
MatrixEffectRotate rotate = new MatrixEffectRotate(rotDyn, new Static3D(1,0,0), new Static3D(gridWidth/2,gridHeight/2,gridWidth/(2*GRID)));
|
|
194 |
MatrixEffectRotate rotate = new MatrixEffectRotate(rotDyn, new Static3D(1,0,0), new Static3D(0,0,0));
|
|
213 | 195 |
gridEffects.apply(rotate); |
214 | 196 |
|
215 | 197 |
Dynamic1D sinkDyn = new Dynamic1D(3000,0.0f); |
src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java | ||
---|---|---|
60 | 60 |
private MeshFlat mMesh; |
61 | 61 |
private int mScreenW, mScreenH; |
62 | 62 |
private int mPrevRendered, mCurrRendered; |
63 |
private Static3D mMove, mScale;
|
|
63 |
private Static3D mScale; |
|
64 | 64 |
|
65 | 65 |
private DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES]; |
66 | 66 |
private DistortedEffects[] mEffects = new DistortedEffects[NUM_LEAVES]; |
... | ... | |
96 | 96 |
mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE); |
97 | 97 |
DistortedTexture surface = new DistortedTexture(3*LEAF_SIZE,3*LEAF_SIZE); |
98 | 98 |
mMesh = new MeshFlat(1,1); |
99 |
mMove = new Static3D(0,0,0); |
|
100 | 99 |
mScale= new Static3D(1,1,1); |
101 | 100 |
|
102 | 101 |
DistortedEffects effects = new DistortedEffects(); |
103 |
effects.apply(new MatrixEffectMove(mMove)); |
|
104 | 102 |
effects.apply(new MatrixEffectScale(mScale)); |
105 | 103 |
|
106 | 104 |
mScreenW = 9*LEAF_SIZE; |
107 | 105 |
mScreenH = 9*LEAF_SIZE; |
108 |
mRoot = new DistortedNode(new DistortedTexture(mScreenW,mScreenH), effects, mMesh); |
|
106 |
DistortedTexture rootTexture = new DistortedTexture(mScreenW,mScreenH); |
|
107 |
mRoot = new DistortedNode(rootTexture, effects, mMesh); |
|
109 | 108 |
|
110 | 109 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
111 | 110 |
rot.setMode(Dynamic1D.MODE_JUMP); |
... | ... | |
113 | 112 |
rot.add(new Static1D(360)); |
114 | 113 |
|
115 | 114 |
int[] colors = new int[] {0,0,1, 0,0,0, 1,0,0, 1,1,0, 0,1,0}; // blue, black, red, yellow, green |
116 |
int[] positions = new int[] {0,4*LEAF_SIZE, 3*LEAF_SIZE,4*LEAF_SIZE, 6*LEAF_SIZE,4*LEAF_SIZE, 3*LEAF_SIZE/2,3*LEAF_SIZE/2, 9*LEAF_SIZE/2,3*LEAF_SIZE/2}; |
|
115 |
int[] positions = new int[] {-3*LEAF_SIZE , LEAF_SIZE , |
|
116 |
0 , LEAF_SIZE , |
|
117 |
3*LEAF_SIZE , LEAF_SIZE , |
|
118 |
-3*LEAF_SIZE/2,-3*LEAF_SIZE/2, |
|
119 |
3*LEAF_SIZE/2,-3*LEAF_SIZE/2 }; |
|
117 | 120 |
|
118 |
Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
|
|
121 |
Static3D center = new Static3D(0,0,0);
|
|
119 | 122 |
Static3D axis = new Static3D(0,0,1); |
120 |
Static3D moveVector = new Static3D(0,LEAF_SIZE,0);
|
|
123 |
Static3D moveVector = new Static3D(-LEAF_SIZE,0,0);
|
|
121 | 124 |
|
122 | 125 |
for(int j=0; j<NUM_LEAVES; j++) |
123 | 126 |
{ |
... | ... | |
169 | 172 |
|
170 | 173 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
171 | 174 |
{ |
172 |
if( (float)mScreenH/mScreenW > (float)height/width ) |
|
173 |
{ |
|
174 |
int w = (height*mScreenW)/mScreenH; |
|
175 |
float factor = (float)height/mScreenH; |
|
176 |
mMove.set((width-w)/2 ,0, 0); |
|
177 |
mScale.set(factor,factor,factor); |
|
178 |
} |
|
179 |
else |
|
180 |
{ |
|
181 |
int h = (width*mScreenH)/mScreenW; |
|
182 |
float factor = (float)width/mScreenW; |
|
183 |
mMove.set(0,(height-h)/2,0); |
|
184 |
mScale.set(factor,factor,factor); |
|
185 |
} |
|
186 |
|
|
175 |
float horiRatio = (float)width / mScreenW; |
|
176 |
float vertRatio = (float)height/ mScreenH; |
|
177 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
178 |
|
|
179 |
mScale.set(factor,factor,factor); |
|
187 | 180 |
mScreen.resize(width, height); |
188 | 181 |
} |
189 | 182 |
|
src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeRenderer.java | ||
---|---|---|
56 | 56 |
private DistortedTexture mLeaf; |
57 | 57 |
private DistortedScreen mScreen; |
58 | 58 |
private int mScreenW, mScreenH; |
59 |
private Static3D mMove, mScale;
|
|
59 |
private Static3D mScale; |
|
60 | 60 |
private Static1D mRadius; |
61 | 61 |
|
62 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
79 | 79 |
mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE); |
80 | 80 |
|
81 | 81 |
MeshFlat mesh = new MeshFlat(1,1); |
82 |
mMove = new Static3D(0,0,0); |
|
83 | 82 |
mScale= new Static3D(1,1,1); |
84 | 83 |
|
85 | 84 |
DistortedEffects rootEffects = new DistortedEffects(); |
... | ... | |
89 | 88 |
|
90 | 89 |
DistortedNode root = new DistortedNode(new DistortedTexture(mScreenW,mScreenH), rootEffects, mesh); |
91 | 90 |
|
92 |
rootEffects.apply(new MatrixEffectMove(mMove)); |
|
93 | 91 |
rootEffects.apply(new MatrixEffectScale(mScale)); |
94 | 92 |
rootEffects.apply(blurEffect); |
95 | 93 |
|
... | ... | |
98 | 96 |
rotate.add(new Static1D( 0)); |
99 | 97 |
rotate.add(new Static1D(360)); |
100 | 98 |
|
101 |
Static3D outerCenter = new Static3D(OUTER*LEAF_SIZE/2, OUTER*LEAF_SIZE/2, 0); |
|
102 |
Static3D innerCenter = new Static3D(INNER*LEAF_SIZE/2, INNER*LEAF_SIZE/2, 0); |
|
103 |
|
|
99 |
Static3D center = new Static3D(0,0,0); |
|
104 | 100 |
Static3D axis = new Static3D(0,0,1); |
105 |
Static3D innerMoveVector = new Static3D( 0, (INNER-1)*LEAF_SIZE/2, 0);
|
|
106 |
Static3D outerMoveVector = new Static3D(3*LEAF_SIZE/2, (OUTER-1)*LEAF_SIZE/2, 0);
|
|
101 |
Static3D innerMoveVector = new Static3D( (1-INNER)*LEAF_SIZE/2, 0, 0);
|
|
102 |
Static3D outerMoveVector = new Static3D( (4-OUTER)*LEAF_SIZE/2, 0, 0);
|
|
107 | 103 |
|
108 | 104 |
for(int j=0; j<NUM_LEAVES; j++) |
109 | 105 |
{ |
110 | 106 |
outerLeafEffects[j] = new DistortedEffects(); |
111 |
outerLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, outerCenter) );
|
|
107 |
outerLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
|
|
112 | 108 |
outerLeafEffects[j].apply(new MatrixEffectMove(outerMoveVector)); |
113 | 109 |
|
114 | 110 |
root.attach(mLeaf, outerLeafEffects[j], mesh); |
115 | 111 |
} |
116 | 112 |
|
117 |
innerEffects.apply( new MatrixEffectMove(new Static3D( (OUTER-INNER)*LEAF_SIZE/2,(OUTER-INNER)*LEAF_SIZE/2, 0)) ); |
|
118 |
innerEffects.apply( new MatrixEffectRotate(rotate, axis, innerCenter) ); |
|
113 |
innerEffects.apply( new MatrixEffectRotate(rotate, axis, center) ); |
|
119 | 114 |
innerEffects.apply( new FragmentEffectChroma(new Static1D(0.5f), new Static3D(1,0,0) ) ); |
120 | 115 |
innerEffects.apply(blurEffect); |
121 | 116 |
|
... | ... | |
125 | 120 |
for(int j=0; j<NUM_LEAVES; j++) |
126 | 121 |
{ |
127 | 122 |
innerLeafEffects[j] = new DistortedEffects(); |
128 |
innerLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, innerCenter) );
|
|
123 |
innerLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
|
|
129 | 124 |
innerLeafEffects[j].apply(new MatrixEffectMove(innerMoveVector)); |
130 | 125 |
|
131 | 126 |
innerNode.attach( mLeaf, innerLeafEffects[j], mesh ); |
... | ... | |
155 | 150 |
|
156 | 151 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
157 | 152 |
{ |
158 |
float factor; |
|
159 |
|
|
160 |
if( (float)mScreenH/mScreenW > (float)height/width ) |
|
161 |
{ |
|
162 |
int w = (height*mScreenW)/mScreenH; |
|
163 |
factor = (float)height/mScreenH; |
|
164 |
mMove.set((width-w)/2 ,0, 0); |
|
165 |
} |
|
166 |
else |
|
167 |
{ |
|
168 |
int h = (width*mScreenH)/mScreenW; |
|
169 |
factor = (float)width/mScreenW; |
|
170 |
mMove.set(0,(height-h)/2,0); |
|
171 |
} |
|
153 |
float horiRatio = (float)width / mScreenW; |
|
154 |
float vertRatio = (float)height/ mScreenH; |
|
155 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
172 | 156 |
|
173 | 157 |
mScale.set(factor,factor,factor); |
174 |
|
|
175 | 158 |
mScreen.resize(width, height); |
176 | 159 |
} |
177 | 160 |
|
src/main/java/org/distorted/examples/quaternion/QuaternionRenderer.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import org.distorted.examples.R; |
30 | 30 |
|
31 |
import org.distorted.library.effect.MatrixEffectMove; |
|
32 | 31 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
33 | 32 |
import org.distorted.library.effect.MatrixEffectScale; |
34 | 33 |
import org.distorted.library.main.DistortedEffects; |
35 | 34 |
import org.distorted.library.main.DistortedScreen; |
36 | 35 |
import org.distorted.library.main.DistortedTexture; |
37 |
import org.distorted.library.mesh.MeshBase; |
|
38 | 36 |
import org.distorted.library.mesh.MeshCubes; |
39 | 37 |
import org.distorted.library.type.Dynamic; |
40 | 38 |
import org.distorted.library.type.DynamicQuat; |
... | ... | |
54 | 52 |
|
55 | 53 |
private GLSurfaceView mView; |
56 | 54 |
private DistortedTexture mTexture; |
57 |
private MeshBase mMesh; |
|
58 | 55 |
private DistortedScreen mScreen; |
59 |
private Static3D mMove, mScale, mCenter;
|
|
56 |
private Static3D mScale;
|
|
60 | 57 |
|
61 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 59 |
|
... | ... | |
64 | 61 |
{ |
65 | 62 |
mView = v; |
66 | 63 |
mTexture = new DistortedTexture(1,1); |
67 |
mMesh = new MeshCubes(1,1,1); |
|
68 | 64 |
|
69 | 65 |
DistortedEffects effects = new DistortedEffects(); |
70 | 66 |
DynamicQuat rot = new DynamicQuat(); |
... | ... | |
88 | 84 |
rot.setDuration(8000); |
89 | 85 |
rot.setMode(Dynamic.MODE_LOOP); |
90 | 86 |
|
91 |
mMove = new Static3D(0,0,0); |
|
92 | 87 |
mScale = new Static3D(1,1,1); |
93 |
mCenter = new Static3D(0,0,0); |
|
94 | 88 |
|
95 |
effects.apply( new MatrixEffectMove(mMove)); |
|
96 | 89 |
effects.apply(new MatrixEffectScale(mScale)); |
97 |
effects.apply( new MatrixEffectQuaternion(rot,mCenter) );
|
|
90 |
effects.apply( new MatrixEffectQuaternion(rot,new Static3D(0,0,0)) );
|
|
98 | 91 |
|
99 | 92 |
mScreen = new DistortedScreen(); |
100 |
mScreen.attach(mTexture,effects,mMesh);
|
|
93 |
mScreen.attach(mTexture,effects,new MeshCubes(1,1,1));
|
|
101 | 94 |
} |
102 | 95 |
|
103 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
113 | 106 |
{ |
114 | 107 |
float w = mTexture.getWidth(); |
115 | 108 |
float h = mTexture.getHeight(); |
116 |
float d = mTexture.getDepth(mMesh); |
|
117 |
|
|
118 | 109 |
float factor = 0.5f*(width>height ? height/h:width/w); |
119 | 110 |
|
120 |
mCenter.set(w/2,h/2,d/2); |
|
121 |
mMove.set( (width-factor*w)/2 , (height-factor*h)/2 , -factor*d/2 ); |
|
122 | 111 |
mScale.set(factor,factor,factor); |
123 |
|
|
124 | 112 |
mScreen.resize(width, height); |
125 | 113 |
} |
126 | 114 |
|
src/main/java/org/distorted/examples/rubik/RubikRenderer.java | ||
---|---|---|
49 | 49 |
private GLSurfaceView mView; |
50 | 50 |
private DistortedTexture mTexture; |
51 | 51 |
private DistortedScreen mScreen; |
52 |
private Static3D mMove, mScale, mCenter;
|
|
52 |
private Static3D mScale;
|
|
53 | 53 |
private MeshCubes[][][] mCubes; |
54 | 54 |
private DistortedEffects[][][] mEffects; |
55 | 55 |
|
... | ... | |
72 | 72 |
mEffects = new DistortedEffects[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE]; |
73 | 73 |
Static3D[][][] cubeVectors = new Static3D[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE]; |
74 | 74 |
|
75 |
mMove = new Static3D(0,0,0); |
|
76 | 75 |
mScale = new Static3D(1,1,1); |
77 |
mCenter= new Static3D(0,0,0);
|
|
76 |
Static3D center= new Static3D(0,0,0);
|
|
78 | 77 |
|
79 |
MatrixEffectMove move = new MatrixEffectMove(mMove); |
|
80 | 78 |
MatrixEffectScale scale = new MatrixEffectScale(mScale); |
81 |
MatrixEffectQuaternion quat1 = new MatrixEffectQuaternion(mQuat1, mCenter);
|
|
82 |
MatrixEffectQuaternion quat2 = new MatrixEffectQuaternion(mQuat2, mCenter);
|
|
79 |
MatrixEffectQuaternion quat1 = new MatrixEffectQuaternion(mQuat1, center);
|
|
80 |
MatrixEffectQuaternion quat2 = new MatrixEffectQuaternion(mQuat2, center);
|
|
83 | 81 |
|
84 | 82 |
// 3x2 bitmap = 6 squares: |
85 | 83 |
// |
... | ... | |
120 | 118 |
|
121 | 119 |
mEffects[x][y][z] = new DistortedEffects(); |
122 | 120 |
|
123 |
mEffects[x][y][z].apply(move); |
|
124 | 121 |
mEffects[x][y][z].apply(scale); |
125 | 122 |
mEffects[x][y][z].apply(quat1); |
126 | 123 |
mEffects[x][y][z].apply(quat2); |
... | ... | |
143 | 140 |
|
144 | 141 |
float w = mTexture.getWidth(); |
145 | 142 |
float h = mTexture.getHeight(); |
146 |
float d = mTexture.getDepth(mCubes[0][0][0]); |
|
147 |
|
|
148 | 143 |
float factor = 0.6f*(width>height ? height/h:width/w)/CUBE_SIZE; |
149 | 144 |
|
150 |
mCenter.set(w/2,h/2,d/2); |
|
151 |
mMove.set( (width-factor*w)/2 , (height-factor*h)/2 , -factor*d/2 ); |
|
152 | 145 |
mScale.set(factor,factor,factor); |
153 |
|
|
154 | 146 |
mScreen.resize(width, height); |
155 | 147 |
} |
156 | 148 |
|
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
---|---|---|
200 | 200 |
|
201 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
202 | 202 |
|
203 |
private void setupScreen(int w, int h)
|
|
203 |
private void setupScreen(int scrW, int scrH)
|
|
204 | 204 |
{ |
205 |
double angleA = (90.0f - FOV_ANGLE/2)*Math.PI/180;
|
|
206 |
double angleB = (90.0f - FOV_ANGLE/2 +CRAWL_ANGLE)*Math.PI/180;
|
|
205 |
double angleA = (90.0f - FOV_ANGLE/2 ) * Math.PI/180;
|
|
206 |
double angleB = (90.0f - FOV_ANGLE/2 + CRAWL_ANGLE) * Math.PI/180;
|
|
207 | 207 |
|
208 | 208 |
if( mCrawlBackgroundTexture!=null ) mCrawlBackgroundTexture.markForDeletion(); |
209 |
mCrawlBackgroundTexture = new DistortedTexture(w,(int)(h*Math.sin(angleA)/Math.sin(angleB)));
|
|
210 |
|
|
209 |
mCrawlBackgroundTexture = new DistortedTexture(scrW,(int)(scrH*Math.sin(angleA)/Math.sin(angleB)));
|
|
210 |
|
|
211 | 211 |
int randomA, randomX, randomY, randomTime; |
212 | 212 |
float randomS, randomAlpha1, randomAlpha2; |
213 | 213 |
|
... | ... | |
217 | 217 |
|
218 | 218 |
for(int i=0; i<NUM_STARS; i++) |
219 | 219 |
{ |
220 |
randomX = mRnd.nextInt(w);
|
|
221 |
randomY = mRnd.nextInt(h);
|
|
220 |
randomX = mRnd.nextInt(scrW) - scrW/2;
|
|
221 |
randomY = mRnd.nextInt(scrH) - scrH/2;
|
|
222 | 222 |
randomS = 0.2f+ 0.8f*mRnd.nextFloat(); |
223 | 223 |
randomA = (int)(180*mRnd.nextFloat()); |
224 | 224 |
randomAlpha1 = 0.2f + 0.8f*mRnd.nextFloat(); |
... | ... | |
239 | 239 |
mScreen.attach(mStarTexture, mStarEffects[i], mQuad); |
240 | 240 |
} |
241 | 241 |
|
242 |
float scale = (0.5f*w/mGFFATexture.getWidth());
|
|
242 |
float scale = (0.5f*scrW/mGFFATexture.getWidth());
|
|
243 | 243 |
|
244 | 244 |
Dynamic1D di = new Dynamic1D(6000,0.5f); |
245 | 245 |
di.add(new Static1D(1.0f)); |
246 | 246 |
di.add(new Static1D(1.0f)); |
247 | 247 |
di.add(new Static1D(0.0f)); |
248 | 248 |
|
249 |
mGFFAEffects.apply( new MatrixEffectMove(new Static3D(w/5,2*h/3,0)) );
|
|
249 |
mGFFAEffects.apply( new MatrixEffectMove(new Static3D(-scrW/3 + mGFFATexture.getWidth()/2 ,scrH/6,0)) );
|
|
250 | 250 |
mGFFAEffects.apply( new MatrixEffectScale(scale) ); |
251 | 251 |
mGFFAEffects.apply( new FragmentEffectAlpha(di) ); |
252 | 252 |
|
... | ... | |
382 | 382 |
mGFFATexture.markForDeletion(); |
383 | 383 |
|
384 | 384 |
int screenW=mScreen.getWidth(); |
385 |
int screenH=mScreen.getHeight(); |
|
386 |
|
|
387 | 385 |
int logoW = mLogoTexture.getWidth(); |
388 |
int logoH = mLogoTexture.getHeight(); |
|
389 |
|
|
390 | 386 |
int initSize= (int)(3.0f*screenW/logoW); |
391 | 387 |
int finaSize= (int)(0.1f*screenW/logoW); |
392 | 388 |
|
... | ... | |
394 | 390 |
di.add(new Static3D(initSize,initSize,1)); |
395 | 391 |
di.add(new Static3D(finaSize,finaSize,1)); |
396 | 392 |
|
397 |
mLogoEffects.apply( new MatrixEffectMove(new Static3D(screenW/2,screenH/2,0)) ); |
|
398 | 393 |
mLogoEffects.apply( new MatrixEffectScale(di) ); |
399 |
mLogoEffects.apply( new MatrixEffectMove(new Static3D(-logoW/2,-logoH/2,0)) ); |
|
400 |
|
|
394 |
|
|
401 | 395 |
mScreen.attach(mLogoTexture, mLogoEffects,mQuad); |
402 | 396 |
mLogoEffects.registerForMessages(this); |
403 | 397 |
} |
... | ... | |
409 | 403 |
int crawlW = mCrawlTexture.getWidth(); |
410 | 404 |
int crawlH = mCrawlTexture.getHeight(); |
411 | 405 |
int screenW= mScreen.getWidth(); |
406 |
int screenH= mScreen.getHeight(); |
|
407 |
int backW = mCrawlBackgroundTexture.getWidth(); |
|
412 | 408 |
int backH = mCrawlBackgroundTexture.getHeight(); |
413 |
float scale= (float)screenW/crawlW;
|
|
409 |
float scale= (float)backW/crawlW;
|
|
414 | 410 |
|
415 |
mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,0,0)) ); |
|
411 |
mCrawlBackgroundEffects.apply( new MatrixEffectMove(new Static3D( 0, (backH-screenH)/2, 0)) ); |
|
412 |
mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(0,-backH/2,0)) ); |
|
416 | 413 |
|
417 | 414 |
final int transpDist = 5; |
418 | 415 |
Static3D center = new Static3D( screenW/2 , transpDist*backH , 0 ); |
... | ... | |
420 | 417 |
mCrawlBackgroundEffects.apply( new FragmentEffectAlpha(new Static1D(1-transpDist*0.6f), center, region, true) ); |
421 | 418 |
|
422 | 419 |
Dynamic3D di = new Dynamic3D(70000,0.5f); |
423 |
di.add(new Static3D(screenW/2,-scale*crawlH/2 , 0));
|
|
424 |
di.add(new Static3D(screenW/2,+scale*crawlH/2 + backH, 0));
|
|
420 |
di.add(new Static3D(0, -(scale*crawlH+backH)/2, 0));
|
|
421 |
di.add(new Static3D(0, +(scale*crawlH+backH)/2, 0));
|
|
425 | 422 |
|
426 | 423 |
mCrawlEffects.apply( new MatrixEffectMove(di) ); |
427 | 424 |
mCrawlEffects.apply( new MatrixEffectScale(new Static3D(scale,scale,scale)) ); |
428 |
mCrawlEffects.apply( new MatrixEffectMove(new Static3D(-crawlW/2,-crawlH/2,0)) ); |
|
429 |
|
|
425 |
|
|
430 | 426 |
mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad); |
431 | 427 |
mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad); |
432 | 428 |
mBackground.glDisable(GLES31.GL_DEPTH_TEST); |
src/main/java/org/distorted/examples/stencil/StencilRenderer.java | ||
---|---|---|
56 | 56 |
private DistortedScreen mScreen; |
57 | 57 |
private DistortedTexture mCubeTex, mFloorTex, mFBOTex; |
58 | 58 |
private DistortedNode mCube1Node, mCube2Node, mFloorNode, mFBONode; |
59 |
private Static3D mMove, mScale, mRotCenter, mFBOScale;
|
|
59 |
private Static3D mScale, mFBOScale;
|
|
60 | 60 |
|
61 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 62 |
|
... | ... | |
89 | 89 |
MeshBase cube = new MeshCubes(1,1,1); |
90 | 90 |
MeshBase quad = new MeshQuad(); |
91 | 91 |
|
92 |
mMove = new Static3D(0,0,0); |
|
93 | 92 |
mScale = new Static3D(1,1,1); |
94 |
mRotCenter = new Static3D(0,0,0); |
|
95 | 93 |
mFBOScale = new Static3D(1,1,1); |
96 | 94 |
|
97 | 95 |
mCubeTex = new DistortedTexture(1,1); |
... | ... | |
137 | 135 |
setScreen(true); |
138 | 136 |
|
139 | 137 |
float cw = mCubeTex.getWidth(); |
140 |
float ch = mCubeTex.getHeight(); |
|
141 |
|
|
142 |
float fw = mFloorTex.getWidth(); |
|
143 |
float fh = mFloorTex.getHeight(); |
|
144 | 138 |
|
145 | 139 |
Static3D axisX = new Static3D(1,0,0); |
146 | 140 |
Static3D axisZ = new Static3D(0,0,1); |
... | ... | |
150 | 144 |
rotDyn.add(new Static1D( 0)); |
151 | 145 |
rotDyn.add(new Static1D(360)); |
152 | 146 |
|
147 |
Static3D rotCenter = new Static3D(0,0,0); |
|
148 |
|
|
153 | 149 |
MatrixEffectScale scale = new MatrixEffectScale(mScale); |
154 |
MatrixEffectMove move1 = new MatrixEffectMove( new Static3D( (fw-cw)/2, (fh-ch)/2, 0) ); |
|
155 |
MatrixEffectMove move2 = new MatrixEffectMove( mMove ); |
|
156 |
MatrixEffectRotate rotaX = new MatrixEffectRotate(new Static1D(-60.0f), axisX, mRotCenter); |
|
157 |
MatrixEffectRotate rotaZ = new MatrixEffectRotate(rotDyn, axisZ, mRotCenter); |
|
150 |
MatrixEffectMove move1 = new MatrixEffectMove( new Static3D( 0, 0, cw/2) ); |
|
151 |
MatrixEffectRotate rotaX = new MatrixEffectRotate(new Static1D(-60.0f), axisX, rotCenter); |
|
152 |
MatrixEffectRotate rotaZ = new MatrixEffectRotate(rotDyn, axisZ, rotCenter); |
|
158 | 153 |
|
159 | 154 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
160 | 155 |
// First move the cube and its reflection to the middle of the floor. Then scale the floor, the cube |
... | ... | |
162 | 157 |
// middle of the screen. |
163 | 158 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
164 | 159 |
// The cube |
165 |
cube1Effects.apply( move2 ); |
|
166 | 160 |
cube1Effects.apply( rotaX ); |
167 | 161 |
cube1Effects.apply( rotaZ ); |
168 | 162 |
cube1Effects.apply( scale ); |
169 | 163 |
cube1Effects.apply( move1 ); |
170 | 164 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
171 | 165 |
// Floor |
172 |
floorEffects.apply( move2 ); |
|
173 | 166 |
floorEffects.apply( rotaX ); |
174 | 167 |
floorEffects.apply( rotaZ ); |
175 | 168 |
floorEffects.apply( scale ); |
176 | 169 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
177 | 170 |
// Reflection |
178 |
cube2Effects.apply( move2 ); |
|
179 | 171 |
cube2Effects.apply( rotaX ); |
180 | 172 |
cube2Effects.apply( rotaZ ); |
181 | 173 |
cube2Effects.apply( scale ); |
182 |
cube2Effects.apply( move1 ); |
|
183 | 174 |
cube2Effects.apply( new MatrixEffectScale(new Static3D(1,1,-1)) ); |
175 |
cube2Effects.apply( move1 ); |
|
184 | 176 |
cube2Effects.apply( new FragmentEffectBrightness(new Static1D(0.5f)) ); |
185 | 177 |
|
186 | 178 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
202 | 194 |
float cw = mCubeTex.getWidth(); |
203 | 195 |
float ch = mCubeTex.getHeight(); |
204 | 196 |
|
205 |
float fw = mFloorTex.getWidth(); |
|
206 |
float fh = mFloorTex.getHeight(); |
|
207 |
|
|
208 | 197 |
float bw = mFBOTex.getWidth(); |
Also available in: Unified diff
Fix several more apps for the 'center-of-matrix-effects-in-screen-center' change.