Project

General

Profile

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

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

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.content.Context;
23
import android.opengl.GLSurfaceView;
24
import android.os.Build;
25
import android.util.AttributeSet;
26
import android.view.MotionEvent;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

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

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
    public AroundTheWorldSurfaceViewPicker(Context c, AttributeSet attrs)
38
      {
39
      super(c, attrs);
40

    
41
      if(!isInEditMode())
42
        {
43
        setEGLContextClientVersion(2);
44

    
45
        if( Build.FINGERPRINT.startsWith("generic") )
46
          {
47
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);
48
          }
49

    
50
        mRenderer = new AroundTheWorldRendererPicker();
51
        setRenderer(mRenderer);
52
        }
53
      }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
    public AroundTheWorldRendererPicker getRenderer()
58
      {
59
      return mRenderer;
60
      }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
    public void setEffectsManager(AroundTheWorldEffectsManager manager)
65
      {
66
      mManager = manager;
67
      }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

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

    
76
      int h = mRenderer.getHeight();
77
      int w = mRenderer.getWidth();
78

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

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

    
101
        mRenderer.move(xf,yf);
102

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

    
106
        mManager.setRace( distance_from_top, distance_from_left );
107
        }
108

    
109
      return true;
110
      }
111
}
112

    
(6-6/6)