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

By Steve Ha on December 15, 2009 at 1:13 pm
Posted Under: Development, Tips

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\smi_wm_pro_sdk_redist_2_1_0.cab

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:

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

If you enjoyed this post, be sure to subscribe to our RSS feed! Or your can read this blog via Email Subscription.

Add a Comment

please enter your name (*required)
will not be published (*required)
your website (optional)

Jump to Top
About | Term of Service | Contact | Site Map
All images and content are copyright to their respected authors.
© 2009 CareAce.net. All Rights Reserved