Revision 18231014
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/examples/projection/ProjectionRenderer.java | ||
---|---|---|
22 | 22 |
import javax.microedition.khronos.egl.EGLConfig; |
23 | 23 |
import javax.microedition.khronos.opengles.GL10; |
24 | 24 |
|
25 |
import org.distorted.library.effect.MatrixEffectScale; |
|
25 | 26 |
import org.distorted.library.effect.VertexEffectDeform; |
26 | 27 |
import org.distorted.library.main.DistortedLibrary; |
27 | 28 |
import org.distorted.library.main.DistortedEffects; |
... | ... | |
47 | 48 |
private MeshRectangles mMesh; |
48 | 49 |
private DistortedTexture mTexture; |
49 | 50 |
private float mF, mNear; |
50 |
|
|
51 |
private Static3D mVector, mPoint1, mPoint2, mPoint3, mPoint4; |
|
52 |
private Static4D mRegion; |
|
51 |
private Static3D mScale; |
|
53 | 52 |
|
54 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 54 |
|
... | ... | |
59 | 58 |
mEffects= new DistortedEffects(); |
60 | 59 |
mScreen = new DistortedScreen(); |
61 | 60 |
|
62 |
mVector = new Static3D(0,0,0); |
|
63 |
mPoint1 = new Static3D(0,0,0); |
|
64 |
mPoint2 = new Static3D(0,0,0); |
|
65 |
mPoint3 = new Static3D(0,0,0); |
|
66 |
mPoint4 = new Static3D(0,0,0); |
|
67 |
mRegion = new Static4D(0,0,0,0); |
|
68 |
|
|
69 |
mEffects.apply( new VertexEffectDeform(mVector, mPoint1, mRegion) ); |
|
70 |
mEffects.apply( new VertexEffectDeform(mVector, mPoint2, mRegion) ); |
|
71 |
mEffects.apply( new VertexEffectDeform(mVector, mPoint3, mRegion) ); |
|
72 |
mEffects.apply( new VertexEffectDeform(mVector, mPoint4, mRegion) ); |
|
61 |
Static3D point1 = new Static3D( 0.25f, 0.25f, 0); |
|
62 |
Static3D point2 = new Static3D( -0.25f, 0.25f, 0); |
|
63 |
Static3D point3 = new Static3D( 0.25f, -0.25f, 0); |
|
64 |
Static3D point4 = new Static3D( -0.25f, -0.25f, 0); |
|
65 |
Static4D region = new Static4D( 0, 0, 0, 0.25f); |
|
66 |
Static3D vector = new Static3D( 0, 0, 0.25f); |
|
67 |
|
|
68 |
mScale = new Static3D(1,1,1); |
|
69 |
|
|
70 |
mEffects.apply( new MatrixEffectScale(mScale) ); |
|
71 |
|
|
72 |
mEffects.apply( new VertexEffectDeform(vector, point1, region) ); |
|
73 |
mEffects.apply( new VertexEffectDeform(vector, point2, region) ); |
|
74 |
mEffects.apply( new VertexEffectDeform(vector, point3, region) ); |
|
75 |
mEffects.apply( new VertexEffectDeform(vector, point4, region) ); |
|
76 |
|
|
77 |
mTexture= new DistortedTexture(); |
|
73 | 78 |
} |
74 | 79 |
|
75 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
120 | 125 |
bmpCanvas.drawRect( 0, height*i/NUMLINES-1, width , height*i/NUMLINES+1, paint); |
121 | 126 |
} |
122 | 127 |
|
123 |
int min = width<height ? width:height; |
|
124 |
|
|
125 |
mVector.set(0,0,min/4); |
|
126 |
mRegion.set(0,0,0,min/4); |
|
127 |
|
|
128 |
mPoint1.set( width/4, height/4, 0); |
|
129 |
mPoint2.set( -width/4, height/4, 0); |
|
130 |
mPoint3.set( width/4, -height/4, 0); |
|
131 |
mPoint4.set( -width/4, -height/4, 0); |
|
128 |
mScale.set(width,height,width); // TODO - width in the third scale?? |
|
132 | 129 |
|
133 |
// Avoid memory leaks: delete old texture if it exists (it might if we |
|
134 |
// got here after a brief amount of time spent in the background) |
|
135 |
if( mTexture!=null ) mTexture.markForDeletion(); |
|
136 |
|
|
137 |
mTexture= new DistortedTexture(); |
|
138 | 130 |
mTexture.setTexture(bmp); |
139 | 131 |
|
140 |
// likewise with the Mesh |
|
141 | 132 |
if( mMesh!=null ) mMesh.markForDeletion(); |
142 | 133 |
mMesh = new MeshRectangles(100,100*height/width); |
143 |
mMesh.setStretch(width,height,0); |
|
144 | 134 |
|
145 | 135 |
mScreen.detachAll(); |
146 | 136 |
mScreen.attach(mTexture,mEffects,mMesh); |
Also available in: Unified diff
Convert Projection to not use the depreciated MeshBase.setStretch() API.