{"id":11093,"date":"2021-12-24T22:12:41","date_gmt":"2021-12-24T14:12:41","guid":{"rendered":"https:\/\/www.bookcard.net\/wordpress\/?p=11093"},"modified":"2021-12-24T22:12:41","modified_gmt":"2021-12-24T14:12:41","slug":"android_studio_ndk_ontouch","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/android_studio_ndk_ontouch\/","title":{"rendered":"Android Studio NDK-\u89e6\u6478onTouch()"},"content":{"rendered":"<figure id=\"attachment_11094\" aria-describedby=\"caption-attachment-11094\" style=\"width: 1280px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2021\/12\/Android_Studio_NDK_onTouch.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11094\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2021\/12\/Android_Studio_NDK_onTouch.jpg\" alt=\"Android Studio NDK-\u89e6\u6478onTouch()\" width=\"1280\" height=\"800\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2021\/12\/Android_Studio_NDK_onTouch.jpg 1280w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2021\/12\/Android_Studio_NDK_onTouch-300x188.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2021\/12\/Android_Studio_NDK_onTouch-768x480.jpg 768w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/a><figcaption id=\"caption-attachment-11094\" class=\"wp-caption-text\">Android Studio NDK-\u89e6\u6478onTouch()<\/figcaption><\/figure>\n<p>\u521d\u53f0Android\u624b\u6a5f\u5df1\u91c7\u7528\u300e\u55ae\u9ede\u300f\u89e6\u6478, \u76f4\u81f3Android2.0(SDK version 5) \u5148\u652f\u6301\u300e\u591a\u9ede\u300f\u89e6\u6478.<\/p>\n<ol>\n<li>Android\u89f8\u6478\u76e3\u807d\u300eOnTouchListener\u300f \u76e3\u807d \u300e\u89e6\u5c4f\u300f\u4e8b\u4ef6.<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">static class TounchListener implements OnTouchListener{<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"2\">\n<li>\u901a\u904e\u300eonTouch()\u300f\u7372\u53d6\u300e\u89e6\u5c4f\u300f\u4fe1\u606f.<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">@Override<\/p>\n<p>public boolean onTouch(View v, MotionEvent event) {<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"3\">\n<li>0(\u00c9CLAIR)(API 5) \u5148\u652f\u6301\u591a\u9ede\u89e6\u6478<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.ECLAIR)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"4\">\n<li>\u8655\u7406\u300e\u591a\u9ede\u300f\u89e6\u6478<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">MultiTouch(v, event); else<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"5\">\n<li>\u8655\u7406\u300e\u55ae\u9ede\u300f\u89e6\u6478<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">SingleTouch(v, event);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"6\">\n<li>\u8fd4\u56defalse, \u7e7c\u7e8c\u8655\u7406\u89f8\u6478\u4e8b\u4ef6.<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">return false;}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<ol>\n<li>\u751f\u6210\u89f8\u6478\u76e3\u807d<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">private static TounchListener Tounch_Listener\u00a0 = new TounchListener() ;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"2\">\n<li>\u70baOpenGL View\u6ce8\u518a\u89e6\u6478\u76d1\u542c,<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">view.setOnTouchListener(Tounch_Listener);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"3\">\n<li>\u901a\u904eOnTouch()(View v, MotionEvent event) \u7372\u53d6\u300e\u89e6\u5c4f\u300f\u5750\u6a19 . \u300e\u89e6\u5c4f\u300f\u539f\u9ede(0,0) \u4fc2\u5de6\u4e0a\u89d2, \u55ae\u4f4d\u8c61\u7d20<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"288\">MotionEvent.getX()<\/td>\n<td width=\"288\">X\u8ef8\u6307\u53f3<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.getY()<\/td>\n<td width=\"288\">Y\u8ef8\u6307\u4e0b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"4\">\n<li>\u7372\u53d6\u300e\u89e6\u5c4f\u300f\u4e8b\u4ef6\u985e\u578b . MotionEvent.getAction()<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"288\">MotionEvent.getAction()<\/td>\n<td width=\"288\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.ACTION_DOWN<\/td>\n<td width=\"288\">\u624b\u6307\u64b3\u5c4f<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.ACTION_POINTER_DOWN<\/td>\n<td width=\"288\">\u624b\u6307\u64b3\u5c4f<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.ACTION_UP<\/td>\n<td width=\"288\">\u624b\u6307\u9b06\u79bb<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.ACTION_POINTER_UP<\/td>\n<td width=\"288\">\u624b\u6307\u9b06\u79bb<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.ACTION_CANCEL<\/td>\n<td width=\"288\">\u624b\u52e2\u9b06<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.ACTION_MOVE<\/td>\n<td width=\"288\">\u79fb\u52d5\u624b\u6307<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"5\">\n<li>\u300e\u89e6\u5c4f\u300f\u985e\u578b\u7c21\u5316\u70ba\u300e\u64b3\u300f\u300e\u9b06\u300f\u300e\u62d6\u300f\u4e09\u985e<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"288\">public static int ACTION_UP =\u00a0\u00a0\u00a0\u00a0 1;<\/td>\n<td width=\"288\">\u9b06<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">public static int ACTION_DOWN = 2;<\/td>\n<td width=\"288\">\u64b3<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">public static int ACTION_DRAGGED = 3;<\/td>\n<td width=\"288\">\u62d6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u8655\u7406\u300e\u55ae\u9ede\u300f\u89e6\u6478<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">static void SingleTouch(View v, MotionEvent event){<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"6\">\n<li>\u63d0\u53d6\u300e\u89e6\u5c4f\u300f\u4e8b\u4ef6\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">int action = event.getAction() &amp; MotionEvent.ACTION_MASK;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"7\">\n<li>\u8655\u7406\u300e\u64b3\u300f\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if(action == MotionEvent.ACTION_DOWN ||<\/p>\n<p>action == MotionEvent.ACTION_POINTER_DOWN)<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Lib.setTouch(ACTION_DOWN,event.getX(),event.getY());else<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"8\">\n<li>\u8655\u7406\u300e\u64b3\u300f\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if(action == MotionEvent.ACTION_UP ||<\/p>\n<p>action == MotionEvent.ACTION_POINTER_UP ||<\/p>\n<p>action == MotionEvent.ACTION_CANCEL)<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Lib.setTouch(ACTION_UP,event.getX(),event.getY());else<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"9\">\n<li>\u8655\u7406\u300e\u62d6\u300f\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if(action == MotionEvent.ACTION_MOVE)<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">Lib.setTouch(ACTION_DRAGGED,event.getX(),event.getY());}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u8655\u7406\u300e\u591a\u9ede\u300f\u89e6\u6478<\/p>\n<ol start=\"10\">\n<li>\u8655\u7406\u591a\u624b\u6307\u89e6\u6478, \u63d0\u53d6\u89e6\u6478\u4e8b\u4ef6\u7d22\u5f15<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">int Pointer_Index = (event.getAction() &amp; MotionEvent.ACTION_POINTER_ID_MASK)&gt;&gt;MotionEvent.ACTION_POINTER_ID_SHIFT;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"11\">\n<li>\u901a\u904e\u89e6\u6478\u4e8b\u4ef6\u7d22\u5f15,\u300e\u89e6\u5c4f\u300f\u539f\u9ede(0,0) \u4fc2\u5de6\u4e0a\u89d2, \u55ae\u4f4d\u8c61\u7d20<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"288\">MotionEvent.getX(index)<\/td>\n<td width=\"288\">X\u8ef8\u6307\u53f3<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">MotionEvent.getY(index)<\/td>\n<td width=\"288\">Y\u8ef8\u6307\u4e0b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"12\">\n<li>\u63d0\u53d6\u300e\u89e6\u5c4f\u300f\u4e8b\u4ef6\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">int action = event.getAction() &amp; MotionEvent.ACTION_MASK;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"13\">\n<li>\u8655\u7406\u591a\u624b\u6307\u89e6\u6478, \u63d0\u53d6\u89e6\u6478\u4e8b\u4ef6\u7d22\u5f15<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">int Pointer_Index = (event.getAction() &amp; MotionEvent.ACTION_POINTER_ID_MASK)&gt;&gt;MotionEvent.ACTION_POINTER_ID_SHIFT;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"14\">\n<li>\u63d0\u53d6\u89f8\u6478\u4e8b\u4ef6\u91cf<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">int Pointer_Count = event.getPointerCount();<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"15\">\n<li>\u904d\u6b77\u519a\u89f8\u6478\u4e8b\u4ef6<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">for(int i=0; i&lt; Pointer_Count; ++i)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"16\">\n<li>\u8df3\u904e\u5187\u95dc\u89f8\u6478\u4e8b\u4ef6<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if (action != MotionEvent.ACTION_MOVE &amp;&amp; i != Pointer_Index)<\/p>\n<p>continue;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"17\">\n<li>\u8655\u7406\u300e\u64b3\u300f\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if(action == MotionEvent.ACTION_DOWN ||<\/p>\n<p>action == MotionEvent.ACTION_POINTER_DOWN)<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Lib.setTouch(ACTION_DOWN,event.getX(i),event.getY(i));else<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"18\">\n<li>\u8655\u7406\u300e\u64b3\u300f\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if(action == MotionEvent.ACTION_UP ||<\/p>\n<p>action == MotionEvent.ACTION_POINTER_UP ||<\/p>\n<p>action == MotionEvent.ACTION_CANCEL)<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Lib.setTouch(ACTION_UP,event.getX(i),event.getY(i));else<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"19\">\n<li>\u8655\u7406\u300e\u62d6\u300f\u985e\u578b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">if(action == MotionEvent.ACTION_MOVE)<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">Lib.setTouch(ACTION_DRAGGED,event.getX(i),event.getY(i));}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u4fc2C++\u7de9\u5b58\u300e\u89e6\u5c4f\u300f\u4fe1\u606fLib.setTouch();<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"288\">typedef struct TOUCH_STR{<\/td>\n<td width=\"288\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">int action;<\/td>\n<td width=\"288\">\u89e6\u5c4f\u985e\u578b<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">int x,y;<\/td>\n<td width=\"288\">\u89e6\u5c4f\u5750\u6a19<\/td>\n<\/tr>\n<tr>\n<td width=\"288\">}TOUCH,*TOUCH_PTR;<\/td>\n<td width=\"288\">&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u300e\u89e6\u5c4f\u5ea7\u6a19\u300f\u8f49\u300e\u7192\u5c4f\u5ea7\u6a19\u300f<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"575\">void TouchToScreen(<a href=\"https:\/\/www.bookcard.net\/wordpress\/android_studio_ndk_opengl_es_2d_camera\/\">CAMERA2D_PTR<\/a> cam,VECTOR2D_PTR touch){<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">touch-&gt;x = (touch-&gt;x \/ (float)cam-&gt;real_width) * cam-&gt;frustum_width * cam-&gt;zoom;<\/td>\n<\/tr>\n<tr>\n<td width=\"575\">touch-&gt;y = (1-touch-&gt;y \/(float)cam-&gt;real_height) * cam-&gt;frustum_height * cam-&gt;zoom; }<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521d\u53f0Android\u624b\u6a5f\u5df1\u91c7\u7528\u300e\u55ae\u9ede\u300f\u89e6\u6478, \u76f4\u81f3Android2.0(SDK version 5) \u5148\u652f\u6301\u300e\u591a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_studio_ndk_ontouch\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">Android Studio NDK-\u89e6\u6478onTouch()<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,62],"tags":[2,50],"class_list":["post-11093","post","type-post","status-publish","format-standard","hentry","category-android","category-opengl","tag-android","tag-opengl","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/11093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/comments?post=11093"}],"version-history":[{"count":1,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/11093\/revisions"}],"predecessor-version":[{"id":11095,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/11093\/revisions\/11095"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=11093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=11093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=11093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}