Revision 16b22aab
Added by Leszek Koltunski over 6 years ago
| src/main/java/org/distorted/examples/stencil/StencilRenderer.java | ||
|---|---|---|
| 56 | 56 |
private DistortedScreen mScreen; |
| 57 | 57 |
private DistortedTexture mCubeTex, mFloorTex, mFBOTex; |
| 58 | 58 |
private DistortedNode mCube1Node, mCube2Node, mFloorNode, mFBONode; |
| 59 |
private Static3D mMove, mScale, mRotCenter, mFBOScale;
|
|
| 59 |
private Static3D mScale, mFBOScale;
|
|
| 60 | 60 |
|
| 61 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 62 | 62 |
|
| ... | ... | |
| 89 | 89 |
MeshBase cube = new MeshCubes(1,1,1); |
| 90 | 90 |
MeshBase quad = new MeshQuad(); |
| 91 | 91 |
|
| 92 |
mMove = new Static3D(0,0,0); |
|
| 93 | 92 |
mScale = new Static3D(1,1,1); |
| 94 |
mRotCenter = new Static3D(0,0,0); |
|
| 95 | 93 |
mFBOScale = new Static3D(1,1,1); |
| 96 | 94 |
|
| 97 | 95 |
mCubeTex = new DistortedTexture(1,1); |
| ... | ... | |
| 137 | 135 |
setScreen(true); |
| 138 | 136 |
|
| 139 | 137 |
float cw = mCubeTex.getWidth(); |
| 140 |
float ch = mCubeTex.getHeight(); |
|
| 141 |
|
|
| 142 |
float fw = mFloorTex.getWidth(); |
|
| 143 |
float fh = mFloorTex.getHeight(); |
|
| 144 | 138 |
|
| 145 | 139 |
Static3D axisX = new Static3D(1,0,0); |
| 146 | 140 |
Static3D axisZ = new Static3D(0,0,1); |
| ... | ... | |
| 150 | 144 |
rotDyn.add(new Static1D( 0)); |
| 151 | 145 |
rotDyn.add(new Static1D(360)); |
| 152 | 146 |
|
| 147 |
Static3D rotCenter = new Static3D(0,0,0); |
|
| 148 |
|
|
| 153 | 149 |
MatrixEffectScale scale = new MatrixEffectScale(mScale); |
| 154 |
MatrixEffectMove move1 = new MatrixEffectMove( new Static3D( (fw-cw)/2, (fh-ch)/2, 0) ); |
|
| 155 |
MatrixEffectMove move2 = new MatrixEffectMove( mMove ); |
|
| 156 |
MatrixEffectRotate rotaX = new MatrixEffectRotate(new Static1D(-60.0f), axisX, mRotCenter); |
|
| 157 |
MatrixEffectRotate rotaZ = new MatrixEffectRotate(rotDyn, axisZ, mRotCenter); |
|
| 150 |
MatrixEffectMove move1 = new MatrixEffectMove( new Static3D( 0, 0, cw/2) ); |
|
| 151 |
MatrixEffectRotate rotaX = new MatrixEffectRotate(new Static1D(-60.0f), axisX, rotCenter); |
|
| 152 |
MatrixEffectRotate rotaZ = new MatrixEffectRotate(rotDyn, axisZ, rotCenter); |
|
| 158 | 153 |
|
| 159 | 154 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 160 | 155 |
// First move the cube and its reflection to the middle of the floor. Then scale the floor, the cube |
| ... | ... | |
| 162 | 157 |
// middle of the screen. |
| 163 | 158 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 164 | 159 |
// The cube |
| 165 |
cube1Effects.apply( move2 ); |
|
| 166 | 160 |
cube1Effects.apply( rotaX ); |
| 167 | 161 |
cube1Effects.apply( rotaZ ); |
| 168 | 162 |
cube1Effects.apply( scale ); |
| 169 | 163 |
cube1Effects.apply( move1 ); |
| 170 | 164 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 171 | 165 |
// Floor |
| 172 |
floorEffects.apply( move2 ); |
|
| 173 | 166 |
floorEffects.apply( rotaX ); |
| 174 | 167 |
floorEffects.apply( rotaZ ); |
| 175 | 168 |
floorEffects.apply( scale ); |
| 176 | 169 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
| 177 | 170 |
// Reflection |
| 178 |
cube2Effects.apply( move2 ); |
|
| 179 | 171 |
cube2Effects.apply( rotaX ); |
| 180 | 172 |
cube2Effects.apply( rotaZ ); |
| 181 | 173 |
cube2Effects.apply( scale ); |
| 182 |
cube2Effects.apply( move1 ); |
|
| 183 | 174 |
cube2Effects.apply( new MatrixEffectScale(new Static3D(1,1,-1)) ); |
| 175 |
cube2Effects.apply( move1 ); |
|
| 184 | 176 |
cube2Effects.apply( new FragmentEffectBrightness(new Static1D(0.5f)) ); |
| 185 | 177 |
|
| 186 | 178 |
///////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 202 | 194 |
float cw = mCubeTex.getWidth(); |
| 203 | 195 |
float ch = mCubeTex.getHeight(); |
| 204 | 196 |
|
| 205 |
float fw = mFloorTex.getWidth(); |
|
| 206 |
float fh = mFloorTex.getHeight(); |
|
| 207 |
|
|
| 208 | 197 |
float bw = mFBOTex.getWidth(); |
| 209 | 198 |
float bh = mFBOTex.getHeight(); |
| 210 | 199 |
|
| 211 | 200 |
float scale = 0.4f*(width>height ? height/ch:width/cw); |
| 212 | 201 |
|
| 213 |
mRotCenter.set(scale*fw/2,scale*fh/2,0); |
|
| 214 | 202 |
mScale.set(scale,scale,scale); |
| 215 |
mMove.set((width-scale*fw)/2 , (height-scale*fh)/2, 0 ); |
|
| 216 | 203 |
mFBOScale.set((float)width/bw, (float)height/bh, 1.0f ); |
| 217 | 204 |
|
| 218 | 205 |
mFBONode.resize(width,height); |
| ... | ... | |
| 240 | 227 |
} |
| 241 | 228 |
|
| 242 | 229 |
mCubeTex.setTexture(bitmap); |
| 243 |
mFloorTex.setColor(0xff000000); // ARGB
|
|
| 230 |
mFloorTex.setColorARGB(0xff000000);
|
|
| 244 | 231 |
|
| 245 | 232 |
FragmentEffectBrightness.enable(); |
| 246 | 233 |
|
Also available in: Unified diff
Fix several more apps for the 'center-of-matrix-effects-in-screen-center' change.