NyARToolkit for Android v2.x, 3.x mainline.
master: NyARToolkit core.
android-1.6: for Android 1.6. obsolete version.
android-2.2: for Android 2.2. current version.
修订版 | be72a53b6273675e0941a1b8e52d651cd52c3d7d (tree) |
---|---|
时间 | 2012-05-26 00:54:23 |
作者 | nyatla <nyatla@user...> |
Commiter | nyatla |
backup
@@ -1,6 +1,7 @@ | ||
1 | 1 | package jp.androidgroup.nyartoolkit.markersystem; |
2 | 2 | |
3 | 3 | import jp.nyatla.nyartoolkit.core.NyARException; |
4 | +import jp.nyatla.nyartoolkit.jogl.utils.NyARGLUtil; | |
4 | 5 | import jp.nyatla.nyartoolkit.markersystem.INyARMarkerSystemConfig; |
5 | 6 | import jp.nyatla.nyartoolkit.markersystem.NyARMarkerSystem; |
6 | 7 |
@@ -11,5 +12,47 @@ public class NyARAndMarkerSystem extends NyARMarkerSystem | ||
11 | 12 | throws NyARException { |
12 | 13 | super(i_config); |
13 | 14 | } |
15 | + private float[] _projection_mat; | |
16 | + protected void initInstance(INyARMarkerSystemConfig i_config) throws NyARException | |
17 | + { | |
18 | + super.initInstance(i_config); | |
19 | + this._projection_mat=new float[16]; | |
20 | + } | |
14 | 21 | |
22 | + /** | |
23 | + * OpenGLスタイルのProjectionMatrixを返します。 | |
24 | + * @param i_gl | |
25 | + * @return | |
26 | + * [readonly] | |
27 | + */ | |
28 | + public float[] getGlProjectionMatrix() | |
29 | + { | |
30 | + return this._projection_mat; | |
31 | + } | |
32 | + public void setProjectionMatrixClipping(double i_near,double i_far) | |
33 | + { | |
34 | + super.setProjectionMatrixClipping(i_near,i_far); | |
35 | + NyARGLUtil.toCameraFrustumRH(this._ref_param,1,i_near,i_far,this._projection_mat); | |
36 | + } | |
37 | + /** | |
38 | + * この関数は、i_bufに指定idのOpenGL形式の姿勢変換行列を設定して返します。 | |
39 | + * @param i_id | |
40 | + * @param i_buf | |
41 | + * @return | |
42 | + */ | |
43 | + public void getMarkerMatrix(int i_id,float[] i_buf) | |
44 | + { | |
45 | + NyARGLUtil.toCameraViewRH(this.getMarkerMatrix(i_id),1,i_buf); | |
46 | + } | |
47 | + /** | |
48 | + * この関数はOpenGL形式の姿勢変換行列を新規に割り当てて返します。 | |
49 | + * @param i_buf | |
50 | + * @return | |
51 | + */ | |
52 | + public float[] getGlMarkerMatrix(int i_id) | |
53 | + { | |
54 | + float[] b=new float[16]; | |
55 | + this.getMarkerMatrix(i_id,b); | |
56 | + return b; | |
57 | + } | |
15 | 58 | } |
@@ -2,14 +2,13 @@ package jp.androidgroup.nyartoolkit.markersystem; | ||
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | |
5 | -import jp.androidgroup.nyartoolkit.utils.CameraPreview; | |
6 | 5 | import jp.androidgroup.nyartoolkit.utils.NyARAndYUV420GsRaster; |
7 | 6 | import jp.androidgroup.nyartoolkit.utils.NyARAndYUV420RgbRaster; |
7 | +import jp.androidgroup.nyartoolkit.utils.camera.CameraPreview; | |
8 | 8 | import jp.nyatla.nyartoolkit.core.NyARException; |
9 | 9 | import jp.nyatla.nyartoolkit.core.raster.INyARGrayscaleRaster; |
10 | 10 | import jp.nyatla.nyartoolkit.core.types.NyARIntSize; |
11 | 11 | import jp.nyatla.nyartoolkit.markersystem.NyARSensor; |
12 | -import android.hardware.Camera; | |
13 | 12 | /** |
14 | 13 | * この関数は、非同期カメライベントをラップした{@see NyARSensor}です。 |
15 | 14 | * 画像取得APIにアクセスするときには、オブジェクトをsynchronizedしてください。 |
@@ -2,31 +2,29 @@ package jp.androidgroup.nyartoolkit.sketch; | ||
2 | 2 | |
3 | 3 | import java.util.ArrayList; |
4 | 4 | |
5 | -import javax.microedition.khronos.egl.EGLConfig; | |
6 | -import javax.microedition.khronos.opengles.GL10; | |
7 | - | |
8 | 5 | import jp.androidgroup.nyartoolkit.R; |
9 | -import jp.androidgroup.nyartoolkit.R.layout; | |
10 | - | |
11 | 6 | import android.app.Activity; |
12 | 7 | import android.content.pm.ActivityInfo; |
13 | 8 | import android.graphics.PixelFormat; |
14 | -import android.opengl.GLSurfaceView; | |
15 | 9 | import android.os.Bundle; |
16 | 10 | import android.util.Log; |
17 | -import android.view.ViewGroup.LayoutParams; | |
18 | 11 | import android.view.Window; |
19 | 12 | import android.view.WindowManager; |
20 | -import android.widget.FrameLayout; | |
21 | 13 | |
22 | 14 | public class AndSketch extends Activity |
23 | 15 | { |
16 | + public interface IAndSketchEventListerner | |
17 | + { | |
18 | + public void onAcResume(); | |
19 | + public void onAcPause(); | |
20 | + public void onAcDestroy() throws Exception; | |
21 | + public void onAcStop() throws Exception; | |
22 | + } | |
23 | + | |
24 | 24 | public ArrayList<IAndSketchEventListerner> _evlistener=new ArrayList<IAndSketchEventListerner>(); |
25 | 25 | |
26 | 26 | |
27 | - final static int AST_SETUP=0; | |
28 | - final static int AST_RUN =1; | |
29 | - int _ast=AST_SETUP; | |
27 | + | |
30 | 28 | public AndSketch() |
31 | 29 | { |
32 | 30 | } |
@@ -34,10 +32,9 @@ public class AndSketch extends Activity | ||
34 | 32 | @Override |
35 | 33 | protected void onResume() { |
36 | 34 | super.onResume(); |
37 | - this._glView.onResume(); | |
38 | 35 | try { |
39 | 36 | for(IAndSketchEventListerner i : this._evlistener) { |
40 | - i.onResume(); | |
37 | + i.onAcResume(); | |
41 | 38 | } |
42 | 39 | } catch (Exception e) { |
43 | 40 | e.printStackTrace(); |
@@ -46,52 +43,26 @@ public class AndSketch extends Activity | ||
46 | 43 | } |
47 | 44 | protected void onPause() { |
48 | 45 | super.onPause(); |
49 | - this._glView.onPause(); | |
50 | 46 | try { |
51 | -// for(IAndSketchEventListerner i : this._evlistener) { | |
52 | -// i.onPause(); | |
53 | -// } | |
47 | + for(IAndSketchEventListerner i : this._evlistener) { | |
48 | + i.onAcPause(); | |
49 | + } | |
54 | 50 | } catch (Exception e) { |
55 | 51 | e.printStackTrace(); |
56 | 52 | } |
57 | - | |
58 | 53 | } |
59 | - | |
60 | 54 | @Override |
61 | 55 | protected void onCreate(Bundle savedInstanceState) |
62 | 56 | { |
63 | 57 | Log.d(this.getClass().getName(), "onCreate"); |
64 | - this.setupDefaultActivity(); | |
65 | 58 | super.onCreate(savedInstanceState); |
59 | + this.setupDefaultActivity(); | |
66 | 60 | this.setContentView(R.layout.main); |
67 | - this._ast=AST_RUN; | |
68 | - } | |
69 | - private int _frid=0xffffffff; | |
70 | - private int _sw; | |
71 | - private int _sh; | |
72 | - public void initView(int i_rid) | |
73 | - { | |
74 | - this.initView(i_rid,LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); | |
75 | - } | |
76 | - public FrameLayout initView(int i_rid,int i_width,int i_height) | |
77 | - { | |
78 | - this._frid=i_rid; | |
79 | - this._sw=i_width; | |
80 | - this._sh=i_height; | |
81 | - // Create the GL view | |
82 | - return this._frame_layout; | |
83 | 61 | } |
84 | 62 | @Override |
85 | 63 | protected void onStart() |
86 | 64 | { |
87 | 65 | super.onStart(); |
88 | - this._frame_layout=((FrameLayout)this.findViewById(this._frid)); | |
89 | - if(this._frame_layout==null){ | |
90 | - Log.d(this.getClass().getName(), "Layout not found. Should call initView in constructor!"); | |
91 | - finish(); | |
92 | - } | |
93 | - this.setupDefaultView(); | |
94 | - this._frame_layout.addView(this._glView, 0, new LayoutParams(this._sw,this._sh)); | |
95 | 66 | return; |
96 | 67 | } |
97 | 68 | @Override |
@@ -100,7 +71,7 @@ public class AndSketch extends Activity | ||
100 | 71 | super.onStop(); |
101 | 72 | try { |
102 | 73 | for(IAndSketchEventListerner i : this._evlistener) { |
103 | - i.onStop(); | |
74 | + i.onAcStop(); | |
104 | 75 | } |
105 | 76 | } catch (Exception e) { |
106 | 77 | e.printStackTrace(); |
@@ -111,18 +82,13 @@ public class AndSketch extends Activity | ||
111 | 82 | super.onDestroy(); |
112 | 83 | try { |
113 | 84 | for(IAndSketchEventListerner i : this._evlistener) { |
114 | - i.onDestroy(); | |
85 | + i.onAcDestroy(); | |
115 | 86 | } |
116 | 87 | } catch (Exception e) { |
117 | 88 | e.printStackTrace(); |
118 | 89 | } |
119 | 90 | } |
120 | 91 | |
121 | - ///////////////////// | |
122 | - protected GLSurfaceView _glView; | |
123 | - private GLSurfaceView.Renderer _render; | |
124 | - private FrameLayout _frame_layout; | |
125 | - | |
126 | 92 | /** |
127 | 93 | * onCreate関数からコールします。 |
128 | 94 | */ |
@@ -137,46 +103,9 @@ public class AndSketch extends Activity | ||
137 | 103 | // 画面がスリープに入らないようにする |
138 | 104 | this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
139 | 105 | // 横向き固定 |
140 | -// this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | |
141 | - } | |
142 | - /** | |
143 | - * onCreate関数からコールします。 | |
144 | - */ | |
145 | - protected void setupDefaultView() | |
146 | - { | |
147 | - this._glView=new GLSurfaceView(this); | |
148 | - this._glView.setEGLConfigChooser( 8, 8, 8, 8, 16, 0); | |
149 | - this._glView.getHolder().setFormat(PixelFormat.TRANSLUCENT); | |
150 | - this._render=new DefaultRenderer(this); | |
151 | - this._glView.setRenderer(this._render); | |
152 | - } | |
153 | - | |
154 | - | |
155 | - | |
156 | - | |
157 | - | |
158 | - | |
159 | - | |
160 | -// | |
161 | -// 関数ハンドラ | |
162 | -// | |
163 | - | |
164 | - public void setup(GL10 gl) | |
165 | - { | |
166 | - } | |
167 | - /** | |
168 | - * 継承したクラスで表示したいものを実装してください | |
169 | - * @param gl | |
170 | - */ | |
171 | - public void draw(GL10 gl) | |
172 | - { | |
106 | + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | |
173 | 107 | } |
174 | 108 | |
175 | - public void addListener(IAndSketchEventListerner i_evl) throws Exception | |
176 | - { | |
177 | - this._evlistener.add(i_evl); | |
178 | - i_evl.onStart(); | |
179 | - } | |
180 | 109 | public void _finish(Exception e) |
181 | 110 | { |
182 | 111 | if(e!=null){ |
@@ -186,43 +115,3 @@ public class AndSketch extends Activity | ||
186 | 115 | } |
187 | 116 | } |
188 | 117 | |
189 | - | |
190 | - | |
191 | -/** | |
192 | - * Single Marker Detector にのみ対応した OpenGL ES Renderer | |
193 | - * モデルデータの読み出しなどが含まれない、純粋にOpenGL ESで処理する場合の基本クラス。 | |
194 | - * 継承したクラス内で何かしらの描画処理を行わないと何もしないので注意してください。 | |
195 | - */ | |
196 | -class DefaultRenderer implements GLSurfaceView.Renderer | |
197 | -{ | |
198 | - private AndSketch _parent; | |
199 | - public DefaultRenderer(AndSketch i_parent) | |
200 | - { | |
201 | - this._parent=i_parent; | |
202 | - } | |
203 | - /** | |
204 | - * Logging Tag | |
205 | - */ | |
206 | - @Override | |
207 | - public void onSurfaceCreated(GL10 gl, EGLConfig config) | |
208 | - { | |
209 | - // Transparent background | |
210 | - gl.glClearColor(0.5f, 0.0f, 0.0f, 0.f); | |
211 | - gl.glEnable(GL10.GL_DEPTH_TEST); | |
212 | - this._parent.setup(gl); | |
213 | - } | |
214 | - | |
215 | - @Override | |
216 | - public void onSurfaceChanged(GL10 gl, int width, int height) | |
217 | - { | |
218 | - for(IAndSketchEventListerner i : this._parent._evlistener) { | |
219 | - i.onGlChanged(gl,width,height); | |
220 | - } | |
221 | - gl.glViewport(0, 0, width, height); | |
222 | - } | |
223 | - @Override | |
224 | - public void onDrawFrame(GL10 gl) | |
225 | - { | |
226 | - this._parent.draw(gl); | |
227 | - } | |
228 | -} |
@@ -1,11 +0,0 @@ | ||
1 | -package jp.androidgroup.nyartoolkit.sketch; | |
2 | - | |
3 | -import javax.microedition.khronos.opengles.GL10; | |
4 | - | |
5 | -public interface IAndSketchEventListerner { | |
6 | - public void onResume(); | |
7 | - public void onStart() throws Exception; | |
8 | - public void onDestroy() throws Exception; | |
9 | - public void onStop() throws Exception; | |
10 | - public void onGlChanged(GL10 i_gl,int i_width,int i_height); | |
11 | -} |
@@ -7,7 +7,6 @@ import jp.nyatla.nyartoolkit.core.raster.INyARGrayscaleRaster; | ||
7 | 7 | import jp.nyatla.nyartoolkit.core.raster.INyARRaster; |
8 | 8 | import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster; |
9 | 9 | import jp.nyatla.nyartoolkit.core.rasterdriver.INyARHistogramFromRaster; |
10 | -import jp.nyatla.nyartoolkit.core.rasterdriver.NyARHistogramFromRasterFactory; | |
11 | 10 | import jp.nyatla.nyartoolkit.core.squaredetect.NyARContourPickup; |
12 | 11 | import jp.nyatla.nyartoolkit.core.types.NyARBufferType; |
13 | 12 | import jp.nyatla.nyartoolkit.core.types.NyARHistogram; |
@@ -183,7 +182,8 @@ class NyARContourPickup_YUV420Reader extends NyARContourPickup_Base | ||
183 | 182 | } |
184 | 183 | if (i == 8) { |
185 | 184 | //8方向全て調べたけどラベルが無いよ? |
186 | - throw new NyARException();// return(-1); | |
185 | + return false; | |
186 | +// throw new NyARException();// return(-1); | |
187 | 187 | } |
188 | 188 | // xcoordとycoordをc,rにも保存 |
189 | 189 | c = c + xdir[dir]; |
@@ -1,6 +1,5 @@ | ||
1 | 1 | package jp.androidgroup.nyartoolkit.utils; |
2 | 2 | |
3 | -import android.util.Log; | |
4 | 3 | import jp.nyatla.nyartoolkit.core.NyARException; |
5 | 4 | import jp.nyatla.nyartoolkit.core.pixeldriver.INyARGsPixelDriver; |
6 | 5 | import jp.nyatla.nyartoolkit.core.pixeldriver.INyARRgbPixelDriver; |
@@ -12,6 +11,7 @@ import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs.INyARRgb2GsFilter; | ||
12 | 11 | import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs.INyARRgb2GsFilterRgbAve; |
13 | 12 | import jp.nyatla.nyartoolkit.core.types.NyARBufferType; |
14 | 13 | import jp.nyatla.nyartoolkit.core.types.NyARIntSize; |
14 | +import android.util.Log; | |
15 | 15 | |
16 | 16 | |
17 | 17 | /** |
@@ -32,17 +32,12 @@ | ||
32 | 32 | * Yasuhide Matsumoto |
33 | 33 | * Fuu Rokubou |
34 | 34 | */ |
35 | -package jp.androidgroup.nyartoolkit.utils; | |
35 | +package jp.androidgroup.nyartoolkit.utils.camera; | |
36 | 36 | |
37 | 37 | import java.io.IOException; |
38 | 38 | import java.util.List; |
39 | 39 | |
40 | -import javax.microedition.khronos.opengles.GL10; | |
41 | - | |
42 | 40 | import jp.androidgroup.nyartoolkit.sketch.AndSketch; |
43 | -import jp.androidgroup.nyartoolkit.sketch.IAndSketchEventListerner; | |
44 | - | |
45 | -import android.content.Context; | |
46 | 41 | import android.graphics.ImageFormat; |
47 | 42 | import android.hardware.Camera; |
48 | 43 | import android.hardware.Camera.Size; |
@@ -62,7 +57,7 @@ import android.view.SurfaceView; | ||
62 | 57 | * @author nyatla |
63 | 58 | * |
64 | 59 | */ |
65 | -public class CameraPreview extends SurfaceView implements IAndSketchEventListerner,SurfaceHolder.Callback,Camera.PreviewCallback | |
60 | +public class CameraPreview extends SurfaceView implements AndSketch.IAndSketchEventListerner,SurfaceHolder.Callback,Camera.PreviewCallback | |
66 | 61 | { |
67 | 62 | public interface IOnPreviewFrame |
68 | 63 | { |
@@ -75,14 +70,20 @@ public class CameraPreview extends SurfaceView implements IAndSketchEventListern | ||
75 | 70 | private int _cap_index; |
76 | 71 | private IOnPreviewFrame _callback; |
77 | 72 | /** |
73 | + * Must call in onSetup | |
78 | 74 | * @param context |
79 | - * @param attrs | |
80 | 75 | */ |
81 | 76 | public CameraPreview(AndSketch context) |
82 | 77 | { |
83 | 78 | super(context); |
84 | 79 | try { |
85 | - context.addListener(this);//called onStart by addlistener | |
80 | + context._evlistener.add(this); | |
81 | + this._camera_ref=Camera.open(); | |
82 | + if(this._is_enabled){ | |
83 | + this._camera_ref.setPreviewDisplay(this._holder); | |
84 | + this._camera_ref.startPreview(); | |
85 | + } | |
86 | + | |
86 | 87 | this._holder = getHolder(); |
87 | 88 | this._holder.addCallback(this); |
88 | 89 | this._holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); |
@@ -209,17 +210,7 @@ public class CameraPreview extends SurfaceView implements IAndSketchEventListern | ||
209 | 210 | ((AndSketch)this.getContext())._finish(e); |
210 | 211 | } |
211 | 212 | } |
212 | - @Override | |
213 | - public void onStart() throws Exception | |
214 | - { | |
215 | - this._camera_ref=Camera.open(); | |
216 | - if(this._is_enabled){ | |
217 | - this._camera_ref.setPreviewDisplay(this._holder); | |
218 | - this._camera_ref.startPreview(); | |
219 | - } | |
220 | - } | |
221 | - | |
222 | - public synchronized void onStop() throws Exception | |
213 | + public synchronized void onAcStop() throws Exception | |
223 | 214 | { |
224 | 215 | if(this._camera_ref!=null){ |
225 | 216 | this._camera_ref.stopPreview(); |
@@ -230,20 +221,16 @@ public class CameraPreview extends SurfaceView implements IAndSketchEventListern | ||
230 | 221 | } |
231 | 222 | } |
232 | 223 | @Override |
233 | - public void onDestroy() throws Exception | |
224 | + public void onAcDestroy() throws Exception | |
234 | 225 | { |
235 | 226 | assert(this._camera_ref==null); |
236 | 227 | } |
237 | 228 | @Override |
238 | - public void onResume() | |
229 | + public void onAcResume() | |
239 | 230 | { |
240 | - // TODO Auto-generated method stub | |
241 | - | |
242 | 231 | } |
243 | 232 | @Override |
244 | - public void onGlChanged(GL10 i_gl,int i_width,int i_height) { | |
245 | - // TODO Auto-generated method stub | |
246 | - | |
233 | + public void onAcPause() | |
234 | + { | |
247 | 235 | } |
248 | - | |
249 | 236 | } |