2011年8月21日日曜日

Using TwitterAPI from Unity Web Player

This blog is a translation of this entry that written by my student.
http://d.hatena.ne.jp/anchan828/20110821

There's a crossdomain limitation to post a tweet from UnityWebPlayer.

Here, we used some detour for this.
The main idea is calling javascript function from Unity and using OAuth2.0 to POST.
We used @Anywhere to implement this.

1. Preparation

Register your application to Twitter dev(https://dev.twitter.com/).
After you finish registration, move to @Anywhere Domains in the settings section for the application and register your domain name.










ex. unity-games.appspot.com for UnityGames(http://unity-games.appspot.com/)

That's all for setting up your application.

Then, insert the line into the webpage where you want to put your UnityWebPlayer.
<script src="http://platform.twitter.com/anywhere.js?id=Consumer key for your Twitter App&v=1">



Now, you are ready to use @AnyWhere

2. Implement javascript function in the webpage.

The functions you need are Authorization and POST.
Authorization function is here.
function connect(){


var url = "https://oauth.twitter.com/2/authorize?oauth_callback_url="
      //the call back should be the webpage address where your Unity Web Player is.
+ encodeURIComponent(location.href)
+ "&oauth_mode=flow_web_client&oauth_client_identifier=Consumer Key for your Twitter App";
var F = 0;
if (screen.height > 500) {
F = Math.round((screen.height / 2) - (250))
}
  // The window option is a default for @AnyWhere
window.open(url, "twitter_anywhere_auth", "left=" + Math.round((screen.width / 2) - (250)) + ",top=" + F
+ ",width=500,height=500"
+ ",personalbar=no,toolbar=no,resizable=no,scrollbars=yes");
}
Next, post function using ajax will be like this. (The function is using JQuery(http://jquery.com))
//url will be something like "https://api.twitter.com/1/statuses/update.json". You must url encode the parameters.

function post(url) {
$.ajax({
type: "post",
     //The access token for twitter can be load with localStorage.getItem("twttr_anywhere")
url: url+ "&oauth_access_token="+encodeURIComponent(localStorage.getItem("twttr_anywhere")),
success: function (e) {
// write whatever you want to do.
}
});
}
Mind that you should use HTTPS protocol here.
You must always give "oauth_access_token=取得したAccess_Token" as a parameter for posting to Twitter.

3. Implementation in Unity.

It's easy to call javascript function in the webpage from Unity.
You can use,
Application.ExternalCall (http://unity3d.com/support/documentation/ScriptReference/Application.ExternalCall.html)

First, authorize your self. If you call the function, a popup window will be shown.
Application.ExternalCall ("connect");

Next, POST your tweet.
//URL encode your twee (http://unity3d.com/support/documentation/ScriptReference/WWW.EscapeURL.html)

Application.ExternalCall ("post", "https://api.twitter.com/1/statuses/update.json?status=" + WWW.EscapeURL (tweet));
Now, you can tweet from your Unity Web Player!
You can try the working example here ->(Let’s Twitter In UnityWebPlayer

2011年1月14日金曜日

Head to "Sojo University Unity3D Competition"

In our university, 3rd grade students are studying game development using Unity3D in the lecture called "Animation Study". Students are required to plan and create their original 3D/2D game with Unity3D. For most students, game development is a first trial (some of them did not even make any 3D models before). They studied Blender and Unity3D, that I introduced in the lecture. Also, some students studied Metasequoia or Google Sketchup to emphasize their work. Finally, their works are forming into a game.

The evaluation of their games is done by public voting on the Web. If they get many votes, they will get a good mark!

I am building the voting system with Slim3 and AppEngine/J. They are really powerful!



You will be able to vote with Google and Mixi OpenID. Also you can use Twitter authentication.
Something like "Like" from Facebook will be supported as well.

It will start on 26th of January, if there is no problem. We hope that many people get interested in the trial. We will post the link for our voting system on the blog later.

Please vote for their games!

2010年8月26日木曜日

Using Emgu CV on Mac OSX


Yesterday, I thought of trying to run Emgu CV on Mac OSX.
I write what I did for that here.

*Emgu CV is a OSS Open CV wrapper for .Net framework.

OS: Mac OSX Snow Leopard (10.6.4) failed
Mac OSX Leopard(10.5.8) succeed!

1. Installing Mono and Monodevelop (for now you dont really need Monodevelop)

== Japanese problem ==
You need to specify a font that can be used for your own language if you are using Multi-bytes.
Create next file with admin authority.
/Library/Frameworks/Mono.Framework/Version/Current/etc/pango/pango.aliases
Write a line like below.
"Lucida Grande" = "Hiragino Kaku Gothic Pro"
==================

2. Installing depending libraries via Macports
sudo port selfupdate
sudo port upgrade outdated
sudo port install cmake
sudo port install ffmpeg
sudo port install tiff
3. Get a source code from SVN repository
svn co https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk emgucv
4. Creating make file by cmake
cmake -DBUILD_NEW_PYTHON_SUPPORT:BOOL=FALSE -DBUILD_TESTS:BOOL=FALSE .

5. Executing make
make
6. Running samples
move to bin directory
set value to read library from current directory

export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
execute a sample
mono Example.PlanarSubdivision.monoexe
Error!
System.DllNotFoundException
7. Setting Log level and execute again
MONO_LOG_LEVEL=debug mono Example.PlanarSubdivision.monoexe
It seems 64bit is not supported by Mono 2.6.7 so that it is hard to run on Snow Leopard.

8. Trying to build with 32bit option
cmake -DCMAKE_OSX_ARCHITECTURES=i386 -DBUILD_NEW_PYTHON_SUPPORT:BOOL=FALSE -DBUILD_TESTS:BOOL=FALSE .
got an error at make command.
It said something like Open CV should be 64bit...

hmm, I gave up with Snow Leopard ...

9. Trying with Leopard (10.5.8)
Mostly same as above however library path was different so set as below.
export LD_LIBRARY_PATH=../lib:.:$LD_LIBRARY_PATH
I could run the sample!

2010年7月18日日曜日

Tomcat 6 grant setting for GWT, Lucene, JPA, HIbernate and Spring Framework

WIth Ubuntu 10.04,

Running GWT on Tomcat6 with Lucene, JPA, Hibernate and Spring Framework,
you need to grant many permissions.

Write in, "04webapps.policy"

grant {

permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "org.apache.lucene.lockDir", "read";
permission java.util.PropertyPermission "sun.arch.data.model", "read";
permission java.util.PropertyPermission "org.apache.lucene.store.FSDirectoryLockFactoryClass", "read";
permission java.util.PropertyPermission "org.apache.lucene.analysis.standard.StandardAnalyzer.replaceInvalidAcronym", "read";
permission java.util.PropertyPermission "cglib.debugLocation", "read";
permission java.util.PropertyPermission "ANTLR_DO_NOT_EXIT", "read";
permission java.util.PropertyPermission "ANTLR_USE_DIRECT_CLASS_LOADING", "read";


//Required for Spring Framework
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.lang.RuntimePermission "getProtectionDomain";
permission java.net.SocketPermission "127.0.0.1:3306","connect,resolve,listen,accept";
permission java.net.SocketPermission "localhost:3306","connect,resolve,listen,accept";

Linux and Proxy setting notes

Linux & proxy settings are always very bothersome to search.

[apt-get] export command or set as a environmental variable
export http_proxy=http://[address]:[port]/

[wget] xport command or set as a environmental variable
export http_proxy=http://[address]:[port]/

[yum] 環xport command or set as a environmental variable
export http_proxy=http://[address]:[port]/

[rpm] use command line options
rpm --httpproxy [address] --httpport [port]

Ubuntu 10.04 sudo via ssh

When you try to send sudo command via ssh, I got this message.
sudo: no tty present and no askpass program specified

There are some entries that says you should comment out "Defaults requiretty" from /etc/sudoers, however, there is no such line in the file for Ubuntu 10.04.

Writing "Defaults visibletty" works fine although you password will be visible when you type.

It didn't sound the best solution and I found out that using "-t" option for ssh command is better way. Then the command will be something like this.

ssh -t [address] sudo shutdown -h now

In addition,
Writing the following like in "/etc/sudoers" will let you "sudo" without prompting password request.
username ALL=NOPASSWD: ALL

2010年3月1日月曜日

Japanese Morphological Analyzer on GAE

I made a Japanese morphological analyzer on Google Apps Engine.

You can input Japanese sentences and then you will see the analysis result.
http://onlinejpanalyser.appspot.com/sen/

I used Slim3 that is a full-stack MVC framework optimized for Google App Engine/Java.
Also, I used Sen to analyze Japanese sentences.