Revision c6526577
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java | ||
|---|---|---|
| 26 | 26 |
import javax.microedition.khronos.opengles.GL10; |
| 27 | 27 |
|
| 28 | 28 |
import org.distorted.examples.R; |
| 29 |
import org.distorted.library.effect.EffectName; |
|
| 30 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 31 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 32 |
import org.distorted.library.effect.VertexEffectDistort; |
|
| 29 | 33 |
import org.distorted.library.main.Distorted; |
| 30 | 34 |
import org.distorted.library.main.DistortedEffects; |
| 31 | 35 |
import org.distorted.library.main.DistortedScreen; |
| 32 | 36 |
import org.distorted.library.main.DistortedTexture; |
| 33 |
import org.distorted.library.EffectNames; |
|
| 34 | 37 |
import org.distorted.library.main.MeshFlat; |
| 35 |
import org.distorted.library.EffectTypes; |
|
| 36 | 38 |
import org.distorted.library.type.Dynamic3D; |
| 37 | 39 |
import org.distorted.library.type.Static3D; |
| 38 | 40 |
import org.distorted.library.type.Static4D; |
| ... | ... | |
| 51 | 53 |
private MeshFlat mMesh; |
| 52 | 54 |
private DistortedScreen mScreen; |
| 53 | 55 |
private int bmpHeight, bmpWidth; |
| 56 |
private Static3D mMove, mScale; |
|
| 54 | 57 |
|
| 55 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 56 | 59 |
|
| ... | ... | |
| 71 | 74 |
dRight.add( new Static3D( 20,-10,0) ); |
| 72 | 75 |
|
| 73 | 76 |
mEffects = new DistortedEffects(); |
| 74 |
mEffects.distort( dLeft, pLeft , rLeft ); |
|
| 75 |
mEffects.distort(dRight, pRight, rRight); |
|
| 77 |
mEffects.apply( new VertexEffectDistort(dLeft , pLeft , rLeft ) ); |
|
| 78 |
mEffects.apply( new VertexEffectDistort(dRight, pRight, rRight) ); |
|
| 79 |
|
|
| 80 |
mMove = new Static3D(0,0,0); |
|
| 81 |
mScale= new Static3D(1,1,1); |
|
| 82 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
| 83 |
mEffects.apply(new MatrixEffectScale(mScale)); |
|
| 76 | 84 |
|
| 77 | 85 |
mScreen = new DistortedScreen(mView); |
| 78 | 86 |
} |
| ... | ... | |
| 88 | 96 |
|
| 89 | 97 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 90 | 98 |
{
|
| 91 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 92 |
|
|
| 93 | 99 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
| 94 | 100 |
{
|
| 95 | 101 |
int w = (height*bmpWidth)/bmpHeight; |
| 96 | 102 |
float factor = (float)height/bmpHeight; |
| 97 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 98 |
mEffects.scale(factor); |
|
| 103 |
|
|
| 104 |
mMove.set((width-w)/2,0,0); |
|
| 105 |
mScale.set( factor,factor,factor ); |
|
| 99 | 106 |
} |
| 100 | 107 |
else |
| 101 | 108 |
{
|
| 102 | 109 |
int h = (width*bmpHeight)/bmpWidth; |
| 103 | 110 |
float factor = (float)width/bmpWidth; |
| 104 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 105 |
mEffects.scale(factor); |
|
| 111 |
|
|
| 112 |
mMove.set(0,(height-h)/2,0); |
|
| 113 |
mScale.set( factor,factor,factor ); |
|
| 106 | 114 |
} |
| 107 | 115 |
|
| 108 | 116 |
mScreen.resize(width, height); |
| ... | ... | |
| 148 | 156 |
mScreen.detachAll(); |
| 149 | 157 |
mScreen.attach(mTexture,mEffects,mMesh); |
| 150 | 158 |
|
| 151 |
DistortedEffects.enableEffect(EffectNames.DISTORT);
|
|
| 159 |
DistortedEffects.enableEffect(EffectName.DISTORT); |
|
| 152 | 160 |
|
| 153 | 161 |
try |
| 154 | 162 |
{
|
| 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 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
| 33 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 31 | 34 |
import org.distorted.library.main.DistortedEffects; |
| 32 | 35 |
import org.distorted.library.main.DistortedScreen; |
| 33 |
import org.distorted.library.EffectTypes; |
|
| 34 | 36 |
import org.distorted.library.main.MeshObject; |
| 35 | 37 |
import org.distorted.library.type.Dynamic; |
| 36 | 38 |
import org.distorted.library.type.DynamicQuat; |
| ... | ... | |
| 52 | 54 |
|
| 53 | 55 |
private GLSurfaceView mView; |
| 54 | 56 |
private DistortedTexture mTexture; |
| 55 |
private DistortedEffects mEffects; |
|
| 56 | 57 |
private MeshObject mMesh; |
| 57 | 58 |
private DistortedScreen mScreen; |
| 58 |
private DynamicQuat mRot;
|
|
| 59 |
|
|
| 59 |
private Static3D mMove, mScale, mCenter;
|
|
| 60 |
|
|
| 60 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | 62 |
|
| 62 | 63 |
QuaternionRenderer(GLSurfaceView v) |
| 63 | 64 |
{
|
| 64 | 65 |
mView = v; |
| 65 | 66 |
mTexture = new DistortedTexture(1,1); |
| 66 |
mEffects = new DistortedEffects(); |
|
| 67 | 67 |
mMesh = new MeshCubes(1,1,1); |
| 68 |
mRot = new DynamicQuat(); |
|
| 68 |
|
|
| 69 |
DistortedEffects effects = new DistortedEffects(); |
|
| 70 |
DynamicQuat rot = new DynamicQuat(); |
|
| 69 | 71 |
|
| 70 | 72 |
Random rnd = new Random(System.currentTimeMillis()); |
| 71 | 73 |
float x,y,z,w, len; |
| ... | ... | |
| 79 | 81 |
|
| 80 | 82 |
len = (float)Math.sqrt( x*x+y*y+z*z+w*w ); |
| 81 | 83 |
|
| 82 |
mRot.add(new Static4D(x/len,y/len,z/len,w/len));
|
|
| 84 |
rot.add(new Static4D(x/len,y/len,z/len,w/len));
|
|
| 83 | 85 |
} |
| 84 | 86 |
|
| 85 |
mRot.setCount(0); |
|
| 86 |
mRot.setDuration(8000); |
|
| 87 |
mRot.setMode(Dynamic.MODE_LOOP); |
|
| 87 |
rot.setCount(0); |
|
| 88 |
rot.setDuration(8000); |
|
| 89 |
rot.setMode(Dynamic.MODE_LOOP); |
|
| 90 |
|
|
| 91 |
mMove = new Static3D(0,0,0); |
|
| 92 |
mScale = new Static3D(1,1,1); |
|
| 93 |
mCenter = new Static3D(0,0,0); |
|
| 94 |
|
|
| 95 |
effects.apply( new MatrixEffectMove(mMove)); |
|
| 96 |
effects.apply(new MatrixEffectScale(mScale)); |
|
| 97 |
effects.apply( new MatrixEffectQuaternion(rot,mCenter) ); |
|
| 88 | 98 |
|
| 89 | 99 |
mScreen = new DistortedScreen(mView); |
| 90 |
mScreen.attach(mTexture,mEffects,mMesh);
|
|
| 100 |
mScreen.attach(mTexture,effects,mMesh);
|
|
| 91 | 101 |
} |
| 92 | 102 |
|
| 93 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 105 | 115 |
float h = mTexture.getHeight(); |
| 106 | 116 |
float d = mTexture.getDepth(mMesh); |
| 107 | 117 |
|
| 108 |
float scaleFactor = 0.5f*(width>height ? height/h:width/w); |
|
| 109 |
Static3D center = new Static3D(w/2,h/2,-d/2); |
|
| 118 |
float factor = 0.5f*(width>height ? height/h:width/w); |
|
| 119 |
|
|
| 120 |
mCenter.set(w/2,h/2,-d/2); |
|
| 121 |
mMove.set( (width-factor*w)/2 , (height-factor*h)/2 , 0 ); |
|
| 122 |
mScale.set(factor,factor,factor); |
|
| 110 | 123 |
|
| 111 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 112 |
mEffects.move( new Static3D( (width-scaleFactor*w)/2 , (height-scaleFactor*h)/2 , 0) ); |
|
| 113 |
mEffects.scale(scaleFactor); |
|
| 114 |
mEffects.quaternion( mRot,center ); |
|
| 115 |
|
|
| 116 | 124 |
mScreen.resize(width, height); |
| 117 | 125 |
} |
| 118 | 126 |
|
| src/main/java/org/distorted/examples/stencil/StencilRenderer.java | ||
|---|---|---|
| 25 | 25 |
import android.opengl.GLSurfaceView; |
| 26 | 26 |
|
| 27 | 27 |
import org.distorted.examples.R; |
| 28 |
import org.distorted.library.effect.EffectName; |
|
| 28 | 29 |
import org.distorted.library.main.Distorted; |
| 29 | 30 |
import org.distorted.library.main.DistortedEffects; |
| 30 | 31 |
import org.distorted.library.main.DistortedFramebuffer; |
| ... | ... | |
| 237 | 238 |
mCubeTex.setTexture(bitmap); |
| 238 | 239 |
mFloorTex.setColor(0xff000000); // ARGB |
| 239 | 240 |
|
| 240 |
DistortedEffects.enableEffect(EffectNames.BRIGHTNESS);
|
|
| 241 |
DistortedEffects.enableEffect(EffectName.BRIGHTNESS); |
|
| 241 | 242 |
|
| 242 | 243 |
try |
| 243 | 244 |
{
|
Also available in: Unified diff
Further progress with Apps: 18 (out of 30) compile now.