{"id":4350,"date":"2018-07-28T20:54:45","date_gmt":"2018-07-28T12:54:45","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=4350"},"modified":"2018-10-14T21:28:27","modified_gmt":"2018-10-14T13:28:27","slug":"android_game_2d_camera","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/android_game_2d_camera\/","title":{"rendered":"Android\u904a\u6232\u4e4b2D\u76f8\u6a5f"},"content":{"rendered":"<figure id=\"attachment_4351\" aria-describedby=\"caption-attachment-4351\" style=\"width: 1200px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/07\/Android_Game_2D_Camera.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4351\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/07\/Android_Game_2D_Camera.jpg\" alt=\"\" width=\"1200\" height=\"800\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/07\/Android_Game_2D_Camera.jpg 1200w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/07\/Android_Game_2D_Camera-300x200.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/07\/Android_Game_2D_Camera-768x512.jpg 768w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/07\/Android_Game_2D_Camera-1024x683.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><figcaption id=\"caption-attachment-4351\" class=\"wp-caption-text\">Android\u904a\u6232\u4e4b2D\u76f8\u6a5f<\/figcaption><\/figure>\n<p>\u5b9a\u7fa92D\u76f8\u6a5f\u5373\u8a2d\u5b9a\u300e\u6295\u5f71\u77e9\u9663\u300f\u8207\u300e\u8996\u53e3\u300f<\/p>\n<p>\u300e\u8996\u53e3\u300f\u7528\u65bc\u63a7\u5236\u8f38\u51fa\u5716\u50cf\u5c3a\u5bf8\u8207\u6e32\u67d3\u5e40\u7de9\u5b58\u4f4d\u7f6e.OpenGL ES\u4f7f\u7528\u300e\u8996\u53e3\u300f\u5c07\u6295\u5f71\u5230\u300e\u8fd1\u88c1\u526a\u9762\u300f\u9ede\u5ea7\u6a19\u8b8a\u63db\u70ba\u300e\u5e40\u7de9\u5b58\u300f\u50cf\u7d20\u5ea7\u6a19<\/p>\n<p>GL10.glViewport(int x,int y,int width,int height);<\/p>\n<p>x\u548cy\u5ea7\u6a19\u70ba\u5e40\u7de9\u5b58\u5340\u8996\u53e3\u5de6\u4e0a\u89d2.width\u548cheight\u70ba\u8996\u53e3\u5927\u5c0f.\u55ae\u4f4d\u70ba\u50cf\u7d20.\u5e40\u7de9\u5b58\u5ea7\u6a19\u539f\u9ede\u70ba\u5c4f\u5e55\u5de6\u4e0b\u89d2.\u901a\u5e38\u5c07x\u548cy\u8a2d\u70ba0.width\u548cheight\u8a2d\u70ba\u5c4f\u5e55\u5206\u8fa8\u7387.\u5373\u8a2d\u70ba\u5168\u5c4f.<\/p>\n<p>gl.glViewport(0, 0, view.getWidth(), view.getHeight());<\/p>\n<p>\u300e\u6295\u5f71\u77e9\u9663\u300f\u57282D\u76f8\u6a5f\u4e2d\u53ea\u4f7f\u7528\u300e\u5e73\u884c\u6295\u5f71\u300f.\u9996\u5148\u5c07\u7576\u524d\u77e9\u9663\u8a2d\u70ba\u300e\u6295\u5f71\u77e9\u9663\u300f<\/p>\n<p>gl.glMatrixMode(GL10.GL_PROJECTION);<\/p>\n<p>\u8f09\u5165\u55ae\u4f4d\u77e9\u9663<\/p>\n<p>gl.glLoadIdentity();<\/p>\n<p>\u8a2d\u7f6e\u6b63\u4ea4\u6295\u5f71\u77e9\u9663<\/p>\n<p>GL10. glOrthof(int left,int right,int bottom,int top,int near,int far);<\/p>\n<p>OpenGL ES\u5ea7\u6a19\u7cfb\u7d71\u6b63X\u8ef8\u6307\u5411\u53f3,\u6b63Y\u8ef8\u6307\u5411\u4e0a.\u6b63Z\u8ef8\u6307\u5411\u6211.left\u8207right\u70baX\u8ef8\u5de6\u53f3\u5169\u689d\u908a.bottom\u8207 top\u70baY\u8ef8\u4e0a\u4e0b\u5169\u689d\u908a.near\u70ba\u8fd1\u7aef\u88c1\u526a\u9762.far\u70ba\u9060\u7aef\u88c1\u526a\u9762.\u82e5\u8a2d2D\u6a6b\u5411\u76f8\u6a5f\u5de6\u4e0b\u89d2(0,0)\u53f3\u4e0a\u89d2(480,320)\u8996\u9310\u6df1\u5ea6\u70ba2<\/p>\n<p>gl.glOrthof(0,480,0,320,1, -1);<\/p>\n<p>\u91cd\u8a2d\u70ba\u6a21\u578b\u8996\u5716\u77e9\u9663<\/p>\n<p>gl.glMatrixMode(GL10.GL_MODELVIEW);<\/p>\n<p>gl.glLoadIdentity();<\/p>\n<p>2D\u76f8\u6a5f\u5c07\u300e\u89f8\u5c4f\u300f\u5750\u6a19\u8f49\u300e\u4e16\u754c\u300f\u5750\u6a19.\u9996\u5148\u8a2d\u5b9a\u8996\u9310\u9ad4\u5bec\u70ba15\u9ad8\u70ba10.<\/p>\n<p>float frustum_width = 15;<\/p>\n<p>float frustum_height = 10;<\/p>\n<p>\u8a2d\u7e2e\u653e\u4fc2\u6578\u70ba1.\u7528\u65bc\u653e\u5927\u5c4f\u5e55\u5927\u65bc1,\u7e2e\u5c0f\u5c4f\u5e55\u5c0f\u65bc1<\/p>\n<p>float zoom = 1;<\/p>\n<p>\u9996\u5148\u5c07\u300e\u89f8\u5c4f\u300f\u4f4d\u7f6e\u6b78\u7bc4\u570d(0~1).\u7136\u5f8c\u4e58\u4ee5\u8996\u9310\u9ad4\u5bec\u548c\u9ad8<\/p>\n<p>touch.x = (touch.x \/ view.getWidth()) * frustum_width * zoom;<\/p>\n<p>\u56e0\u70ba\u89f8\u5c4f\u5ea7\u6a19\u539f\u9ede\u4f4d\u65bc\u5c4f\u5e55\u5de6\u4e0a\u89d2.\u9700\u5012\u8f49Y\u8ef8<\/p>\n<p>touch.y = (1-touch.y \/view.getHeight()) * frustum_height * zoom;<\/p>\n<p>\u8207\u76f8\u6a5f\u4f4d\u7f6e\u76f8\u6a5f<\/p>\n<p>touch.add(position);<\/p>\n<p>\u6700\u5f8c\u6e1b\u65bc\u8996\u9310\u9ad4\u4e2d\u5fc3\u4f4d\u7f6e.\u5f97\u5230\u904a\u6232\u300e\u4e16\u754c\u300f\u5750\u6a19<\/p>\n<p>touch.x = touch.x &#8211; frustum_width*zoom\/2f;<\/p>\n<p>touch.y = touch.y &#8211; frustum_height*zoom\/2f;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u7fa92D\u76f8\u6a5f\u5373\u8a2d\u5b9a\u300e\u6295\u5f71\u77e9\u9663\u300f\u8207\u300e\u8996\u53e3\u300f \u300e\u8996\u53e3\u300f\u7528\u65bc\u63a7\u5236\u8f38\u51fa\u5716\u50cf\u5c3a\u5bf8\u8207\u6e32\u67d3\u5e40\u7de9\u5b58\u4f4d\u7f6e.OpenGL ES\u4f7f\u7528 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_2d_camera\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">Android\u904a\u6232\u4e4b2D\u76f8\u6a5f<\/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-4350","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\/4350","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=4350"}],"version-history":[{"count":1,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4350\/revisions"}],"predecessor-version":[{"id":4352,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4350\/revisions\/4352"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=4350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=4350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=4350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}