Revision ba984444
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java | ||
|---|---|---|
| 25 | 25 |
import android.opengl.GLSurfaceView; |
| 26 | 26 |
|
| 27 | 27 |
import org.distorted.library.effect.EffectType; |
| 28 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 28 | 29 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
| 29 | 30 |
import org.distorted.library.effect.MatrixEffectScale; |
| 30 |
import org.distorted.library.effect.VertexEffectMove; |
|
| 31 | 31 |
import org.distorted.library.effect.VertexEffectRotate; |
| 32 | 32 |
import org.distorted.library.main.DistortedEffects; |
| 33 | 33 |
import org.distorted.library.main.DistortedLibrary; |
| ... | ... | |
| 35 | 35 |
import org.distorted.library.main.DistortedTexture; |
| 36 | 36 |
import org.distorted.library.mesh.MeshBase; |
| 37 | 37 |
import org.distorted.library.mesh.MeshJoined; |
| 38 |
import org.distorted.library.mesh.MeshRectangles;
|
|
| 38 |
import org.distorted.library.mesh.MeshTriangles;
|
|
| 39 | 39 |
import org.distorted.library.type.Dynamic1D; |
| 40 | 40 |
import org.distorted.library.type.DynamicQuat; |
| 41 | 41 |
import org.distorted.library.type.Static1D; |
| ... | ... | |
| 153 | 153 |
mAngleDyn.resetToBeginning(); |
| 154 | 154 |
} |
| 155 | 155 |
|
| 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 157 |
|
|
| 158 |
private Bitmap createTexture() |
|
| 159 |
{
|
|
| 160 |
final int[] FACE_COLORS = new int[] { 0xffff0000, 0xff00ff00 };
|
|
| 161 |
final int FACES=FACE_COLORS.length; |
|
| 162 |
int SIZE = 200; |
|
| 163 |
|
|
| 164 |
Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888); |
|
| 165 |
Canvas canvas = new Canvas(result); |
|
| 166 |
Paint paint = new Paint(); |
|
| 167 |
paint.setStyle(Paint.Style.FILL); |
|
| 168 |
|
|
| 169 |
for(int i=0; i<FACES; i++) |
|
| 170 |
{
|
|
| 171 |
paint.setColor(FACE_COLORS[i]); |
|
| 172 |
canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint); |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
return result; |
|
| 176 |
} |
|
| 177 |
|
|
| 178 | 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 179 | 157 |
|
| 180 | 158 |
private MeshBase createMesh() |
| 181 | 159 |
{
|
| 182 |
final int MESHES=2;
|
|
| 160 |
final int MESHES=4;
|
|
| 183 | 161 |
|
| 184 |
MeshBase[] meshes = new MeshRectangles[MESHES]; |
|
| 162 |
MeshBase[] meshes = new MeshTriangles[MESHES]; |
|
| 163 |
MatrixEffectMove[] moveEffect = new MatrixEffectMove[MESHES]; |
|
| 185 | 164 |
|
| 186 |
meshes[0] = new MeshRectangles(1,1);
|
|
| 165 |
meshes[0] = new MeshTriangles(1);
|
|
| 187 | 166 |
meshes[0].setEffectAssociation(0,1,0); |
| 188 | 167 |
|
| 189 | 168 |
for(int i=1; i<MESHES; i++) |
| ... | ... | |
| 192 | 171 |
meshes[i].setEffectAssociation(0,1,i); |
| 193 | 172 |
} |
| 194 | 173 |
|
| 195 |
Static4D[] lTextureMaps = new Static4D[MESHES]; |
|
| 196 |
Static4D[] rTextureMaps = new Static4D[MESHES]; |
|
| 174 |
Static4D[] textureMaps = new Static4D[MESHES]; |
|
| 197 | 175 |
|
| 198 | 176 |
for(int i=0; i<MESHES; i++) |
| 199 | 177 |
{
|
| 200 |
lTextureMaps[i] = new Static4D(0.0f,0.0f,0.5f,1.0f); |
|
| 201 |
rTextureMaps[i] = new Static4D(0.5f,0.0f,0.5f,1.0f); |
|
| 178 |
textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f); |
|
| 202 | 179 |
} |
| 203 | 180 |
|
| 204 | 181 |
MeshBase[] tmp = new MeshBase[2]; |
| 205 | 182 |
|
| 206 | 183 |
tmp[0] = new MeshJoined(meshes); |
| 207 |
tmp[0].setTextureMap(lTextureMaps,0); |
|
| 208 | 184 |
|
| 209 |
VertexEffectMove effect0 = new VertexEffectMove ( new Static3D(0,0,0.5f) ); |
|
| 210 |
VertexEffectRotate effect1 = new VertexEffectRotate( new Static1D(180), new Static3D(1,0,0), new Static3D(0,0,0) ); |
|
| 211 |
|
|
| 212 |
effect0.setMeshAssociation(1,0); // apply only to Components whose andAssoc has the least significant bit set, i.e. |
|
| 213 |
// to both meshes[0] and meshes[1] |
|
| 214 |
effect1.setMeshAssociation(0,1); // apply only to Components whose equAssoc is equal to 1, i.e. only to mesh[1] |
|
| 215 |
|
|
| 216 |
tmp[0].apply(effect0); |
|
| 217 |
tmp[0].apply(effect1); |
|
| 185 |
for(int i=0; i<MESHES; i++) |
|
| 186 |
{
|
|
| 187 |
moveEffect[i] = new MatrixEffectMove( new Static3D(0,0,0.5f-i/(MESHES-1.0f)) ); |
|
| 188 |
tmp[0].apply(moveEffect[i],0,i); |
|
| 189 |
} |
|
| 218 | 190 |
|
| 219 | 191 |
tmp[1] = tmp[0].copy(true); |
| 220 |
tmp[1].setTextureMap(rTextureMaps,0); |
|
| 221 | 192 |
|
| 222 | 193 |
tmp[0].mergeEffComponents(); |
| 223 | 194 |
tmp[1].mergeEffComponents(); |
| ... | ... | |
| 227 | 198 |
|
| 228 | 199 |
MeshBase combined = new MeshJoined(tmp); |
| 229 | 200 |
|
| 230 |
VertexEffectMove moveL = new VertexEffectMove ( new Static3D(-0.6f,0,0) ); |
|
| 231 |
VertexEffectMove moveR = new VertexEffectMove ( new Static3D(+0.6f,0,0) ); |
|
| 201 |
MatrixEffectMove moveL = new MatrixEffectMove( new Static3D(-0.6f,0,0) ); |
|
| 202 |
MatrixEffectMove moveR = new MatrixEffectMove( new Static3D(+0.6f,0,0) ); |
|
| 203 |
|
|
| 204 |
combined.apply(moveL,0,0); |
|
| 205 |
combined.apply(moveR,0,1); |
|
| 232 | 206 |
|
| 233 |
moveL.setMeshAssociation(0,0); // apply only to tmp[0]
|
|
| 234 |
moveR.setMeshAssociation(0,1); // apply only to tmp[1]
|
|
| 207 |
combined.setTextureMap(textureMaps,0);
|
|
| 208 |
combined.setTextureMap(textureMaps,MESHES);
|
|
| 235 | 209 |
|
| 236 |
combined.apply(moveL); |
|
| 237 |
combined.apply(moveR); |
|
| 238 | 210 |
|
| 239 | 211 |
return combined; |
| 240 | 212 |
} |
| 213 |
|
|
| 214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 215 |
|
|
| 216 |
private Bitmap createTexture() |
|
| 217 |
{
|
|
| 218 |
final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
|
|
| 219 |
final int FACES=FACE_COLORS.length; |
|
| 220 |
int SIZE = 200; |
|
| 221 |
float STROKE = 0.05f*SIZE; |
|
| 222 |
float OFF = STROKE/2 -1; |
|
| 223 |
float OFF2 = 0.5f*SIZE + OFF; |
|
| 224 |
float HEIGHT = SIZE - OFF; |
|
| 225 |
float RADIUS = SIZE/12; |
|
| 226 |
float ARC1_H = 0.2f*SIZE; |
|
| 227 |
float ARC1_W = SIZE*0.5f; |
|
| 228 |
float ARC2_W = 0.153f*SIZE; |
|
| 229 |
float ARC2_H = 0.905f*SIZE; |
|
| 230 |
float ARC3_W = SIZE-ARC2_W; |
|
| 231 |
|
|
| 232 |
Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888); |
|
| 233 |
Canvas canvas = new Canvas(result); |
|
| 234 |
Paint paint = new Paint(); |
|
| 235 |
paint.setAntiAlias(true); |
|
| 236 |
paint.setStrokeWidth(STROKE); |
|
| 237 |
|
|
| 238 |
for(int i=0; i<FACES; i++) |
|
| 239 |
{
|
|
| 240 |
paint.setColor(FACE_COLORS[i]); |
|
| 241 |
paint.setStyle(Paint.Style.FILL); |
|
| 242 |
|
|
| 243 |
canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint); |
|
| 244 |
|
|
| 245 |
paint.setColor(0xff000000); |
|
| 246 |
paint.setStyle(Paint.Style.STROKE); |
|
| 247 |
|
|
| 248 |
canvas.drawLine( i*SIZE, HEIGHT, SIZE +i*SIZE, HEIGHT, paint); |
|
| 249 |
canvas.drawLine( OFF +i*SIZE, SIZE, OFF2 +i*SIZE, 0, paint); |
|
| 250 |
canvas.drawLine((SIZE-OFF)+i*SIZE, SIZE, (SIZE-OFF2) +i*SIZE, 0, paint); |
|
| 251 |
|
|
| 252 |
canvas.drawArc( ARC1_W-RADIUS+i*SIZE, ARC1_H-RADIUS, ARC1_W+RADIUS+i*SIZE, ARC1_H+RADIUS, 225, 90, false, paint); |
|
| 253 |
canvas.drawArc( ARC2_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC2_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 105, 90, false, paint); |
|
| 254 |
canvas.drawArc( ARC3_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC3_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 345, 90, false, paint); |
|
| 255 |
} |
|
| 256 |
|
|
| 257 |
return result; |
|
| 258 |
} |
|
| 259 |
|
|
| 241 | 260 |
} |
Also available in: Unified diff
Bugfix and new debugging methods in MeshBase
DeferredJob app rewritten to show the (just fixed) bug