Project

General

Profile

« Previous | Next » 

Revision 936287ff

Added by Leszek Koltunski almost 7 years ago

Progress with Effect classes.

The last 10 errors in the last 2 APPs.

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.EffectName;
28
import org.distorted.library.effect.EffectType;
29
import org.distorted.library.effect.MatrixEffectMove;
30
import org.distorted.library.effect.MatrixEffectQuaternion;
31
import org.distorted.library.effect.MatrixEffectScale;
27 32
import org.distorted.library.main.Distorted;
28 33
import org.distorted.library.main.DistortedEffects;
29 34
import org.distorted.library.main.DistortedNode;
30 35
import org.distorted.library.main.DistortedScreen;
31 36
import org.distorted.library.main.DistortedTexture;
32
import org.distorted.library.EffectNames;
33 37
import org.distorted.library.main.MeshFlat;
34 38
import org.distorted.library.main.MeshObject;
35
import org.distorted.library.EffectTypes;
36
import org.distorted.library.type.Dynamic3D;
37
import org.distorted.library.type.DynamicQuat;
38 39
import org.distorted.library.type.Static3D;
39 40
import org.distorted.library.type.Static4D;
40 41

  
......
53 54

  
54 55
    private GLSurfaceView mView;
55 56
    private DistortedTexture mObjectTexture, mBackgroundTexture, mCenterTexture, mRegionTexture;
56
    private DistortedEffects mObjectEffects, mBackgroundEffects, mCenterEffects, mRegionEffects;
57 57
    private DistortedScreen mScreen;
58 58
    private DistortedNode mCenterNode, mRegionNode;
59
    private int mObjWidth, mObjHeight, mObjDepth;
60
    private DynamicQuat mQuatInt1, mQuatInt2;
61

  
62
    private Dynamic3D mCenterInter, mRegionInter;
63
    private Static3D mCenterPoint, mRegionPoint;
64
    private Dynamic3D mRegionScaleInter;
65
    private Static3D mRegionScalePoint;
59
    private int mObjWidth, mObjHeight;
60
    private Static3D mCenterPoint, mRegionPoint, mRegionScalePoint;
61
    private Static3D mRotateCen, mMoveObject, mMoveCenter, mScaleCenter, mMoveRegion, mMoveBackground, mScaleBackground;
66 62

  
67 63
    private float mFactorObj, mFactorReg;
68 64

  
......
79 75

  
80 76
      Effects3DActivity act = (Effects3DActivity)v.getContext();
81 77

  
78
      mRotateCen      = new Static3D(0,0,0);
79
      mMoveObject     = new Static3D(0,0,0);
80
      mMoveCenter     = new Static3D(0,0,0);
81
      mScaleCenter    = new Static3D(1,1,1);
82
      mMoveRegion     = new Static3D(0,0,0);
83
      mMoveBackground = new Static3D(0,0,0);
84
      mScaleBackground= new Static3D(1,1,1);
85

  
82 86
      mObjectTexture     = act.getTexture();
83
      mObjectEffects     = act.getEffects();
84 87
      mBackgroundTexture = new DistortedTexture(100,100);
85 88
      mCenterTexture     = new DistortedTexture(100,100);
86 89
      mRegionTexture     = new DistortedTexture(100,100);
87
      mBackgroundEffects = new DistortedEffects();
88
      mCenterEffects     = new DistortedEffects();
89
      mRegionEffects     = new DistortedEffects();
90

  
91
      DistortedEffects objectEffects     = act.getEffects();
92
      DistortedEffects backgroundEffects = new DistortedEffects();
93
      DistortedEffects centerEffects     = new DistortedEffects();
94
      DistortedEffects regionEffects     = new DistortedEffects();
90 95

  
91 96
      MeshObject meshO   = act.getMesh();
92 97
      MeshFlat quad      = new MeshFlat(1,1);
93 98

  
94 99
      mObjWidth = mObjectTexture.getWidth();
95 100
      mObjHeight= mObjectTexture.getHeight();
96
      mObjDepth = mObjectTexture.getDepth(meshO);
101
      int objDepth = mObjectTexture.getDepth(meshO);
97 102

  
98 103
      mQuat1 = new Static4D(0,0,0,1);  // unity
99 104
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
100 105

  
101
      mQuatInt1 = new DynamicQuat(0,0.5f);
102
      mQuatInt2 = new DynamicQuat(0,0.5f);
103

  
104
      mQuatInt1.add(mQuat1);
105
      mQuatInt2.add(mQuat2);
106

  
107
      mCenterInter= new Dynamic3D();
108 106
      mCenterPoint= new Static3D(0,0,0);
109
      mCenterInter.add(mCenterPoint);
110

  
111
      mRegionInter= new Dynamic3D();
112 107
      mRegionPoint= new Static3D(0,0,0);
113
      mRegionInter.add(mRegionPoint);
114

  
115
      mRegionScaleInter = new Dynamic3D();
116 108
      mRegionScalePoint = new Static3D(0,0,0);
117
      mRegionScaleInter.add(mRegionScalePoint);
118 109

  
119
      mCenterNode = new DistortedNode(mCenterTexture, mCenterEffects, quad);
120
      mRegionNode = new DistortedNode(mRegionTexture, mRegionEffects, quad);
110
      mCenterNode = new DistortedNode(mCenterTexture, centerEffects, quad);
111
      mRegionNode = new DistortedNode(mRegionTexture, regionEffects, quad);
121 112

  
122 113
      mScreen = new DistortedScreen(mView);
123 114
      mScreen.setProjection(FOV, NEAR);
124
      mScreen.attach(mBackgroundTexture, mBackgroundEffects, quad );
125
      mScreen.attach(mObjectTexture    , mObjectEffects    , meshO);
115
      mScreen.attach(mBackgroundTexture, backgroundEffects, quad );
116
      mScreen.attach(mObjectTexture    , objectEffects    , meshO);
117

  
118
      int regionSize = mRegionTexture.getWidth();
119
      Static3D rotateObj = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, -(float)objDepth/2 );
120
      mRotateCen = new Static3D(0 ,0, 0);
121

  
122
      MatrixEffectQuaternion quat1obj = new MatrixEffectQuaternion(mQuat1,  rotateObj);
123
      MatrixEffectQuaternion quat2obj = new MatrixEffectQuaternion(mQuat2,  rotateObj);
124
      MatrixEffectQuaternion quat1cen = new MatrixEffectQuaternion(mQuat1, mRotateCen);
125
      MatrixEffectQuaternion quat2cen = new MatrixEffectQuaternion(mQuat2, mRotateCen);
126
      MatrixEffectMove centerMove = new MatrixEffectMove(mCenterPoint);
127

  
128
      objectEffects.apply( new MatrixEffectMove(mMoveObject));
129
      objectEffects.apply( new MatrixEffectScale(mFactorObj) );
130
      objectEffects.apply(quat1obj);
131
      objectEffects.apply(quat2obj);
132

  
133
      centerEffects.apply(quat1cen);
134
      centerEffects.apply(quat2cen);
135
      centerEffects.apply( new MatrixEffectMove(mMoveCenter) );
136
      centerEffects.apply( centerMove );
137
      centerEffects.apply( new MatrixEffectScale(mScaleCenter) );
138

  
139
      regionEffects.apply(quat1cen);
140
      regionEffects.apply(quat2cen);
141
      regionEffects.apply( new MatrixEffectMove(mMoveRegion) );
142
      regionEffects.apply( centerMove );
143
      regionEffects.apply( new MatrixEffectMove(mRegionPoint) );
144
      regionEffects.apply( new MatrixEffectScale(mRegionScalePoint) );
145
      regionEffects.apply( new MatrixEffectMove(new Static3D( -regionSize/2 , -regionSize/2 , 0)) );
146

  
147
      // quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() )
148
      backgroundEffects.apply(new MatrixEffectMove(mMoveBackground) );
149
      backgroundEffects.apply(new MatrixEffectScale(mScaleBackground) );
126 150
      }
127 151

  
128 152
///////////////////////////////////////////////////////////////////////////////////////////////////
......
175 199
      {
176 200
      mScreenMin = width<height ? width:height;
177 201

  
178
      mObjectEffects.abortEffects(EffectTypes.MATRIX);
179
      mBackgroundEffects.abortEffects(EffectTypes.MATRIX);
180
      mCenterEffects.abortEffects(EffectTypes.MATRIX);
181
      mRegionEffects.abortEffects(EffectTypes.MATRIX);
182

  
183 202
      float factorCen;
184 203
      int centerSize = mCenterTexture.getWidth();
185 204
      int regionSize = mRegionTexture.getWidth();
......
198 217
      Effects3DActivity act = (Effects3DActivity)mView.getContext();
199 218
      mCenterPoint.set(mFactorObj*act.getCenterX(),mFactorObj*act.getCenterY(),0);
200 219
      mRegionPoint.set(mFactorObj*act.getRegionX(),mFactorObj*act.getRegionY(),0);
201

  
202 220
      mFactorReg = 2*mFactorObj*act.getRegionR()/regionSize;
203 221
      mRegionScalePoint.set(mFactorReg,mFactorReg,mFactorReg);
222
      mMoveObject.set( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0 );
223
      mRotateCen.set(width/2,height/2, 0);
204 224

  
205
      Static3D rotateObj = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
206

  
207
      mObjectEffects.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
208
      mObjectEffects.scale(mFactorObj);
209
      mObjectEffects.quaternion(mQuatInt1, rotateObj);
210
      mObjectEffects.quaternion(mQuatInt2, rotateObj);
211

  
212
      Static3D rotateCen = new Static3D(width/2,height/2, 0);
213

  
214
      mCenterEffects.quaternion(mQuatInt1, rotateCen);
215
      mCenterEffects.quaternion(mQuatInt2, rotateCen);
216

  
217
      mCenterEffects.move( new Static3D( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
218
                                  (height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , 15) );
219
      mCenterEffects.move(mCenterInter);
220
      mCenterEffects.scale(factorCen);
221

  
222
      mRegionEffects.quaternion(mQuatInt1, rotateCen);
223
      mRegionEffects.quaternion(mQuatInt2, rotateCen);
224

  
225
      mRegionEffects.move( new Static3D( (width -mFactorObj*mObjWidth )/2 ,
226
                                  (height-mFactorObj*mObjHeight)/2 , 12) );
227
      mRegionEffects.move(mCenterInter);
228
      mRegionEffects.move(mRegionInter);
229
      mRegionEffects.scale(mRegionScaleInter);
230
      mRegionEffects.move( new Static3D( -regionSize/2 , -regionSize/2 , 0) );
225
      mMoveCenter.set( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
226
                       (height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , 15 );
227
      mScaleCenter.set(factorCen,factorCen,factorCen);
228
      mMoveRegion.set( (width -mFactorObj*mObjWidth )/2 ,(height-mFactorObj*mObjHeight)/2 , 12 );
231 229

  
232 230
      int backgroundSize = mBackgroundTexture.getWidth();
233 231
      float factorBackX = ((float)width)/backgroundSize;
234 232
      float factorBackY = ((float)height)/backgroundSize;
235 233

  
236 234
      // quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() )
237
      mBackgroundEffects.move(new Static3D( -width/2, -height/2, -0.9f*height*(1.0f-NEAR)/(2.0f*(float)Math.tan(FOV*Math.PI/360))) );
238
      mBackgroundEffects.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) );
235
      mMoveBackground.set( -width/2, -height/2, -0.9f*height*(1.0f-NEAR)/(2.0f*(float)Math.tan(FOV*Math.PI/360)) );
236
      mScaleBackground.set( 2*factorBackX, 2*factorBackY, 1.0f );
239 237

  
240 238
      mScreen.resize(width, height);
241 239
      }
......
274 272
      mCenterTexture.setTexture(bitmapC);
275 273
      mRegionTexture.setTexture(bitmapR);
276 274

  
277
      EffectTypes type;
275
      EffectType type;
278 276

  
279
      for( EffectNames name : EffectNames.values() )
277
      for( EffectName name : EffectName.values() )
280 278
        {
281 279
        type = name.getType();
282 280

  
283
        if( type== EffectTypes.VERTEX || type==EffectTypes.FRAGMENT )
281
        if( type== EffectType.VERTEX || type==EffectType.FRAGMENT )
284 282
          {
285 283
          DistortedEffects.enableEffect(name);
286 284
          }

Also available in: Unified diff