Project

General

Profile

« Previous | Next » 

Revision 65f622c1

Added by Leszek Koltunski over 5 years ago

Progress with Effects3D app - merge Matrix effects

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
24 24
import android.opengl.GLSurfaceView;
25 25

  
26 26
import org.distorted.examples.R;
27
import org.distorted.library.effect.FragmentEffectAlpha;
28
import org.distorted.library.effect.FragmentEffectBrightness;
29
import org.distorted.library.effect.FragmentEffectChroma;
30
import org.distorted.library.effect.FragmentEffectContrast;
31
import org.distorted.library.effect.FragmentEffectSaturation;
32 27
import org.distorted.library.effect.MatrixEffectMove;
33 28
import org.distorted.library.effect.MatrixEffectQuaternion;
34 29
import org.distorted.library.effect.MatrixEffectScale;
35
import org.distorted.library.effect.PostprocessEffectBlur;
36
import org.distorted.library.effect.PostprocessEffectGlow;
37
import org.distorted.library.effect.VertexEffectDeform;
38
import org.distorted.library.effect.VertexEffectDistort;
39
import org.distorted.library.effect.VertexEffectPinch;
40
import org.distorted.library.effect.VertexEffectSink;
41
import org.distorted.library.effect.VertexEffectSwirl;
42
import org.distorted.library.effect.VertexEffectWave;
43 30
import org.distorted.library.main.Distorted;
44 31
import org.distorted.library.main.DistortedEffects;
45 32
import org.distorted.library.main.DistortedNode;
......
73 60
    private boolean mShowingCenter=false;
74 61
    private boolean mShowingRegion=false;
75 62
    private float mFactorObj, mFactorReg;
63
    private int mWidth;
76 64

  
77 65
    Static4D mQuat1, mQuat2;
78 66
    int mScreenMin;
......
104 92
      DistortedEffects centerEffects     = new DistortedEffects();
105 93
      DistortedEffects regionEffects     = new DistortedEffects();
106 94

  
107
      MeshObject meshO   = act.getMesh();
95
      MeshObject mesh    = act.getMesh();
108 96
      MeshFlat quad      = new MeshFlat(1,1);
109 97

  
110 98
      mObjWidth = mObjectTexture.getWidth();
111 99
      mObjHeight= mObjectTexture.getHeight();
112
      int objDepth = mObjectTexture.getDepth(meshO);
113 100

  
114 101
      mQuat1 = new Static4D(0,0,0,1);  // unity
115 102
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
......
124 111
      mScreen = new DistortedScreen();
125 112
      mScreen.setProjection(FOV, NEAR);
126 113
      mScreen.attach(mBackgroundTexture, backgroundEffects, quad );
127
      mScreen.attach(mObjectTexture    , objectEffects    , meshO);
114
      mScreen.attach(mObjectTexture    , objectEffects    , mesh );
128 115

  
129 116
      int regionSize = mRegionTexture.getWidth();
130
      Static3D rotateObj = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, -(float)objDepth/2 );
131 117
      mRotateCen = new Static3D(0 ,0, 0);
132 118

  
133
      MatrixEffectQuaternion quat1obj = new MatrixEffectQuaternion(mQuat1,  rotateObj);
134
      MatrixEffectQuaternion quat2obj = new MatrixEffectQuaternion(mQuat2,  rotateObj);
135 119
      MatrixEffectQuaternion quat1cen = new MatrixEffectQuaternion(mQuat1, mRotateCen);
136 120
      MatrixEffectQuaternion quat2cen = new MatrixEffectQuaternion(mQuat2, mRotateCen);
137 121
      MatrixEffectMove centerMove = new MatrixEffectMove(mCenterPoint);
138 122

  
139
      objectEffects.apply( new MatrixEffectMove(mMoveObject));
140
      objectEffects.apply( new MatrixEffectScale(mScaleObject) );
141
      objectEffects.apply(quat1obj);
142
      objectEffects.apply(quat2obj);
143

  
144 123
      centerEffects.apply(quat1cen);
145 124
      centerEffects.apply(quat2cen);
146 125
      centerEffects.apply( new MatrixEffectMove(mMoveCenter) );
......
155 134
      regionEffects.apply( new MatrixEffectScale(mRegionScalePoint) );
156 135
      regionEffects.apply( new MatrixEffectMove(new Static3D( -regionSize/2 , -regionSize/2 , 0)) );
157 136

  
137
      resetMatrixEffects();
138

  
158 139
      // quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() )
159 140
      backgroundEffects.apply(new MatrixEffectMove(mMoveBackground) );
160 141
      backgroundEffects.apply(new MatrixEffectScale(mScaleBackground) );
161 142
      }
162 143

  
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

  
146
    void resetMatrixEffects()
147
      {
148
      Effects3DActivity2 act = (Effects3DActivity2)mView.getContext();
149

  
150
      DistortedEffects objectEffects= act.getEffects();
151
      MeshObject mesh  = act.getMesh();
152

  
153
      int objDepth = mObjectTexture.getDepth(mesh);
154

  
155
      Static3D rotateObj = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, -(float)objDepth/2 );
156

  
157
      MatrixEffectQuaternion quat1obj = new MatrixEffectQuaternion(mQuat1,  rotateObj);
158
      MatrixEffectQuaternion quat2obj = new MatrixEffectQuaternion(mQuat2,  rotateObj);
159

  
160
      objectEffects.apply( new MatrixEffectMove(mMoveObject));
161
      objectEffects.apply( new MatrixEffectScale(mScaleObject) );
162
      objectEffects.apply(quat1obj);
163
      objectEffects.apply(quat2obj);
164

  
165
      mQuat1.set(0,0,0,1);
166
      mQuat2.set(0,0,0,1);
167
      }
168

  
163 169
///////////////////////////////////////////////////////////////////////////////////////////////////
164 170

  
165 171
    void showRegionAndCenter(boolean showRegion, boolean showCenter)
......
181 187
        }
182 188
      }
183 189

  
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

  
192
    public int getWidth()
193
      {
194
      return mWidth;
195
      }
196

  
184 197
///////////////////////////////////////////////////////////////////////////////////////////////////
185 198

  
186 199
    void setCenter(float x, float y, float z)
......
215 228

  
216 229
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
217 230
      {
231
      mWidth = width;
218 232
      mScreenMin = width<height ? width:height;
219 233

  
220 234
      float factorCen;

Also available in: Unified diff