Project

General

Profile

« Previous | Next » 

Revision b88ec561

Added by Leszek Koltunski almost 6 years ago

Progress with the Earth app.

View differences:

src/main/java/org/distorted/examples/earth/EarthRenderer.java
62 62

  
63 63
class EarthRenderer implements GLSurfaceView.Renderer
64 64
{
65
    private static final int   SIZE =   500;
66
    private static final int   LEVEL=    32;
67
    private static final float FOV  = 30.0f;
68
    private static final float NEAR =  0.1f;
65
    private static final float D      = (float)Math.sqrt(2.0)/2.0f;
66

  
67
    private static final int   SIZE   =   500;
68
    private static final int   RADIUS =   (int)(SIZE*D);
69
    private static final int   LEVEL  =    32;
70
    private static final float FOV    = 30.0f;
71
    private static final float NEAR   =  0.1f;
69 72

  
70 73
    private GLSurfaceView mView;
71 74
    private DistortedTexture mTexture;
......
79 82
    int mScreenMin;
80 83

  
81 84
    private Static3D mColor;
85
    private Static3D mRegionF;
82 86
    private Static1D mStrength;
83 87

  
84 88
///////////////////////////////////////////////////////////////////////////////////////////////////
......
88 92
      mView = v;
89 93

  
90 94
      mStrength = new Static1D(0.5f);
91
      mColor= new Static3D(255,0,0);
92
      mMove = new Static3D(0,0,0);
93
      mScale= new Static3D(1,1,1);
94
      mCenter=new Static3D(0,0,0);
95
      mColor    = new Static3D(255,0,0);
96
      mRegionF  = new Static3D(RADIUS,RADIUS,RADIUS);
97
      mMove     = new Static3D(0,0,0);
98
      mScale    = new Static3D(1,1,1);
99
      mCenter   = new Static3D(0,0,0);
95 100

  
96
      mMesh   = new MeshSphere(LEVEL);
97
      mTexture= new DistortedTexture(SIZE,SIZE);
101
      mMesh     = new MeshSphere(LEVEL);
102
      mTexture  = new DistortedTexture(SIZE,SIZE);
98 103

  
99 104
      mObjWidth = mTexture.getWidth();
100 105
      mObjHeight= mTexture.getHeight();
......
115 120
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
116 121
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
117 122

  
123

  
124
      Static3D center = new Static3D(0.5f*mObjWidth,0.5f*mObjHeight,0.5f*mObjDepth);
125
      mEffects.apply( new FragmentEffectChroma(mStrength, mColor,center, mRegionF, false) );
126

  
118 127
      mScreen = new DistortedScreen();
119 128
      mScreen.setProjection(FOV, NEAR);
120 129
      }
......
163 172
      float y = 0.7071f*(float)(cosLON*cosLAT);
164 173
      float z = 0.7071f*(float)        sinLAT ;
165 174

  
166
      float radius = SIZE/10;
167
      Static4D region = new Static4D(x*mObjWidth,y*mObjHeight,radius,radius);
175
      Static3D center = new Static3D(x*mObjWidth,y*mObjHeight,z*mObjDepth);
176

  
177
      android.util.Log.e("earth", "center "+(x*mObjWidth)+" "+(y*mObjHeight)+" "+(z*mObjDepth));
178
      android.util.Log.e("earth", "longitude: "+longitude+" latitude:"+latitude);
168 179

  
169 180
      switch(name)
170 181
        {
......
175 186
        case PINCH            : effect = new VertexEffectPinch  (mDyn2, center, mRegionV); break;
176 187
        case SWIRL            : effect = new VertexEffectSwirl  (mDyn1, center, mRegionV); break;
177 188
        case WAVE             : effect = new VertexEffectWave   (mDyn5, center, mRegionV); break;
178

  
179
        case ALPHA            : effect = new FragmentEffectAlpha     (mStrength,        region, false); break;
180
        case SMOOTH_ALPHA     : effect = new FragmentEffectAlpha     (mStrength,        region, true ); break;
181
        case CHROMA           : effect = new FragmentEffectChroma    (mStrength, mColor,region, false); break;
182
        case SMOOTH_CHROMA    : effect = new FragmentEffectChroma    (mStrength, mColor,region, true ); break;
183
        case BRIGHTNESS       : effect = new FragmentEffectBrightness(mStrength,        region, false); break;
184
        case SMOOTH_BRIGHTNESS: effect = new FragmentEffectBrightness(mStrength,        region, true ); break;
185
        case SATURATION       : effect = new FragmentEffectSaturation(mStrength,        region, false); break;
186
        case SMOOTH_SATURATION: effect = new FragmentEffectSaturation(mStrength,        region, true ); break;
187
        case CONTRAST         : effect = new FragmentEffectContrast  (mStrength,        region, false); break;
188
        case SMOOTH_CONTRAST  : effect = new FragmentEffectContrast  (mStrength,        region, true ); break;
189 189
        */
190
        case ALPHA            : effect = new FragmentEffectAlpha     (mStrength,        center, mRegionF, false); break;
191
        case SMOOTH_ALPHA     : effect = new FragmentEffectAlpha     (mStrength,        center, mRegionF, true ); break;
192
        case CHROMA           : effect = new FragmentEffectChroma    (mStrength, mColor,center, mRegionF, false); break;
193
        case SMOOTH_CHROMA    : effect = new FragmentEffectChroma    (mStrength, mColor,center, mRegionF, true ); break;
194
        case BRIGHTNESS       : effect = new FragmentEffectBrightness(mStrength,        center, mRegionF, false); break;
195
        case SMOOTH_BRIGHTNESS: effect = new FragmentEffectBrightness(mStrength,        center, mRegionF, true ); break;
196
        case SATURATION       : effect = new FragmentEffectSaturation(mStrength,        center, mRegionF, false); break;
197
        case SMOOTH_SATURATION: effect = new FragmentEffectSaturation(mStrength,        center, mRegionF, true ); break;
198
        case CONTRAST         : effect = new FragmentEffectContrast  (mStrength,        center, mRegionF, false); break;
199
        case SMOOTH_CONTRAST  : effect = new FragmentEffectContrast  (mStrength,        center, mRegionF, true ); break;
200

  
201
        default               : android.util.Log.e("EarthRenderer", "unexpected effect: "+name.toString() );
190 202
        }
191 203

  
192 204
      if( effect!=null )
193 205
        {
194
        android.util.Log.e("renderer", "adding fragment effect");
195 206
        mEffects.apply(effect);
196 207
        }
197 208
      }
......
229 240
      mScreen.detachAll();
230 241
      mScreen.attach(mTexture,mEffects,mMesh);
231 242

  
243
      Effect.enableEffects(EffectType.FRAGMENT);
244
      Effect.enableEffects(EffectType.VERTEX);
245

  
232 246
      try
233 247
        {
234 248
        Distorted.onCreate(mView.getContext());
src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java
99 99
  private View mButton, mEffect, mCenter, mRegion;
100 100
  private long mId;
101 101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
// this will enable() all Fragment Effects twice (once for smooth variant, once for non-smooth)
104
// but this shouldn't matter.
105

  
106
  static void enableAllEffects()
107
    {
108
    Method method=null;
109

  
110
    for(EffectName name: EffectName.values())
111
      {
112
      if( name.getType() != EffectType.MATRIX )  // you don't need to enable Matrix Effects
113
        {
114
        Class<? extends Effect> cls = name.getEffectClass();
115

  
116
        try
117
          {
118
          method = cls.getMethod("enable");
119
          }
120
        catch(NoSuchMethodException ex)
121
          {
122
          android.util.Log.e("Effects3DEffect", "exception getting method: "+ex.getMessage());
123
          }
124

  
125
        try
126
          {
127
          method.invoke(null);
128
          }
129
        catch(Exception ex)
130
          {
131
          android.util.Log.e("Effects3DEffect", "exception invoking method: "+ex.getMessage());
132
          }
133
        }
134
      }
135
    }
136

  
137 102
///////////////////////////////////////////////////////////////////////////////////////////////////
138 103
// requires knowledge about effect nature
139 104

  
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.Effect;
28
import org.distorted.library.effect.EffectType;
27 29
import org.distorted.library.effect.MatrixEffectMove;
28 30
import org.distorted.library.effect.MatrixEffectQuaternion;
29 31
import org.distorted.library.effect.MatrixEffectScale;
......
300 302
      mCenterTexture.setTexture(bitmapC);
301 303
      mRegionTexture.setTexture(bitmapR);
302 304

  
303
      Effects3DEffect.enableAllEffects();
305
      Effect.enableEffects(EffectType.VERTEX);
306
      Effect.enableEffects(EffectType.FRAGMENT);
307
      Effect.enableEffects(EffectType.POSTPROCESS);
304 308

  
305 309
      try
306 310
        {

Also available in: Unified diff