Revision f793bd9d
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/examples/meshjoin/MeshJoinRenderer.java | ||
---|---|---|
20 | 20 |
package org.distorted.examples.meshjoin; |
21 | 21 |
|
22 | 22 |
import android.graphics.Bitmap; |
23 |
import android.graphics.BitmapFactory; |
|
24 | 23 |
import android.graphics.Canvas; |
25 | 24 |
import android.graphics.Paint; |
26 | 25 |
import android.opengl.GLSurfaceView; |
27 | 26 |
|
28 |
import org.distorted.examples.R; |
|
29 | 27 |
import org.distorted.library.effect.MatrixEffect; |
30 | 28 |
import org.distorted.library.effect.MatrixEffectMove; |
31 | 29 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
... | ... | |
45 | 43 |
import org.distorted.library.type.Static3D; |
46 | 44 |
import org.distorted.library.type.Static4D; |
47 | 45 |
|
48 |
import java.io.IOException; |
|
49 |
import java.io.InputStream; |
|
50 |
|
|
51 | 46 |
import javax.microedition.khronos.egl.EGLConfig; |
52 | 47 |
import javax.microedition.khronos.opengles.GL10; |
53 | 48 |
|
... | ... | |
118 | 113 |
|
119 | 114 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
120 | 115 |
{ |
121 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.pyraminx); |
|
122 |
Bitmap bitmap; |
|
123 |
|
|
124 |
try |
|
125 |
{ |
|
126 |
bitmap = BitmapFactory.decodeStream(is); |
|
127 |
} |
|
128 |
finally |
|
129 |
{ |
|
130 |
try |
|
131 |
{ |
|
132 |
is.close(); |
|
133 |
} |
|
134 |
catch(IOException e) { } |
|
135 |
} |
|
136 |
|
|
137 | 116 |
if( mTexture==null ) mTexture = new DistortedTexture(); |
138 |
mTexture.setTexture( createTetrahedronTexture(bitmap) );
|
|
117 |
mTexture.setTexture( createTetrahedronTexture() ); |
|
139 | 118 |
|
140 | 119 |
if( mMesh==null ) mMesh = createJoinedTetrahedron(); |
141 | 120 |
|
... | ... | |
156 | 135 |
|
157 | 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
158 | 137 |
|
159 |
private Bitmap createTetrahedronTexture(Bitmap input)
|
|
138 |
private Bitmap createTetrahedronTexture() |
|
160 | 139 |
{ |
161 | 140 |
final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 }; |
162 | 141 |
final int FACES=FACE_COLORS.length; |
163 |
int height = input.getHeight(); |
|
164 |
|
|
165 |
Bitmap result = Bitmap.createBitmap(FACES*height,height, Bitmap.Config.ARGB_8888); |
|
142 |
int SIZE = 128; |
|
143 |
int STROKE = SIZE/20; |
|
144 |
int OFF = STROKE/2 -1; |
|
145 |
int OFF2 = (int)(0.577f*SIZE) + OFF; |
|
146 |
int HEIGHT = SIZE - OFF; |
|
147 |
int RADIUS = SIZE/12; |
|
148 |
int ARC1_H = (int)(0.31f*SIZE); |
|
149 |
float ARC1_W = SIZE*0.5f; |
|
150 |
float ARC2_W = 19.5f; |
|
151 |
float ARC2_H = 116.5f; |
|
152 |
float ARC3_W = 108.5f; |
|
153 |
|
|
154 |
Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888); |
|
166 | 155 |
Canvas canvas = new Canvas(result); |
167 | 156 |
Paint paint = new Paint(); |
168 |
paint.setStyle(Paint.Style.FILL); |
|
157 |
paint.setAntiAlias(true); |
|
158 |
paint.setStrokeWidth(STROKE); |
|
169 | 159 |
|
170 | 160 |
for(int i=0; i<FACES; i++) |
171 | 161 |
{ |
172 | 162 |
paint.setColor(FACE_COLORS[i]); |
173 |
canvas.drawRect(i*height,0,(i+1)*height,height,paint); |
|
174 |
canvas.drawBitmap(input,i*height,0,null); |
|
163 |
paint.setStyle(Paint.Style.FILL); |
|
164 |
|
|
165 |
canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint); |
|
166 |
|
|
167 |
paint.setColor(0xff000000); |
|
168 |
paint.setStyle(Paint.Style.STROKE); |
|
169 |
|
|
170 |
canvas.drawLine( i*SIZE, HEIGHT, SIZE +i*SIZE, HEIGHT, paint); |
|
171 |
canvas.drawLine( OFF +i*SIZE, SIZE, OFF2 +i*SIZE, 0, paint); |
|
172 |
canvas.drawLine((SIZE-OFF)+i*SIZE, SIZE, (SIZE-OFF2) +i*SIZE, 0, paint); |
|
173 |
|
|
174 |
canvas.drawArc( ARC1_W-RADIUS+i*SIZE, ARC1_H-RADIUS, ARC1_W+RADIUS+i*SIZE, ARC1_H+RADIUS, 225, 90, false, paint); |
|
175 |
canvas.drawArc( ARC2_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC2_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 105, 90, false, paint); |
|
176 |
canvas.drawArc( ARC3_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC3_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 345, 90, false, paint); |
|
175 | 177 |
} |
176 | 178 |
|
177 | 179 |
return result; |
Also available in: Unified diff
Minor.