Friday, June 1, 2007

Mobile Java 3D Tips, Tricks & Code

MascotWorldConnected: adding interaction between two phones via Bluetooth

This example is based on a previous example entitled "MascotWorld" and adds player interaction via Bluetooth™.

Download MascotWorldConnected example>>

To run this application, you need two Bluetooth-enabled mobile phones (e.g. Sony Ericsson K750) and you connect them at the start of application using Bluetooth. Once communication is established, the 3D world is started and each user sees two cars: his own and the opponent's. Each user can drive his own car or navigate through the 3D world. You can switch between these using the phone's soft keys.

The Bluetooth part of the application consists of server or a client. The user chooses between them.

While you are moving your own car, the updated position and rotation coordinates are sent to other party, so your car can be displayed in the proper location on your opponents screen.

The User can control movement of the car, but this is limited. When the user is moving the car, the camera follows the same way. The car can move:

* arrow left/right: turn left/right
* arrow up/down: move forward/backward
* keys 4/6: move left/right
* fire: centers camera on top of car

In a commercial application, it is possible to speed up the Bluetooth connection setup by hardcoding the URL of the other phones. This could be done by caching the URL once connected, so it will connect much faster the next time.

No comments: