Project

General

Profile

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

examples / src / main / java / org / distorted / examples / aroundtheworld / AroundTheWorldSurfaceViewPicker.java @ fe59d375

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.aroundtheworld;
21

    
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLSurfaceView;
26
import android.util.AttributeSet;
27
import android.view.MotionEvent;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
class AroundTheWorldSurfaceViewPicker extends GLSurfaceView
32
{
33
    private AroundTheWorldRendererPicker mRenderer;
34
    private AroundTheWorldEffectsManager mManager;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
    public AroundTheWorldSurfaceViewPicker(Context context, AttributeSet attrs)
39
      {
40
      super(context, attrs);
41

    
42
      if(!isInEditMode())
43
        {
44
        final ActivityManager activityManager     = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
45
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
46
        android.util.Log.e("View", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
47
        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
48
        mRenderer = new AroundTheWorldRendererPicker();
49
        setRenderer(mRenderer);
50
        }
51
      }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
    public AroundTheWorldRendererPicker getRenderer()
56
      {
57
      return mRenderer;
58
      }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
    public void setEffectsManager(AroundTheWorldEffectsManager manager)
63
      {
64
      mManager = manager;
65
      }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
    @Override public boolean onTouchEvent(MotionEvent event)
70
      {
71
      int x = (int)event.getX();
72
      int y = (int)event.getY();
73

    
74
      int h = mRenderer.getHeight();
75
      int w = mRenderer.getWidth();
76

    
77
      float xf = (x-w/2)*3.0f/h;
78
      float yf =-(y-h/2)*3.0f/h;
79

    
80
      if( yf>-1.5f && yf<1.5f )
81
        {
82
        if( yf>=0 && yf> 1-0.577f*xf )
83
          {
84
          float d = 0.577f*xf + yf;
85
          yf /= d;
86
          xf /= d;
87
          }
88
        else if( yf<=0 && yf< 0.577f*xf-1 )
89
          {
90
          float d = 0.577f*xf - yf;
91
          yf /= d;
92
          xf /= d;
93
          }
94
        else if( xf< -0.865f )
95
          {
96
          xf  =  -0.865f;
97
          }
98

    
99
        mRenderer.move(xf,yf);
100

    
101
        float distance_from_left =(xf+0.865f)/(3*0.865f);
102
        float distance_from_top  =0.333f*(1-yf)-0.192f*xf;
103

    
104
        mManager.setRace( distance_from_top, distance_from_left );
105
        }
106

    
107
      return true;
108
      }
109
}
110

    
(6-6/6)