Project

General

Profile

Download (4.9 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / earth / EarthActivity.java @ 9814e53c

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.earth;
21

    
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25
import android.widget.SeekBar;
26

    
27
import org.distorted.examples.R;
28
import org.distorted.library.main.Distorted;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.mesh.MeshBase;
31
import org.distorted.library.mesh.MeshSphere;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
public class EarthActivity extends Activity implements SeekBar.OnSeekBarChangeListener
36
{
37
    private static final int SIZE = 100;
38
    private static final int LEVEL=  32;
39

    
40
    private DistortedTexture mTexture;
41
    private MeshBase mMesh;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
    
45
    @Override
46
    protected void onPause() 
47
      {
48
      GLSurfaceView mView = this.findViewById(R.id.earthSurfaceView);
49
      if( mView!=null ) mView.onPause();
50

    
51
      Distorted.onPause();
52
      super.onPause();
53
      }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
    
57
    @Override
58
    protected void onResume() 
59
      {
60
      super.onResume();
61
      
62
      GLSurfaceView mView = this.findViewById(R.id.earthSurfaceView);
63
      if( mView!=null ) mView.onResume();  
64
      }
65
    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
    
68
    @Override
69
    protected void onDestroy() 
70
      {
71
      Distorted.onDestroy();  
72
      super.onDestroy();
73
      }
74
 
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
    @Override
78
    protected void onCreate(Bundle savedState)
79
      {
80
      super.onCreate(savedState);
81

    
82
      mMesh = new MeshSphere(LEVEL);
83
      mTexture= new DistortedTexture(SIZE,SIZE);
84

    
85
      setContentView(R.layout.earthlayout);
86

    
87
      SeekBar levelBar = findViewById(R.id.earthInflateLevel);
88
      levelBar.setOnSeekBarChangeListener(this);
89
      levelBar.setProgress(50);
90
      }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
95
      {
96
      switch (bar.getId())
97
        {
98
        case R.id.earthInflateLevel: EarthSurfaceView view = this.findViewById(R.id.earthSurfaceView);
99
                                     view.getRenderer().setLevel(progress);
100
                                     break;
101
        }
102
      }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
    public void onStartTrackingTouch(SeekBar bar) { }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
    public void onStopTrackingTouch(SeekBar bar)  { }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
    public DistortedTexture getTexture()
115
      {
116
      return mTexture;
117
      }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
    public MeshBase getMesh()
122
      {
123
      return mMesh;
124
      }
125
}
(1-1/3)