Revision bc0a685b
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/scratchpad/ScratchpadSurfaceView.java | ||
---|---|---|
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 |
|
|
1 | 20 |
package org.distorted.examples.scratchpad; |
2 | 21 |
|
3 | 22 |
import android.content.Context; |
... | ... | |
11 | 30 |
import org.distorted.library.Float4D; |
12 | 31 |
import org.distorted.library.Interpolator3D; |
13 | 32 |
|
14 |
/////////////////////////////////////////////////////////////////// |
|
33 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
15 | 34 |
|
16 | 35 |
public class ScratchpadSurfaceView extends GLSurfaceView |
17 |
{
|
|
18 |
private ScratchpadRenderer mRenderer;
|
|
19 |
private static int mCurrentEffect;
|
|
20 |
private static int mDuration;
|
|
21 |
private static float mCount;
|
|
22 |
private static int mScrW, mScrH;
|
|
36 |
{ |
|
37 |
private ScratchpadRenderer mRenderer; |
|
38 |
private static int mCurrentEffect; |
|
39 |
private static int mDuration; |
|
40 |
private static float mCount; |
|
41 |
private static int mScrW, mScrH; |
|
23 | 42 |
|
24 |
private static Float4D region;
|
|
25 |
private static Float2D point;
|
|
43 |
private static Float4D region; |
|
44 |
private static Float2D point; |
|
26 | 45 |
|
27 |
private static Interpolator3D di;
|
|
28 |
private static Float3D v0, v1, v2, v3;
|
|
46 |
private static Interpolator3D di; |
|
47 |
private static Float3D v0, v1, v2, v3; |
|
29 | 48 |
|
30 |
/////////////////////////////////////////////////////////////////// |
|
49 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
31 | 50 |
|
32 |
public ScratchpadSurfaceView(Context c, AttributeSet attrs)
|
|
33 |
{
|
|
34 |
super(c, attrs);
|
|
51 |
public ScratchpadSurfaceView(Context c, AttributeSet attrs) |
|
52 |
{ |
|
53 |
super(c, attrs); |
|
35 | 54 |
|
36 |
mDuration = 10000;
|
|
37 |
mCount = 1.0f;
|
|
55 |
mDuration = 10000; |
|
56 |
mCount = 1.0f; |
|
38 | 57 |
|
39 |
di = new Interpolator3D();
|
|
58 |
di = new Interpolator3D(); |
|
40 | 59 |
|
41 |
di.setDuration(mDuration);
|
|
42 |
di.setCount(mCount);
|
|
60 |
di.setDuration(mDuration); |
|
61 |
di.setCount(mCount); |
|
43 | 62 |
|
44 |
if(!isInEditMode())
|
|
45 |
{
|
|
46 |
setFocusable(true);
|
|
47 |
setFocusableInTouchMode(true);
|
|
48 |
|
|
49 |
setEGLContextClientVersion(2);
|
|
63 |
if(!isInEditMode()) |
|
64 |
{ |
|
65 |
setFocusable(true); |
|
66 |
setFocusableInTouchMode(true); |
|
67 |
|
|
68 |
setEGLContextClientVersion(2); |
|
50 | 69 |
|
51 |
if( Build.FINGERPRINT.startsWith("generic") ) // when running on the emulator, insert a magic line that is
|
|
52 |
{ // supposed to cure the 'no config chosen' crash on emulator startup
|
|
53 |
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
|
|
54 |
}
|
|
70 |
if( Build.FINGERPRINT.startsWith("generic") ) // when running on the emulator, insert a magic line that is |
|
71 |
{ // supposed to cure the 'no config chosen' crash on emulator startup |
|
72 |
setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
|
73 |
} |
|
55 | 74 |
|
56 |
mRenderer = new ScratchpadRenderer(this);
|
|
57 |
setRenderer(mRenderer);
|
|
75 |
mRenderer = new ScratchpadRenderer(this); |
|
76 |
setRenderer(mRenderer); |
|
58 | 77 |
|
59 |
point = new Float2D(0,0);
|
|
60 |
region= new Float4D(0,0,60,60);
|
|
78 |
point = new Float2D(0,0); |
|
79 |
region= new Float4D(0,0,60,60); |
|
61 | 80 |
|
62 |
int h = 30;
|
|
63 |
int r = 20;
|
|
81 |
int h = 30; |
|
82 |
int r = 20; |
|
64 | 83 |
|
65 |
v0 = new Float3D( 0, r, h );
|
|
66 |
v1 = new Float3D(-r, 0, h );
|
|
67 |
v2 = new Float3D( 0,-r, h );
|
|
68 |
v3 = new Float3D( r, 0, h );
|
|
84 |
v0 = new Float3D( 0, r, h ); |
|
85 |
v1 = new Float3D(-r, 0, h ); |
|
86 |
v2 = new Float3D( 0,-r, h ); |
|
87 |
v3 = new Float3D( r, 0, h ); |
|
69 | 88 |
|
70 |
di.add(v0);
|
|
71 |
di.add(v1);
|
|
72 |
di.add(v2);
|
|
73 |
di.add(v3);
|
|
89 |
di.add(v0); |
|
90 |
di.add(v1); |
|
91 |
di.add(v2); |
|
92 |
di.add(v3); |
|
74 | 93 |
|
75 |
setEffect(0); |
|
76 |
} |
|
94 |
setEffect(0); |
|
77 | 95 |
} |
96 |
} |
|
78 | 97 |
|
79 |
/////////////////////////////////////////////////////////////////// |
|
98 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
80 | 99 |
|
81 |
public static void setScreenSize(int width, int height)
|
|
82 |
{
|
|
83 |
mScrW = width;
|
|
84 |
mScrH = height;
|
|
85 |
}
|
|
100 |
public static void setScreenSize(int width, int height) |
|
101 |
{ |
|
102 |
mScrW = width; |
|
103 |
mScrH = height; |
|
104 |
} |
|
86 | 105 |
|
87 |
/////////////////////////////////////////////////////////////////// |
|
106 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
88 | 107 |
|
89 |
public static int getEffect()
|
|
90 |
{
|
|
91 |
return mCurrentEffect;
|
|
92 |
}
|
|
108 |
public static int getEffect() |
|
109 |
{ |
|
110 |
return mCurrentEffect; |
|
111 |
} |
|
93 | 112 |
|
94 |
/////////////////////////////////////////////////////////////////// |
|
113 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
95 | 114 |
|
96 |
public static void setEffect(int effect)
|
|
97 |
{
|
|
98 |
mCurrentEffect = effect;
|
|
99 |
}
|
|
115 |
public static void setEffect(int effect) |
|
116 |
{ |
|
117 |
mCurrentEffect = effect; |
|
118 |
} |
|
100 | 119 |
|
101 |
/////////////////////////////////////////////////////////////////// |
|
120 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
102 | 121 |
|
103 |
public static void setDuration(int duration)
|
|
104 |
{
|
|
105 |
mDuration = duration;
|
|
106 |
di.setDuration(duration);
|
|
107 |
}
|
|
122 |
public static void setDuration(int duration) |
|
123 |
{ |
|
124 |
mDuration = duration; |
|
125 |
di.setDuration(duration); |
|
126 |
} |
|
108 | 127 |
|
109 |
/////////////////////////////////////////////////////////////////// |
|
128 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
110 | 129 |
|
111 |
public static void setCount(float count)
|
|
112 |
{
|
|
113 |
mCount = count;
|
|
114 |
di.setCount(count);
|
|
115 |
}
|
|
130 |
public static void setCount(float count) |
|
131 |
{ |
|
132 |
mCount = count; |
|
133 |
di.setCount(count); |
|
134 |
} |
|
116 | 135 |
|
117 |
/////////////////////////////////////////////////////////////////// |
|
136 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
118 | 137 |
|
119 |
@Override public boolean onTouchEvent(MotionEvent event)
|
|
120 |
{
|
|
121 |
int action = event.getAction();
|
|
122 |
int x, y;
|
|
138 |
@Override public boolean onTouchEvent(MotionEvent event) |
|
139 |
{ |
|
140 |
int action = event.getAction(); |
|
141 |
int x, y; |
|
123 | 142 |
|
124 |
switch(action)
|
|
143 |
switch(action) |
|
125 | 144 |
{ |
126 | 145 |
case MotionEvent.ACTION_DOWN: x = (int)event.getX()*ScratchpadRenderer.BWID/mScrW; |
127 | 146 |
y = (int)event.getY()*ScratchpadRenderer.BHEI/mScrH; |
... | ... | |
143 | 162 |
break; |
144 | 163 |
} |
145 | 164 |
|
146 |
return true; |
|
147 |
} |
|
148 |
|
|
149 |
/////////////////////////////////////////////////////////////////// |
|
150 |
// end of file |
|
151 |
|
|
165 |
return true; |
|
166 |
} |
|
152 | 167 |
} |
Also available in: Unified diff
Add License