Project

General

Profile

« Previous | Next » 

Revision 643844c9

Added by Leszek Koltunski about 7 years ago

Improve Around the World.

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldSurfaceViewPicker.java
33 33
    private AroundTheWorldRendererPicker mRenderer;
34 34
    private AroundTheWorldEffectsManager mManager;
35 35

  
36
    private float mX, mY;
37

  
36 38
///////////////////////////////////////////////////////////////////////////////////////////////////
37 39

  
38 40
    public AroundTheWorldSurfaceViewPicker(Context context, AttributeSet attrs)
......
66 68

  
67 69
///////////////////////////////////////////////////////////////////////////////////////////////////
68 70

  
71
    float getx()
72
      {
73
      return mX;
74
      }
75

  
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

  
78
    float gety()
79
      {
80
      return mY;
81
      }
82

  
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

  
85
    void set(float x, float y)
86
      {
87
      mX = x;
88
      mY = y;
89

  
90
      mRenderer.move(mX,mY);
91

  
92
      float distance_from_left =(mX+0.865f)/(3*0.865f);
93
      float distance_from_top  =0.333f*(1-mY)-0.192f*mX;
94

  
95
      mManager.setRace( distance_from_top, distance_from_left );
96
      }
97

  
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

  
100

  
69 101
    @Override public boolean onTouchEvent(MotionEvent event)
70 102
      {
71 103
      int x = (int)event.getX();
......
74 106
      int h = mRenderer.getHeight();
75 107
      int w = mRenderer.getWidth();
76 108

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

  
80
      if( yf>-1.5f && yf<1.5f )
112
      if( mY>-1.5f && mY<1.5f )
81 113
        {
82
        if( yf>=0 && yf> 1-0.577f*xf )
114
        if( mY>=0 && mY> 1-0.577f*mX )
83 115
          {
84
          float d = 0.577f*xf + yf;
85
          yf /= d;
86
          xf /= d;
116
          float d = 0.577f*mX + mY;
117
          mY /= d;
118
          mX /= d;
87 119
          }
88
        else if( yf<=0 && yf< 0.577f*xf-1 )
120
        else if( mY<=0 && mY< 0.577f*mX-1 )
89 121
          {
90
          float d = 0.577f*xf - yf;
91
          yf /= d;
92
          xf /= d;
122
          float d = 0.577f*mX - mY;
123
          mY /= d;
124
          mX /= d;
93 125
          }
94
        else if( xf< -0.865f )
126
        else if( mX< -0.865f )
95 127
          {
96
          xf  =  -0.865f;
128
          mX  =  -0.865f;
97 129
          }
98 130

  
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 );
131
        set(mX,mY);
105 132
        }
106 133

  
107 134
      return true;

Also available in: Unified diff