{"id":3046,"date":"2013-09-16T12:36:09","date_gmt":"2013-09-16T03:36:09","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3046"},"modified":"2014-11-03T16:30:03","modified_gmt":"2014-11-03T07:30:03","slug":"post-3046","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/javascript\/3046","title":{"rendered":"JavaScript\u3067\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0"},"content":{"rendered":"<p>\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u3067\u5730\u7403\u5100\u3092\u3050\u308b\u3050\u308b\u56de\u3059\u3088\uff01<br \/>\n<a href=\"http:\/\/shimz.me\/labo\/HeadTracking\/01\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/d3glob.jpg\" alt=\"d3glob\" width=\"564\" height=\"503\" class=\"aligncenter size-full wp-image-2634\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/d3glob.jpg 564w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/d3glob-168x150.jpg 168w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/labo\/HeadTracking\/01\/\">example<\/a><\/p>\n<p><a href=\"http:\/\/gunma-web.org\/\">Gunma.web #14<\/a>\u3067\u767a\u8868\u3057\u3066\u304d\u305f\u5185\u5bb9\u306e\u4e00\u3064\u3001Canvas\u3092\u4f7f\u3063\u305f\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u4f5c\u6210\u3057\u305f\u30c7\u30e2\u3067\u3059\u3002<br \/>\n\u30ab\u30e1\u30e9\u306b\u5bfe\u3059\u308b\u982d(\u9854)\u306e\u4f4d\u7f6e\u3067\u3001\u5730\u7403\u5100\u306e\u56de\u8ee2\u3059\u308b\u65b9\u5411(X\u8ef8)\u304c\u5909\u308f\u308a\u307e\u3059\u3002<br \/>\n\u5f53\u7136\u306e\u3053\u3068\u306a\u304c\u3089Web\u30ab\u30e1\u30e9\u304c\u306a\u3044PC\u3067\u306f\u52d5\u304d\u307e\u305b\u3093\u3002\u307e\u305f\u3001Chrome\u3067\u3057\u304b\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u3044\u307e\u305b\u3093\u3002<br \/>\n\u4e0a\u8a18\u30da\u30fc\u30b8\u3092\u958b\u304f\u3068\u300cWeb\u30ab\u30e1\u30e9\u306e\u4f7f\u7528\u300d\u306e\u8a31\u53ef\uff0f\u62d2\u5426\u3092\u5229\u304b\u308c\u308b\u306e\u3067\u3001\u5229\u7528\u306e\u969b\u306f\u8a31\u53ef\u3092\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u5168\u3066\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u3067\u51e6\u7406\u3092\u884c\u3046\u305f\u3081\u3001\u30b5\u30fc\u30d0\u30fc\u5074\u306b\u30c7\u30fc\u30bf\u3092\u9001\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u6c17\u306b\u306a\u308b\u4eba\u306fWeb\u30ab\u30e1\u30e9\u4f7f\u7528\u306e\u8a31\u53ef\u3092\u51fa\u3059\u524d\u306b\u30bd\u30fc\u30b9\u3092\u8abf\u3079\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/auduno\/headtrackr\">headtrackr.js<\/a><\/p>\n<p>\u4e0a\u8a18\u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u3001Web\u30ab\u30e1\u30e9\u304b\u3089\u306e\u5165\u529b\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u89e3\u6790\u3057\u3066\u9854\u306e\u4f4d\u7f6e\u3092\u691c\u51fa\u3057\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u3001\u6b63\u9762\u3067\u3057\u304b\u691c\u51fa\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u307e\u305f\u3001\u691c\u51fa\u5f8c\u306e\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u306f\u30a8\u30c3\u30b8\u3068\u808c\u306e\u8272\u3092\u5143\u306b\u8ffd\u8de1\u3059\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u808c\u306e\u8272\u3068\u80cc\u666f\u306e\u8272\u306b\u5dee\u304c\u3042\u307e\u308a\u306a\u3044\u3068\u898b\u5931\u3046\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<br \/>\n\u307e\u305f\u3001\u90e8\u5c4b\u304c\u6697\u3059\u304e\u305f\u308a\u3057\u3066\u3082\u99c4\u76ee\u3002<br \/>\n\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u7aef\u672b\u306e\u30b9\u30da\u30c3\u30af\u306b\u3088\u3063\u3066\u306f\u3001\u9854\u5ea7\u6a19\u3092\u691c\u51fa\u3059\u308b\u307e\u3067\u306b\u7d50\u69cb\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3059\u3002<br \/>\n\u4f7f\u3044\u3069\u3053\u308d\u304c\u96e3\u3057\u3044\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u304c\u3001\u7c21\u5358\u306b\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u3092\u5b9f\u88c5\u3067\u304d\u308b\u306e\u3067\u3001\u8a66\u3057\u3066\u307f\u308b\u3068\u9762\u767d\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u5730\u7403\u5100\u81ea\u4f53\u306fD3.js\u3092\u4f7f\u3063\u3066\u63cf\u753b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2631\">\u3010D3.js\u3011 SVG\u3067\u5730\u7403\u5100\u3092\u63cf\u304f<\/a><\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>headtrackr.js\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:xhtml decode:true \" >&lt;script src=&quot;..\/headtrackr.min.js&quot;&gt;&lt;\/script&gt;\r\n<\/pre>\n<p>input\u7528\u30fboutput\u7528\u306e\u30ad\u30e3\u30f3\u30d0\u30b9\u3068\u3001web\u30ab\u30e1\u30e9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\u305f\u3081\u306evideo\u30bf\u30b0\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:xhtml decode:true \" >&lt;canvas id='ic' width=&quot;160&quot; height=&quot;120&quot; style=&quot;display:none&quot; &gt;&lt;\/canvas&gt;\r\n&lt;video id=&quot;iv&quot; autoplay loop&gt;&lt;\/video&gt;\r\n&lt;canvas id='oc' width=&quot;160&quot; height=&quot;120&quot;&gt;&lt;\/canvas&gt;\r\n<\/pre>\n<p>\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u51e6\u7406\u306f\u4ee5\u4e0b\u3002<\/p>\n<pre class=\"lang:js decode:true \" >var svg = d3.select('svg');\r\n\r\nvar rotateX = 0;\r\n\r\n\/\/\u6d77\u3000\u5b9f\u306f\u305f\u3060\u306ecircle\r\nsvg.append('circle')\r\n    .attr({\r\n\tfill:&quot;blue&quot;,\r\n\tcx:480,\r\n\tcy:250,\r\n\tr:245\r\n    });\r\n\r\nvar\tprojection = d3.geo.orthographic() \/\/\u6295\u5f71\u6cd5\u3092\u6307\u5b9a\r\n\t.scale(245) \/\/\u5927\u304d\u3055\r\n\t.rotate([rotateX,0,0]) \/\/x,y,z\u56de\u8ee2\r\n\t.clipAngle(90); \/\/\u8868\u793a\u3059\u308b\u89d2\u5ea6 180\u5ea6\u3092\u6307\u5b9a\u3059\u308b\u3068\u88cf\u5074\u306e\u5927\u9678\u307e\u3067\u8868\u793a\u3055\u308c\u308b\r\n\r\nvar \tpath = d3.geo.path().projection(projection);\r\n\r\n\r\nd3.json(&quot;world.topojson&quot;, function(json){ \/\/\u5730\u56f3\u60c5\u5831\u306e\u8aad\u307f\u8fbc\u307f\r\n\r\n    var data = topojson.object(json, json.objects.conuntries); \/\/topojson\u5909\u63db\r\n\r\n    svg.append(&quot;svg:g&quot;).attr({&quot;class&quot;:&quot;earth&quot;}); \/\/g\u8981\u7d20\u8ffd\u52a0(\u30b0\u30eb\u30fc\u30d7\u5316)\r\n   \r\n   \/\/\u5730\u56f3\u8868\u793a\r\n    map = svg\r\n\t.selectAll(&quot;path&quot;)\r\n\t.data(data.geometries) \r\n\t.enter()\r\n\t.append(&quot;svg:path&quot;)\r\n\t.style(&quot;background-color&quot;, &quot;blue&quot;)\r\n\t.attr({\r\n\t    &quot;class&quot;: &quot;path tip&quot;,\r\n\t    &quot;d&quot;:path,\r\n\t    &quot;fill-opacity&quot;:1,\r\n\t    &quot;fill&quot;:&quot;green&quot;,\r\n\t    &quot;stroke&quot;:&quot;#222&quot;,\r\n\t    'data-tip':function(d){ return d.properties.sovereignt }\r\n\t})\r\n\t.on(&quot;mouseover&quot;, function(){\r\n\t    d3.select(this).attr(&quot;fill&quot;, &quot;red&quot;);\r\n\t})\r\n\t.on(&quot;mouseout&quot;, function(){\r\n\t    d3.select(this).transition().duration(500).attr(&quot;fill&quot;, &quot;green&quot;);\r\n\t});\r\n       \r\n\tmap.append('title') \/\/\u30c4\u30fc\u30eb\u30c1\u30c3\u30d7\u8ffd\u52a0\r\n\t    .text(function(d){ return d.properties.sovereignt });\r\n\t\r\n});\r\n\r\n\r\n\r\n\/*\r\n * \u3053\u3053\u304b\u3089\u4e0b\u304cheadtrackr\u95a2\u9023\u306e\u51e6\u7406\r\n *\/\r\nvar vi = document.getElementById('iv');\r\nvar ci = document.getElementById('ic');\r\nvar co = document.getElementById('oc');\r\n\r\n\/\/ output\u7528\u30ad\u30e3\u30f3\u30d0\u30b9\u306e\u4f4d\u7f6e\u8a2d\u5b9a\r\nco.style.position = &quot;absolute&quot;;\r\nco.style.top = '0px';\r\nco.style.zIndex = '999';\r\nco.style.display = 'block';\r\n\r\n\/\/\u30b3\u30f3\u30c6\u30af\u30b9\u30c8\u53d6\u5f97\r\nvar ctx = co.getContext('2d');\r\nctx.strokeStyle = &quot;red&quot;;\r\n\r\nvar x = 0;\r\nvar y = 0;\r\nvar w = 0;\r\nvar h = 0;\r\n\r\n\/\/ headtrackr\u8aad\u307f\u8fbc\u307f\r\nvar ht = new headtrackr.Tracker({ui : false});\r\nconsole.log(ht.init(vi, ci));\r\n\/\/\u3000\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u958b\u59cb\r\nht.start();\r\n\r\n\/\/\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u958b\u59cb\u6642\u306e\u30a4\u30d9\u30f3\u30c8\r\ndocument.addEventListener('headtrackrStatus', \r\n    function (event) {\r\n\tswitch (event.status) {\r\n\t    case 'no camera': alert('WEB\u30ab\u30e1\u30e9\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093');break;\r\n\t    case 'no getUserMedia': alert('getUserMedia\u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u30d6\u30e9\u30a6\u30b6\u3067\u3059');break;\r\n\t}    \r\n\td3.select('#HSstatus').text(&quot;status:&quot; + event.status);\r\n    }\r\n);\r\n    \r\n\/\/\u3000\u30d5\u30a7\u30a4\u30b9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u30a4\u30d9\u30f3\u30c8\r\ndocument.addEventListener('facetrackingEvent', \r\n    function (event) {\r\n\td3.select('#FTEheight').text(&quot;height:&quot; + event.height);\r\n\td3.select('#FTEwidth').text(&quot;width:&quot; + event.width);\r\n\td3.select('#FTEangle').text(&quot;angle:&quot; + event.angle);\r\n\td3.select('#FTEx').text(&quot;x:&quot; + event.x);\r\n\td3.select('#FTEy').text(&quot;y:&quot; + event.y);\r\n\td3.select('#FTEy').text(&quot;y:&quot; + event.y);\r\n\td3.select('#FTEconfidence').text(&quot;confidence:&quot; + event.confidence);\r\n\td3.select('#FTEdetection').text(&quot;detection:&quot; + event.detection);\r\n\td3.select('#FTEtime').text(&quot;time:&quot; + event.time);\r\n\r\n\t\/\/\u524d\u753b\u9762\u3092\u30af\u30ea\u30a2\r\n\tctx.clearRect(0, 0, 160, 120);\r\n\r\n\tw = event.width;\r\n\th = event.height;\r\n\tx = event.x - w\/2;\r\n\ty = event.y - h\/2;\r\n\r\n\t\/\/\u9854\u306e\u5468\u308a\u306b\u56db\u89d2\u3092\u66f8\u304d\u51fa\u3059\r\n\tctx.strokeRect(x, y, w, h);\r\n    }    \r\n);\r\n\r\n\/\/\u3000\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u30a4\u30d9\u30f3\u30c8\r\ndocument.addEventListener('headtrackingEvent', \r\n    function (event) {\r\n\td3.select('#HTEx').text(&quot;x:&quot; + event.x);\r\n\td3.select('#HTEy').text(&quot;y:&quot; + event.y);\r\n\td3.select('#HTEz').text(&quot;z:&quot; + event.z);\r\n        \r\n\t\/\/\u5730\u7403\u5100\u56de\u3059\u51e6\u7406 \r\n\trotateX = rotateX + ~~event.x * -1;   \r\n\tprojection.rotate([rotateX, 0, 0]);  \/\/rotate\u306e\u5024\u3092\u5897\u3084\u3057\u3066\r\n\tpath = d3.geo.path().projection(projection);    \/\/path\u95a2\u6570\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\r\n\tmap.attr(&quot;d&quot;, path); \/\/paht\u95a2\u6570\u3092map\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u9069\u7528\r\n      \r\n    }\r\n);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30d8\u30c3\u30c9\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u3067\u5730\u7403\u5100\u3092\u3050\u308b\u3050\u308b\u56de\u3059\u3088\uff01 ex&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2634,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56,18,6],"tags":[],"class_list":["post-3046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-canvas","category-d3-js","category-javascript","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=3046"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3046\/revisions"}],"predecessor-version":[{"id":3256,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3046\/revisions\/3256"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2634"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}