Revision d381aa80
Added by Leszek Koltunski over 6 years ago
| src/main/java/org/distorted/examples/bean/BeanRenderer.java | ||
|---|---|---|
| 27 | 27 |
|
| 28 | 28 |
import org.distorted.examples.R; |
| 29 | 29 |
|
| 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.main.DistortedEffects; |
| ... | ... | |
| 52 | 51 |
private DistortedScreen mScreen; |
| 53 | 52 |
private DistortedTexture mTexture; |
| 54 | 53 |
private MeshFlat mMesh; |
| 55 |
private int mObjHeight, mObjWidth; |
|
| 56 |
private Static3D mMove, mScale; |
|
| 54 |
private Static3D mScale; |
|
| 57 | 55 |
|
| 58 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 59 | 57 |
|
| ... | ... | |
| 85 | 83 |
dynRight.add(vect1); |
| 86 | 84 |
dynRight.add(vect1); |
| 87 | 85 |
|
| 88 |
mMove = new Static3D(0,0,0); |
|
| 89 | 86 |
mScale= new Static3D(1,1,1); |
| 90 | 87 |
|
| 91 | 88 |
mEffects = new DistortedEffects(); |
| 92 | 89 |
mEffects.apply( new VertexEffectDistort(dynLeft , pointLeft , regionLeft) ); |
| 93 | 90 |
mEffects.apply( new VertexEffectDistort(dynRight, pointRight, regionRight)); |
| 94 |
mEffects.apply( new MatrixEffectMove (mMove ) ); |
|
| 95 | 91 |
mEffects.apply( new MatrixEffectScale(mScale) ); |
| 96 | 92 |
|
| 97 | 93 |
mScreen = new DistortedScreen(); |
| ... | ... | |
| 108 | 104 |
|
| 109 | 105 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 110 | 106 |
{
|
| 111 |
if( (float)mObjHeight/mObjWidth > (float)height/width ) |
|
| 112 |
{
|
|
| 113 |
int w = (height*mObjWidth)/mObjHeight; |
|
| 114 |
float factor = (float)height/mObjHeight; |
|
| 115 |
mMove.set((width-w)/2,0,0); |
|
| 116 |
mScale.set(factor,factor,factor); |
|
| 117 |
} |
|
| 118 |
else |
|
| 119 |
{
|
|
| 120 |
int h = (width*mObjHeight)/mObjWidth; |
|
| 121 |
float factor = (float)width/mObjWidth; |
|
| 122 |
mMove.set(0,(height-h)/2,0); |
|
| 123 |
mScale.set(factor,factor,factor); |
|
| 124 |
} |
|
| 125 |
|
|
| 126 |
mScreen.resize(width,height); |
|
| 107 |
float horiRatio = (float)width / mTexture.getWidth(); |
|
| 108 |
float vertRatio = (float)height/ mTexture.getHeight(); |
|
| 109 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
| 110 |
|
|
| 111 |
mScale.set( factor,factor,factor ); |
|
| 112 |
mScreen.resize(width, height); |
|
| 127 | 113 |
} |
| 128 | 114 |
|
| 129 | 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 146 | 132 |
catch(IOException e) { }
|
| 147 | 133 |
} |
| 148 | 134 |
|
| 149 |
mObjHeight = bitmap.getHeight();
|
|
| 150 |
mObjWidth = bitmap.getWidth();
|
|
| 135 |
int bmpHeight = bitmap.getHeight();
|
|
| 136 |
int bmpWidth = bitmap.getWidth();
|
|
| 151 | 137 |
|
| 152 |
if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
|
|
| 138 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
|
|
| 153 | 139 |
mTexture.setTexture(bitmap); |
| 154 |
if( mMesh==null ) mMesh = new MeshFlat(25,25*mObjHeight/mObjWidth);
|
|
| 140 |
if( mMesh==null ) mMesh = new MeshFlat(25,25*bmpHeight/bmpWidth);
|
|
| 155 | 141 |
|
| 156 | 142 |
mScreen.detachAll(); |
| 157 | 143 |
mScreen.attach(mTexture,mEffects,mMesh); |
| src/main/java/org/distorted/examples/catanddog/CatAndDogRenderer.java | ||
|---|---|---|
| 36 | 36 |
import org.distorted.library.main.DistortedScreen; |
| 37 | 37 |
import org.distorted.library.main.DistortedTexture; |
| 38 | 38 |
import org.distorted.library.mesh.MeshFlat; |
| 39 |
import org.distorted.library.type.Dynamic; |
|
| 39 | 40 |
import org.distorted.library.type.Dynamic1D; |
| 40 | 41 |
import org.distorted.library.type.Dynamic3D; |
| 41 | 42 |
import org.distorted.library.type.Static1D; |
| ... | ... | |
| 49 | 50 |
|
| 50 | 51 |
class CatAndDogRenderer implements GLSurfaceView.Renderer |
| 51 | 52 |
{
|
| 52 |
private static final int DURATION = 10000; // 10 seconds |
|
| 53 |
private static final int DURATION_CHROMA_ALPHA = 3000; |
|
| 54 |
private static final int DURATION_MATRIX_EFFECTS = 10000; |
|
| 53 | 55 |
|
| 54 | 56 |
private GLSurfaceView mView; |
| 55 | 57 |
private DistortedEffects mEffects; |
| ... | ... | |
| 57 | 59 |
private DistortedTexture mTexture; |
| 58 | 60 |
private DistortedScreen mScreen; |
| 59 | 61 |
private int mObjHeight, mObjWidth; |
| 60 |
private Static3D mMove, mRotate;
|
|
| 62 |
private Static3D mMoveStartingPoint, mMoveEndPoint;
|
|
| 61 | 63 |
|
| 62 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 63 | 65 |
|
| ... | ... | |
| 67 | 69 |
|
| 68 | 70 |
mMesh = new MeshFlat(1,1); // no vertex effects, grid can be a (1x1) quad. |
| 69 | 71 |
|
| 70 |
Dynamic3D moveDyn= new Dynamic3D(DURATION,0.0f); |
|
| 71 |
mRotate = new Static3D(0,0,0); |
|
| 72 |
mMove = new Static3D(0,0,0); |
|
| 72 |
Dynamic3D moveDyn= new Dynamic3D(DURATION_MATRIX_EFFECTS,0.0f); |
|
| 73 | 73 |
|
| 74 |
moveDyn.add(mMove); |
|
| 75 |
moveDyn.add(new Static3D(0,0,0)); |
|
| 74 |
mMoveStartingPoint = new Static3D(0,0,0); |
|
| 75 |
mMoveEndPoint = new Static3D(0,0,0); |
|
| 76 |
|
|
| 77 |
moveDyn.add(mMoveStartingPoint); |
|
| 78 |
moveDyn.add(mMoveEndPoint); |
|
| 76 | 79 |
|
| 77 | 80 |
Static3D chromaCenter= new Static3D( 530, 300, 0 ); |
| 78 | 81 |
Static3D chromaRegion= new Static3D( 100, 100, 100 ); |
| 79 | 82 |
Static3D alphaCenter = new Static3D( 230, 300, 0 ); |
| 80 | 83 |
Static3D alphaRegion = new Static3D( 100, 100, 100 ); |
| 81 | 84 |
|
| 82 |
Dynamic1D chromaDyn = new Dynamic1D(3000,0.0f);
|
|
| 85 |
Dynamic1D chromaDyn = new Dynamic1D(DURATION_CHROMA_ALPHA,0.0f);
|
|
| 83 | 86 |
chromaDyn.add(new Static1D(1)); |
| 84 | 87 |
chromaDyn.add(new Static1D(0)); |
| 85 |
Dynamic1D alphaDyn = new Dynamic1D(3000,0.0f);
|
|
| 88 |
Dynamic1D alphaDyn = new Dynamic1D(DURATION_CHROMA_ALPHA,0.0f);
|
|
| 86 | 89 |
alphaDyn.add(new Static1D(1)); |
| 87 | 90 |
alphaDyn.add(new Static1D(0)); |
| 88 |
Dynamic3D diScale = new Dynamic3D(DURATION,0.0f); |
|
| 91 |
Dynamic3D diScale = new Dynamic3D(DURATION_MATRIX_EFFECTS,0.0f);
|
|
| 89 | 92 |
diScale.add(new Static3D(1,1,1)); |
| 90 | 93 |
diScale.add(new Static3D(0.33f,0.33f,1)); |
| 91 |
Dynamic1D diRotate = new Dynamic1D(DURATION,0.0f); |
|
| 94 |
diScale.add(new Static3D(1,1,1)); |
|
| 95 |
diScale.setMode(Dynamic.MODE_PATH); |
|
| 96 |
Dynamic1D diRotate = new Dynamic1D(DURATION_MATRIX_EFFECTS,0.0f); |
|
| 92 | 97 |
diRotate.add(new Static1D( 0)); |
| 93 | 98 |
diRotate.add(new Static1D(360)); |
| 94 | 99 |
|
| ... | ... | |
| 97 | 102 |
mEffects.apply( new FragmentEffectAlpha(alphaDyn, alphaCenter, alphaRegion, false) ); |
| 98 | 103 |
mEffects.apply( new MatrixEffectMove(moveDyn)); |
| 99 | 104 |
mEffects.apply( new MatrixEffectScale(diScale)); |
| 100 |
mEffects.apply( new MatrixEffectRotate( diRotate, new Static3D(0,0,1), mRotate) );
|
|
| 105 |
mEffects.apply( new MatrixEffectRotate( diRotate, new Static3D(0,0,1), new Static3D(0,0,0)) );
|
|
| 101 | 106 |
|
| 102 | 107 |
mScreen = new DistortedScreen(); |
| 103 | 108 |
} |
| ... | ... | |
| 106 | 111 |
|
| 107 | 112 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 108 | 113 |
{
|
| 109 |
mMove.set(width-mObjWidth,height-mObjHeight,0); |
|
| 114 |
mMoveStartingPoint.set( (width-mObjWidth)/2, (height-mObjHeight)/2, 0); |
|
| 115 |
mMoveEndPoint .set(-(width-mObjWidth)/2,-(height-mObjHeight)/2, 0); |
|
| 116 |
|
|
| 110 | 117 |
mScreen.resize(width, height); |
| 111 | 118 |
} |
| 112 | 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 138 | 145 |
|
| 139 | 146 |
mObjHeight = bitmap.getHeight(); |
| 140 | 147 |
mObjWidth = bitmap.getWidth(); |
| 141 |
mRotate.set(mObjWidth/2,mObjHeight/2,0); |
|
| 142 | 148 |
|
| 143 | 149 |
if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight); |
| 144 | 150 |
mTexture.setTexture(bitmap); |
| src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
|---|---|---|
| 23 | 23 |
import javax.microedition.khronos.opengles.GL10; |
| 24 | 24 |
|
| 25 | 25 |
import org.distorted.library.effect.EffectName; |
| 26 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 27 | 26 |
import org.distorted.library.effect.MatrixEffectShear; |
| 28 | 27 |
import org.distorted.library.effect.VertexEffectDeform; |
| 29 | 28 |
import org.distorted.library.effect.VertexEffectDistort; |
| ... | ... | |
| 63 | 62 |
private Static3D[] vShear; |
| 64 | 63 |
|
| 65 | 64 |
private Static4D mRegion; |
| 66 |
private Static3D mMove; |
|
| 67 | 65 |
private int scrHeight, scrWidth; |
| 68 | 66 |
private float mRadius; |
| 69 | 67 |
|
| ... | ... | |
| 82 | 80 |
|
| 83 | 81 |
stretchEffects = new DistortedEffects(); |
| 84 | 82 |
mRegion = new Static4D(0,0,0,0); |
| 85 |
mMove = new Static3D(0,0,0); |
|
| 86 | 83 |
mTouchPoint = new Static3D(0,0,0); |
| 87 | 84 |
|
| 88 | 85 |
// DISTORT |
| ... | ... | |
| 142 | 139 |
mReleasedDistort = new VertexEffectDistort( releasedDistortDynamic, mTouchPoint, mRegion); |
| 143 | 140 |
mReleasedDeform = new VertexEffectDeform ( releasedDeformDynamic , mTouchPoint, mRegion); |
| 144 | 141 |
mReleasedShear = new MatrixEffectShear ( releasedShearDynamic , mTouchPoint ); |
| 145 |
|
|
| 146 |
stretchEffects.apply(new MatrixEffectMove(mMove)); |
|
| 147 | 142 |
} |
| 148 | 143 |
|
| 149 | 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 202 | 197 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h); |
| 203 | 198 |
stretchTexture.setTexture(stretchBitmap); |
| 204 | 199 |
|
| 205 |
mMove.set(scrWidth/4,scrHeight/4,0); |
|
| 206 |
|
|
| 207 | 200 |
mScreen.detachAll(); |
| 208 | 201 |
mScreen.attach(stretchTexture,stretchEffects,stretchMesh); |
| 209 |
|
|
| 210 | 202 |
mScreen.resize(width, height); |
| 211 | 203 |
} |
| 212 | 204 |
|
| 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.MatrixEffectMove; |
|
| 31 | 30 |
import org.distorted.library.effect.MatrixEffectScale; |
| 32 | 31 |
import org.distorted.library.effect.VertexEffectDistort; |
| 33 | 32 |
import org.distorted.library.effect.VertexEffectSink; |
| ... | ... | |
| 58 | 57 |
private MeshFlat mMesh; |
| 59 | 58 |
private Static3D v0,v1,v2,v3; |
| 60 | 59 |
private Static1D dBegin, dMiddle, dEnd, s0; |
| 61 |
private int bmpHeight, bmpWidth; |
|
| 62 |
private Static3D mMove, mScale; |
|
| 60 |
private Static3D mScale; |
|
| 63 | 61 |
|
| 64 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | 63 |
|
| ... | ... | |
| 123 | 121 |
mEffects.apply( new VertexEffectDistort( diR , pRight, Region ) ); |
| 124 | 122 |
mEffects.apply( new VertexEffectSwirl ( diHips, pHips , HipsRegion) ); |
| 125 | 123 |
|
| 126 |
mMove = new Static3D(0,0,0); |
|
| 127 | 124 |
mScale= new Static3D(1,1,1); |
| 128 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
| 129 | 125 |
mEffects.apply(new MatrixEffectScale(mScale)); |
| 130 | 126 |
|
| 131 | 127 |
mScreen = new DistortedScreen(); |
| ... | ... | |
| 167 | 163 |
|
| 168 | 164 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 169 | 165 |
{
|
| 170 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 171 |
{
|
|
| 172 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 173 |
float factor = (float)height/bmpHeight; |
|
| 174 |
|
|
| 175 |
mMove.set((width-w)/2,0,0); |
|
| 176 |
mScale.set(factor,factor,factor); |
|
| 177 |
} |
|
| 178 |
else |
|
| 179 |
{
|
|
| 180 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 181 |
float factor = (float)width/bmpWidth; |
|
| 166 |
float horiRatio = (float)width / mTexture.getWidth(); |
|
| 167 |
float vertRatio = (float)height/ mTexture.getHeight(); |
|
| 168 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
| 182 | 169 |
|
| 183 |
mMove.set(0,(height-h)/2,0); |
|
| 184 |
mScale.set(factor,factor,factor); |
|
| 185 |
} |
|
| 186 |
|
|
| 170 |
mScale.set( factor,factor,factor ); |
|
| 187 | 171 |
mScreen.resize(width, height); |
| 188 | 172 |
} |
| 189 | 173 |
|
| ... | ... | |
| 207 | 191 |
catch(IOException e) { }
|
| 208 | 192 |
} |
| 209 | 193 |
|
| 210 |
bmpHeight = bitmap.getHeight(); |
|
| 211 |
bmpWidth = bitmap.getWidth(); |
|
| 194 |
int bmpHeight = bitmap.getHeight();
|
|
| 195 |
int bmpWidth = bitmap.getWidth();
|
|
| 212 | 196 |
|
| 213 | 197 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight); |
| 214 | 198 |
mTexture.setTexture(bitmap); |
| src/main/java/org/distorted/examples/listener/ListenerRenderer.java | ||
|---|---|---|
| 29 | 29 |
import org.distorted.examples.R; |
| 30 | 30 |
|
| 31 | 31 |
import org.distorted.library.effect.EffectType; |
| 32 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 33 | 32 |
import org.distorted.library.effect.MatrixEffectScale; |
| 34 | 33 |
import org.distorted.library.effect.VertexEffectDistort; |
| 35 | 34 |
import org.distorted.library.main.Distorted; |
| ... | ... | |
| 51 | 50 |
|
| 52 | 51 |
class ListenerRenderer implements GLSurfaceView.Renderer,EffectListener |
| 53 | 52 |
{
|
| 54 |
private final int NUM_BUBBLES = 12; |
|
| 53 |
private final int NUM_CONCURRENT_BUBBLES = 12;
|
|
| 55 | 54 |
|
| 56 | 55 |
private GLSurfaceView mView; |
| 57 | 56 |
private DistortedEffects mEffects; |
| ... | ... | |
| 60 | 59 |
private MeshFlat mMesh; |
| 61 | 60 |
private int bmpHeight, bmpWidth; |
| 62 | 61 |
private Random mRnd; |
| 63 |
private Static3D mMove, mScale;
|
|
| 62 |
private Static3D mScale; |
|
| 64 | 63 |
|
| 65 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 66 | 65 |
|
| ... | ... | |
| 72 | 71 |
mScreen = new DistortedScreen(); |
| 73 | 72 |
mRnd = new Random(0); |
| 74 | 73 |
|
| 75 |
mMove = new Static3D(0,0,0); |
|
| 76 | 74 |
mScale= new Static3D(1,1,1); |
| 77 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
| 78 | 75 |
mEffects.apply(new MatrixEffectScale(mScale)); |
| 79 | 76 |
} |
| 80 | 77 |
|
| ... | ... | |
| 121 | 118 |
|
| 122 | 119 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 123 | 120 |
{
|
| 124 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 125 |
{
|
|
| 126 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 127 |
float factor = (float)height/bmpHeight; |
|
| 121 |
float horiRatio = (float)width / mTexture.getWidth(); |
|
| 122 |
float vertRatio = (float)height/ mTexture.getHeight(); |
|
| 123 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
| 128 | 124 |
|
| 129 |
mMove.set((width-w)/2,0,0); |
|
| 130 |
mScale.set(factor,factor,factor); |
|
| 131 |
} |
|
| 132 |
else |
|
| 133 |
{
|
|
| 134 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 135 |
float factor = (float)width/bmpWidth; |
|
| 136 |
|
|
| 137 |
mMove.set(0,(height-h)/2,0); |
|
| 138 |
mScale.set(factor,factor,factor); |
|
| 139 |
} |
|
| 140 |
|
|
| 125 |
mScale.set( factor,factor,factor ); |
|
| 141 | 126 |
mScreen.resize(width, height); |
| 142 | 127 |
} |
| 143 | 128 |
|
| ... | ... | |
| 172 | 157 |
mScreen.detachAll(); |
| 173 | 158 |
mScreen.attach(mTexture,mEffects,mMesh); |
| 174 | 159 |
|
| 175 |
for(int i=0; i<NUM_BUBBLES; i++) addNewBubble();
|
|
| 160 |
for(int i = 0; i< NUM_CONCURRENT_BUBBLES; i++) addNewBubble();
|
|
| 176 | 161 |
|
| 177 | 162 |
// one more than we have bubbles at any given time because it can sometimes |
| 178 | 163 |
// happen that the old bubble is not yet removed when we add a new one |
| 179 |
DistortedEffects.setMax(EffectType.VERTEX,NUM_BUBBLES+1);
|
|
| 164 |
DistortedEffects.setMax(EffectType.VERTEX, NUM_CONCURRENT_BUBBLES +1);
|
|
| 180 | 165 |
VertexEffectDistort.enable(); |
| 181 | 166 |
|
| 182 | 167 |
try |
| 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.MatrixEffectMove; |
|
| 30 | 29 |
import org.distorted.library.effect.MatrixEffectScale; |
| 31 | 30 |
import org.distorted.library.effect.VertexEffectDistort; |
| 32 | 31 |
import org.distorted.library.main.Distorted; |
| ... | ... | |
| 51 | 50 |
private DistortedTexture mTexture; |
| 52 | 51 |
private MeshFlat mMesh; |
| 53 | 52 |
private DistortedScreen mScreen; |
| 54 |
private int bmpHeight, bmpWidth; |
|
| 55 |
private Static3D mMove, mScale; |
|
| 53 |
private Static3D mScale; |
|
| 56 | 54 |
|
| 57 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 58 | 56 |
|
| ... | ... | |
| 88 | 86 |
mEffects.apply( new VertexEffectDistort(dLeft , pLeft , rLeft ) ); |
| 89 | 87 |
mEffects.apply( new VertexEffectDistort(dRight, pRight, rRight) ); |
| 90 | 88 |
|
| 91 |
mMove = new Static3D(0,0,0); |
|
| 92 | 89 |
mScale= new Static3D(1,1,1); |
| 93 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
| 94 | 90 |
mEffects.apply(new MatrixEffectScale(mScale)); |
| 95 | 91 |
|
| 96 | 92 |
mScreen = new DistortedScreen(); |
| ... | ... | |
| 106 | 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 107 | 103 |
|
| 108 | 104 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 109 |
{
|
|
| 110 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 111 |
{
|
|
| 112 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 113 |
float factor = (float)height/bmpHeight; |
|
| 114 |
|
|
| 115 |
mMove.set((width-w)/2,0,0); |
|
| 116 |
mScale.set( factor,factor,factor ); |
|
| 117 |
} |
|
| 118 |
else |
|
| 119 |
{
|
|
| 120 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 121 |
float factor = (float)width/bmpWidth; |
|
| 122 |
|
|
| 123 |
mMove.set(0,(height-h)/2,0); |
|
| 124 |
mScale.set( factor,factor,factor ); |
|
| 125 |
} |
|
| 105 |
{
|
|
| 106 |
float horiRatio = (float)width / mTexture.getWidth(); |
|
| 107 |
float vertRatio = (float)height/ mTexture.getHeight(); |
|
| 108 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
| 126 | 109 |
|
| 110 |
mScale.set( factor,factor,factor ); |
|
| 127 | 111 |
mScreen.resize(width, height); |
| 128 | 112 |
} |
| 129 | 113 |
|
| ... | ... | |
| 147 | 131 |
catch(IOException e) { }
|
| 148 | 132 |
} |
| 149 | 133 |
|
| 150 |
bmpHeight = bitmap.getHeight(); |
|
| 151 |
bmpWidth = bitmap.getWidth(); |
|
| 134 |
int bmpHeight = bitmap.getHeight();
|
|
| 135 |
int bmpWidth = bitmap.getWidth();
|
|
| 152 | 136 |
|
| 153 | 137 |
// We could have gotten here after the activity went to the background |
| 154 | 138 |
// for a brief amount of time; in this case mTexture is already created. |
| src/main/java/org/distorted/examples/rubik/RubikRenderer.java | ||
|---|---|---|
| 84 | 84 |
// 3x2 bitmap = 6 squares: |
| 85 | 85 |
// |
| 86 | 86 |
// RED GREEN BLUE |
| 87 |
// YELLOW WHITE BROWN
|
|
| 87 |
// YELLOW WHITE ORANGE
|
|
| 88 | 88 |
|
| 89 | 89 |
final float ze = 0.0f; |
| 90 | 90 |
final float ot = 1.0f/3.0f; |
| ... | ... | |
| 177 | 177 |
// 3x2 bitmap = 6 squares: |
| 178 | 178 |
// |
| 179 | 179 |
// RED GREEN BLUE |
| 180 |
// YELLOW WHITE BROWN
|
|
| 180 |
// YELLOW WHITE ORANGE
|
|
| 181 | 181 |
|
| 182 | 182 |
paint.setColor(0xff000000); // BLACK BACKGROUND |
| 183 | 183 |
canvas.drawRect(0, 0, W, H, paint); // |
| 184 | 184 |
|
| 185 |
paint.setColor(0xffff0000); // RED
|
|
| 185 |
paint.setColor(0xffb90000); // RED
|
|
| 186 | 186 |
canvas.drawRoundRect( 0+M, 0+M, S-M, S-M, R, R, paint); // |
| 187 |
paint.setColor(0xff00ff00); // GREEN
|
|
| 187 |
paint.setColor(0xff009b48); // GREEN
|
|
| 188 | 188 |
canvas.drawRoundRect( S+M, 0+M, 2*S-M, S-M, R, R, paint); // |
| 189 |
paint.setColor(0xff0000ff); // BLUE
|
|
| 189 |
paint.setColor(0xff0045ad); // BLUE
|
|
| 190 | 190 |
canvas.drawRoundRect(2*S+M, 0+M, 3*S-M, S-M, R, R, paint); // |
| 191 |
paint.setColor(0xffffff00); // YELLOW
|
|
| 191 |
paint.setColor(0xffffd500); // YELLOW
|
|
| 192 | 192 |
canvas.drawRoundRect( 0+M, S+M, S-M, 2*S-M, R, R, paint); // |
| 193 | 193 |
paint.setColor(0xffffffff); // WHITE |
| 194 | 194 |
canvas.drawRoundRect( S+M, S+M, 2*S-M, 2*S-M, R, R, paint); // |
| 195 |
paint.setColor(0xffb5651d); // BROWN
|
|
| 195 |
paint.setColor(0xffff5900); // ORANGE
|
|
| 196 | 196 |
canvas.drawRoundRect(2*S+M, S+M, 3*S-M, 2*S-M, R, R, paint); // |
| 197 | 197 |
|
| 198 | 198 |
if( mTexture==null ) mTexture = new DistortedTexture(SIZE,SIZE); |
| src/main/java/org/distorted/examples/sink/SinkRenderer.java | ||
|---|---|---|
| 27 | 27 |
|
| 28 | 28 |
import org.distorted.examples.R; |
| 29 | 29 |
|
| 30 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 31 | 30 |
import org.distorted.library.effect.MatrixEffectScale; |
| 32 | 31 |
import org.distorted.library.effect.VertexEffectSink; |
| 33 | 32 |
import org.distorted.library.main.Distorted; |
| ... | ... | |
| 52 | 51 |
private DistortedScreen mScreen; |
| 53 | 52 |
private DistortedTexture mTexture; |
| 54 | 53 |
private MeshFlat mMesh; |
| 55 |
private int bmpHeight, bmpWidth; |
|
| 56 |
private Static3D mScale, mMove; |
|
| 54 |
private Static3D mScale; |
|
| 57 | 55 |
|
| 58 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 59 | 57 |
|
| ... | ... | |
| 70 | 68 |
mEffects.apply(sinkEffect); |
| 71 | 69 |
|
| 72 | 70 |
mScale = new Static3D(1,1,1); |
| 73 |
mMove = new Static3D(0,0,0); |
|
| 74 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
| 75 | 71 |
mEffects.apply(new MatrixEffectScale(mScale)); |
| 76 | 72 |
|
| 77 | 73 |
mScreen = new DistortedScreen(); |
| ... | ... | |
| 87 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 88 | 84 |
|
| 89 | 85 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 90 |
{
|
|
| 91 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 92 |
{
|
|
| 93 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 94 |
float factor = (float)height/bmpHeight; |
|
| 95 |
mMove.set((width-w)/2,0,0); |
|
| 96 |
mScale.set(factor,factor,factor); |
|
| 97 |
} |
|
| 98 |
else |
|
| 99 |
{
|
|
| 100 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 101 |
float factor = (float)width/bmpWidth; |
|
| 102 |
mMove.set(0,(height-h)/2,0); |
|
| 103 |
mScale.set(factor,factor,factor); |
|
| 104 |
} |
|
| 105 |
|
|
| 86 |
{
|
|
| 87 |
float horiRatio = (float)width / mTexture.getWidth(); |
|
| 88 |
float vertRatio = (float)height/ mTexture.getHeight(); |
|
| 89 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
| 90 |
|
|
| 91 |
mScale.set( factor,factor,factor ); |
|
| 106 | 92 |
mScreen.resize(width, height); |
| 107 | 93 |
} |
| 108 | 94 |
|
| ... | ... | |
| 126 | 112 |
catch(IOException e) { }
|
| 127 | 113 |
} |
| 128 | 114 |
|
| 129 |
bmpHeight = bitmap.getHeight(); |
|
| 130 |
bmpWidth = bitmap.getWidth(); |
|
| 115 |
int bmpHeight = bitmap.getHeight();
|
|
| 116 |
int bmpWidth = bitmap.getWidth();
|
|
| 131 | 117 |
|
| 132 | 118 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight); |
| 133 | 119 |
mTexture.setTexture(bitmap); |
Also available in: Unified diff
Move the default center of the matrix effects to the center of the screen (rather than the bottom-left like before)