Project

General

Profile

« Previous | Next » 

Revision 1833b023

Added by Leszek Koltunski over 5 years ago

Progress with the Earth app.

View differences:

src/main/java/org/distorted/examples/earth/EarthRenderer.java
47 47
import org.distorted.library.main.DistortedTexture;
48 48
import org.distorted.library.mesh.MeshBase;
49 49
import org.distorted.library.mesh.MeshSphere;
50
import org.distorted.library.type.Dynamic3D;
50 51
import org.distorted.library.type.DynamicQuat;
51 52
import org.distorted.library.type.Static1D;
52 53
import org.distorted.library.type.Static3D;
......
68 69
    private static final float FOV     = 30.0f;
69 70
    private static final float NEAR    =  0.1f;
70 71
    private static final int   MAX_EFF =    20;
71

  
72
    private static final float SCALE   = 1.10f;
72 73

  
73 74
    private GLSurfaceView mView;
74 75
    private DistortedTexture mTexture;
......
76 77
    private MeshBase mMesh;
77 78
    private DistortedScreen mScreen;
78 79
    private int mObjWidth, mObjHeight, mObjDepth;
79
    private Static3D mMove, mScale, mCenter;
80
    private Static3D mMove, mScaleFactor, mCenter;
81
    private Dynamic3D mScale;
80 82

  
81
    Static4D mQuat1, mQuat2;
82
    int mScreenMin;
83
    private int mScrWidth, mScrHeight;
84
    private float mLevel;
83 85

  
84 86
    private Static3D mColor;
85 87
    private Static3D mRegionF;
86 88
    private Static1D mStrength;
87 89

  
90
    Static4D mQuat1, mQuat2;
91
    int mScreenMin;
92

  
88 93
///////////////////////////////////////////////////////////////////////////////////////////////////
89 94

  
90 95
    EarthRenderer(GLSurfaceView v)
91 96
      {
92 97
      mView = v;
93 98

  
99
      mLevel = SCALE;
100

  
94 101
      DistortedEffects.setMax(EffectType.VERTEX  , MAX_EFF);
95 102
      DistortedEffects.setMax(EffectType.FRAGMENT, MAX_EFF);
96 103

  
97
      mStrength = new Static1D(0.5f);
98
      mColor    = new Static3D(255,0,0);
99
      mRegionF  = new Static3D(RADIUS,RADIUS,RADIUS);
100
      mMove     = new Static3D(0,0,0);
101
      mScale    = new Static3D(1,1,1);
102
      mCenter   = new Static3D(0,0,0);
104
      mScale      = new Dynamic3D(0,0.5f);
105
      mStrength   = new Static1D(0.5f);
106
      mColor      = new Static3D(255,0,0);
107
      mRegionF    = new Static3D(RADIUS,RADIUS,RADIUS);
108
      mMove       = new Static3D(0,0,0);
109
      mScaleFactor= new Static3D(1,1,1);
110
      mCenter     = new Static3D(0,0,0);
111

  
112
      mScale.add(mScaleFactor);
103 113

  
104 114
      mMesh     = new MeshSphere(LEVEL);
105 115
      mTexture  = new DistortedTexture(SIZE,SIZE);
......
138 148
    
139 149
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
140 150
      {
141
      final float SCALE = 1.10f;
151
      mScrWidth = width;
152
      mScrHeight= height;
153
      mScreenMin= width<height ? width:height;
154

  
155
      adjustFactor();
142 156

  
143
      mScreenMin = width<height ? width:height;
144
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight :  (SCALE*width)/mObjWidth;
145
      mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
146
      mScale.set(factor,factor,factor);
147 157
      mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, (float)mObjDepth/2 );
148 158
      mScreen.resize(width, height);
149 159
      }
......
152 162

  
153 163
    void setLevel(int level)
154 164
      {
155
      float inflateLevel = (level-50)/50.0f;
156
      mMesh.setInflate(inflateLevel);
165
      float N=3.0f;
166

  
167
      // MAP: 0--> SCALE/N   50-->SCALE   100->SCALE*N
168
      mLevel = SCALE* (1.0f+  (level>=50 ? N-1 : (N-1)/N) * (level-50)/50.0f);
169

  
170
      adjustFactor();
171
      }
172

  
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

  
175
    private void adjustFactor()
176
      {
177
      float xW = (float)mScrWidth /mObjWidth;
178
      float xH = (float)mScrHeight/mObjHeight;
179

  
180
      float factor = xW>xH ? mLevel*xH : mLevel*xW;
181

  
182
      mMove.set( (mScrWidth-factor*mObjWidth)/2 , (mScrHeight-factor*mObjHeight)/2 , 0);
183
      mScaleFactor.set(factor,factor,factor);
157 184
      }
158 185

  
159 186
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff