Monday, August 6th, 2007

The Wii Remote API: Now your userbase is four.

Category: Games, Opera

<>p>The Opera folk have released an API that allows you, the developer, to be able to monitor all of the remotes that are connected with The Wii Remote API.

This means that you can watch up to four people buzzing around the screen:

Polling the status of a remote

The Wii Remote data is accessed through the opera.wiiremote object. This object offers a single method opera.wiiremote.update(n) which is used to obtain the status of an individual Wii Remote. The method expects a single parameter; the Wii Remote number. The number is zero-based, so it starts at 0 for the first remote, and ends at 3 for the fourth remote. The method returns a KpadStatus object, which has several properties that give information about the remote.

This update method can be called as often as is needed to obtain a fluid response, but note that the Wii is not as powerful as most desktop computers, so it is important to make sure that it is polled only as often as the script that uses that data can process it. For example, if a script uses the Wii Remote status to update the display of a canvas element, and that update will take perhaps 50 ms to update in Opera on a desktop computer, it may take over 100 ms on a Wii. Attempting to use a polling interval of less than 100 ms will cause the response to appear very sluggish.

Note that the opera.wiiremote object only exists in Opera on Wii, so it is important to check for its existence, as well as the existence of the opera object, before attempting to use it.

Examples

javascript
< view plain text >
  1. //Obtaining the roll of the third Wii remote in degrees
  2.  
  3. var remote, roll = 0;
  4. //check if the browser provides access to the Wii Remote data
  5. if( window.opera && opera.wiiremote ) {
  6.   //get the KpadStatus object for the third Wii Remote
  7.   remote = opera.wiiremote.update(2);
  8.   //check that the remote is enabled
  9.   if( remote.isEnabled ) {
  10.     //get the roll angle in radians
  11.     roll = Math.atan2( remote.dpdRollY, remote.dpdRollX );
  12.     //convert the roll to degrees
  13.     roll = roll * ( 180 / Math.PI );
  14.   }
  15. }
  16.  
  17. // Checking what buttons are pressed on the second remote
  18. var remote, buttons = {};
  19. //check if the browser provides access to the Wii Remote data
  20. if( window.opera && opera.wiiremote ) {
  21.   //get the KpadStatus object for the third Wii Remote
  22.   remote = opera.wiiremote.update(1);
  23.   //check that the remote is enabled
  24.   if( remote.isEnabled ) {
  25.     //use the bitwise AND operator to compare against the bitmasks
  26.     buttons.pressedLeft = remote.hold & 1;
  27.     buttons.pressedRight = remote.hold & 2;
  28.     buttons.pressedDown = remote.hold & 4;
  29.     buttons.pressedUp = remote.hold & 8;
  30.     buttons.pressedPlus = remote.hold & 16;
  31.     buttons.pressed2 = remote.hold & 256;
  32.     buttons.pressed1 = remote.hold & 512;
  33.     buttons.pressedB = remote.hold & 1024;
  34.     buttons.pressedA = remote.hold & 2048;
  35.     buttons.pressedMinus = remote.hold & 4096;
  36.     buttons.pressedZ = remote.hold & 8192;
  37.     buttons.pressedC = remote.hold & 16384;
  38.   }
  39. }

There are a bunch of demonstrations, including a simple game.

I can’t wait to see the Star Wars light sabre web game… and then see a Comet based app that grows beyond the four connected devices!

Related Content:

Posted by Dion Almaer at 6:15 pm
11 Comments

++++-
4.4 rating from 28 votes

11 Comments »

Comments feed TrackBack URI

…that is so freakin cool… awesome

Comment by Mark Holton — August 6, 2007

can’t wait to test it ^^

Comment by DarkRat — August 6, 2007

Why polling? Why not defining event handlers? Sounds very lame for me. While these news are cool news, the situation is a bit strange for me…

Comment by András Bártházi — August 6, 2007

I hope this works!

Comment by Hugh Jarse — August 6, 2007

The real problem is there is no information about the accelerometers. Not sure why opera exposed the other things. Detecting the remotes motion is what would be useful in an online game. Hopefully that will be released in the near future.

Ryan

Comment by Ryan — August 6, 2007

There is even the roll vale, looks interesting.
The accelerometer info is not so easy to handle, you need a quite complex code to correctly parse them, perhaps too much for a javascript code.

Comment by Andrea — August 7, 2007

polling is less resource consuming than event triggering. This must be why they implemeted it so on a hardware that’s no so powerfull as a classic computer.

Comment by gizmo — August 7, 2007

Arve, gizmo: thanks for the answer. After my message I was wondering about the same thing, this solution was quite strange. However, keep up your great work!

Comment by András Bártházi — August 7, 2007

Is it just me or they removed the article, when I try the link it tells me access is denied, even when I’m logged in.

Comment by Duarte Fonseca — August 9, 2007

Shameless Plus:

Wii Opera SDK – http://hullbreachonline.com/wii/sdk.html

Comment by Daniel Gump — September 5, 2007

Great stuff!

While trying it out I noticed that it only can get a roll value when the remote cursor is on the screen. Does anyone know why this is?

Comment by usernate — March 6, 2008

Leave a comment

You must be logged in to post a comment.