Developing with Samsung SDK: Simple Compass using 3D Orientation API

Posted on Dec 15 2009 - 1:13pm by Steve Ha

With the latest Samsung SDK release by Samsung Mobile Innovator, we are going to take a look at what we can do with the tools provided.

Using the 3D Orientation API from Samsung SDK 2.0 (or later), we have developed a simple compass, with the red needle pointing north and the blue needle pointing south.

The provided API made it easy to put together this application. Here are some of the source code for the application:

Coding with Samsung SDK’s 3D Orientation API

1. Register orientation handler

Smi3DOrientationCapabilities cap;
UINT period;
if(Smi3DOrientationGetCapabilities(∩) == SMI_SUCCESS)
period = cap.callbackPeriod;
if(Smi3DOrientationRegisterHandler(period, GetVectorHandler) == SMI_SUCCESS)
printf(“Callbacks will occur every %d ms”,period);

2. Read angle value

void GetVectorHandler(Smi3DOrientationPosition position)
printf(“heading = %d \npitch = %d \nroll = %d \naccuracy = %d\n”,
position.heading, position.pitch, position.roll, position.accuracy);
g_angle = -position.heading;

With the 3D Orientation API, I can get various values to estimate the relative position of a phone in the 3D space, and one of them is Heading value.

The value of Heading, yaw or azimuth angle, starts at 0 when the phone is facing magnetic north, and increases as the phone is turned clockwise. Using this value, the compass application calculates the north and draws needle pointing towards it.

With this program, no matter which direction your phone is facing, the red part of needle will always point north.

DialerAce: Practical Use

DialerAce uses this orientation feature to select a person to call in the 3D view. Visit here if you are interested in learning more about DialerAce application. You’ll see how you can call your friends without touching the device.

Download and Install Samsung SDK 2.1

Samsung SDK 2.1: Click here
Installer cab file for Samsung SDK:
(directory of the SDK)\redist\

Download and Install the Compass Sample App

If you are interested in trying or check out the compass sample application that we illustrated above, you can download the following zip file: [download id="25"]

To try out the compass on your device, copy the 3D_Orientation.exe file onto your device and run it to start the application.

Leave A Response