Unity free で Leap Motionをつかってみる

Unity standard(free版)でLeap Motionを使おうと思ったのだが、ちょっとつまる所があったので備忘として。

ちなみにwindows7 64bitを使っている。

何故かLeap Motion Developers に書いてあるとおりにして、シーンを実行しても落ちてしまうので、自分の書いたHello Worldが悪いのかと思い、Unityのasset storeから「Leap Motion Skeletal Assets」をインポートしてみた。

サンプルも実行しても落ちるので環境構築がうまく行ってないことがほぼ確定したのでインポートしたLeapMotionのおいてあるassetのフォルダにあるpluginsのフォルダにある

・LeapCSharp.NET3.5.dllをassetフォルダにおく
・plugins\x86_64にあるLeapCSharp.dllとLeap.dllをプロジェクトのrootにおく

と動いた。

結果的にはLeapMotionDevelopersのサイトにあるフォルダの配置にはなるが、何故かこちらでは動くので一応、備忘までに

ProcessingのTextArea(下にある黒いところ)に日本語を表示させる

processingをいじっていて、下の黒い部分に日本語を表示させる必要が出てきたが、
文字化けしてしまって出ないということがあった。

processingのコメントアウトのところを日本語にする方法は
様々なところ(例えばこことか)で述べられているけれど
下の黒いエリア、正確にはTextAreaに日本語を表示させる方法が見つからなかったので
日本語化の手順を紹介してみます。

ちなみに、自分の環境は
windows7-64bit
processing 2.0.3
エディタとして
sublime text2
を利用しています。

①processingを起動する。

②File -> preferencesをクリックして、「More Preferences can be edited directly in the file」に続くファイルの場所にあるpreferences.txtを開く
(自分の場合は「C:\Users\USERNAME\AppData\Roaming\Processing」にあった。)

③その中にある「console.font =processing.mono,plain,12」を
「console.font =MSGothic,plain,12」に書き換える。

※ちなみに「editor.font =processing.mono,plain,12」を
「editor.font =MSGothic,plain,12」に書き換えると、コメントアウト部分の日本語表示も可能になる。
※編集する際はprocessingは一旦終了してください。

④書き換えて保存したらprocessingを起動して、println("こんにちは世界");などと記入すると下の黒い部分に日本語が表示される!!

これで下のTextAreaに日本語が表示されるようになったはずです。
もしこれで表示されなかったらPCを再起動してみるかpreferences.txtを再確認してみてください。

processingでtwitter !!

ちょっと時間ができたのでprocessingでtwitterにtweetする方法でも紹介してみます。

主に参考にしたサイト:Processing 2.0とTwitter4Jで、ProcessingからTweetしてみる
環境:windows7 64bit processing2.0.1


twitterのアカウントを作成する(みんな持ってると思うけど)

Twitter for Developersにログイン

③自分のアイコンのところにマウスカーソルを持ってくと現れるメニューから

「My applications」を選択

③「create a new application」をクリック

④必要事項を入力(注意!この時、「callback URL」は必須ではないですがhttp://hogehoge.comとか適当に入れとかないとできません)して、「create your twitter appication」をクリック

⑤「Settings」から「Application Type」の「Access」を「Read and Write」に変更して

下の「update this Twitter application's update」をクリック

⑥「Details」から「Create my access token」をクリック

⑦processingを起動し以下のコードをコピー&ペーストする(このコードはほぼここからの引用です)

import twitter4j.conf.*;

import twitter4j.internal.async.*;

import twitter4j.internal.org.json.*;

import twitter4j.internal.logging.*;

import twitter4j.internal.util.*;

import twitter4j.api.*;

import twitter4j.util.*;

import twitter4j.internal.http.*;


String msg = "Automatically posted from Processing";

 

String consumerKey = "xxxx";

String consumerSecret = "xxxx";

String accessToken = "xxxx";

String accessSecret = "xxxx";

Twitter myTwitter;

 

int ms;

color bg = color(0, 0, 0);

 

void setup() {

  size(400, 400);

  frameRate(60);

 

  ConfigurationBuilder cb = new ConfigurationBuilder();

  cb.setOAuthConsumerKey(consumerKey);

  cb.setOAuthConsumerSecret(consumerSecret);

  cb.setOAuthAccessToken(accessToken);

  cb.setOAuthAccessTokenSecret(accessSecret);

  myTwitter = new TwitterFactory(cb.build()).getInstance();

}

 

void draw() {

  background(bg);

  if (millis() - ms > 1000) {

    bg = color(0, 0, 0);

  }

}

 

void mousePressed() {

  try {

    Status st = myTwitter.updateStatus(msg + ", " + getDate());

    println("Successfully updated the status to [" + st.getText() + "].");

    ms = millis();

    bg = color(0, 0, 255);

  }

  catch (TwitterException e) {

    println(e.getStatusCode());

    bg = color(255, 0, 0);

  }

}

 

String getDate() {

  String monthStr, dayStr, hourStr, minuteStr, secondStr;

 

  if (month() < 10) {

    monthStr = "0" + month();

  } 

  else {

    monthStr = "" + month();

  }

  if (day() < 10) {

    dayStr = "0" + day();

  } 

  else {

    dayStr = "" + day();

  }

  if (hour() < 10) {

    hourStr = "0" + hour();

  } 

  else {

    hourStr = "" + hour();

  }

  if (minute() < 10) {

    minuteStr = "0" + minute();

  } 

  else {

    minuteStr = "" + minute();

  }

  if (second() < 10) {

    secondStr = "0" + second();

  } 

  else {

    secondStr = "" + second();

  }

 

  return monthStr + "/" + dayStr + ", " + hourStr + ":" + minuteStr + ":" + secondStr;

} 

⑧上のコードの「consumerKey」「consumerSecret」「accessToken」
「 accessSecret」にそれぞれ自分の「Twitter for Developers」の「Details」からそれぞれのxxxxに値を代入する

ここからtwitter4jの最新版(2013/8/3現在はtwitter4f-3.0.3.zip)をダウンロード&解凍

⑨先ほどダウンロードしたTwitter4jの中の「lib」の中にある5つの「.jar」ファイルを

コードの中にドラッグ&ドロップ



⑩実行して出てきた画面をクリックするとツイートされます!!

⑪いろいろ改造するとbotとか作れるようになる!!


Android端末で動かす場合は下記の2点に注意してください。
1.「(マイ)ドキュメント」→「processing」→「libraries」に「twitter4j」フォルダを入れない。
2.Processingの「Android」タブから「Sketch Permissions」の「INTERNET」にチェックを入れる。



こんな感じで気が向いた時とか詰まってたことが解決した時とかに書いていくかもなのでよろしくお願いします。