Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
scraft
Posts: 44
Registered: ‎01-06-2012
My Device: PlayBook
My Carrier: Orange

Accelerometer axis orientation

Hi there,

 

When calling the following function:

 

accelerometer_read_forces

 

How can I be sure which axis is which? This issue has come up because I use the same code for Playbook and BB10, and I believe the BB10 has a different axis set up when running a portrait application (presumably the axis are aligned if the device is the 'right way up' but how do I query the 'right way up' in a future proof way that will work if a landscape BB10 phone comes out, or a portrait PlayBook tablet).

 

Kind regards,

 

Steve

Please use plain text.
Super Contributor
Meghasanghvi
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Re: Accelerometer axis orientation

[ Edited ]

Hi,

 

You can find the axis direction from this link:

https://developer.blackberry.com/html5/apis/acceleration.html

 

In BBJAVA device axis direction can be find from this link:

http://www.blackberry.com/developers/docs/4.7.0api/net/rim/device/api/system/AccelerometerSensor.htm...

 

I observe that BB10 has same axis as BBJAVA has. 

 

 

Thanks,

Megha.

 

Please use plain text.
Contributor
scraft
Posts: 44
Registered: ‎01-06-2012
My Device: PlayBook
My Carrier: Orange

Re: Accelerometer axis orientation

Hi Megha,

 

I believe my question instead should be, how do I know whether the device is portrait or landscape? For my graphics and input code, I create my surface, and then set a variable:

 

// Is hardware landscape or portrait.
m_LandscapeHardware = m_Width > m_Height;

 

Then if the hardware surface orientation doesn't match the applications required orientation, I set up a rotation hardware viewport matrix to correct this graphically, and apply suitable flipping for touch screen input cordinates.

 

However, it did not appear that this flag necessarily matches up with the physics orientation of the device, and therefore the orientation of the accelerometer axis. Instead, when setting up the accelerometer values for the game, I hard code, along the lines of:

 

// TODO: Although we know if the touch screen is landscape/portrait, we don't know the orientation for the accelerometer axis.
#if defined(_BB10)
bool landscapeHardware = false;
#elif defined(_PLAYBOOK)
bool landscapeHardware = true;
#endif

 

if ( landscapeHardware != landscapeGame )

  accelerometer_read_forces( &y, &x, &z );

else

  accelerometer_read_forces( &x, &y, &z );

 

So I need something to replace the #ifdef code for landscapeHardware, getting it from the NDK/device.

 

Hopefully this clearly describes my problem, advance appologies if I have overlocked something obvious (probably the case).

 

Kind regards,

 

Steve

Please use plain text.
Super Contributor
Meghasanghvi
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Re: Accelerometer axis orientation

Hi,

 

If you want to know current orientation of the BB10 device you can find it using this api. https://developer.blackberry.com/native/beta/reference/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_r...

 

 

Please use plain text.
Contributor
scraft
Posts: 44
Registered: ‎01-06-2012
My Device: PlayBook
My Carrier: Orange

Re: Accelerometer axis orientation

Hi,

 

As the accelerometer axis is not affected by the current orientation of the device, I do not believe this helps me. The accelerometer axis is based on the devices default orientation (I believe), so I need to know if the default orientation is portrait or landscape.

 

Kind regards,

 

Steve

 

Please use plain text.
Super Contributor
Meghasanghvi
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Re: Accelerometer axis orientation

So you only need to find default orientation right? There is function by using which you can find the default orientation of your application. You can also lock the orienation in bar file.

Please use plain text.
Contributor
scraft
Posts: 44
Registered: ‎01-06-2012
My Device: PlayBook
My Carrier: Orange

Re: Accelerometer axis orientation

I don't think it is the orientation from the BAR file, as it is my belief the accelerometer doesn't provide data that is flipped based on this orientation.

 

I believe the accelerometer always provides data based on hard coded axis along the device, ultimately I need to know that, if, when the device is being held in landscape, is it the X or the Y accelerometer axis that runs horizonally along the device.

 

For the PlayBook, the accelerometer axis is based on the device being landscape (so the X accelerometer axis runs along the X axis of the screen when in landscape), for the BB10 Dev Alpha, the acceleomter axis is based on the device being in portrait (so the X accelerometer axis runs along the Y axis of the screen when in landscape).

 

I hope I am explaining myself fully.

 

Kind regards,

 

Steve

Please use plain text.
Contributor
singmajesty
Posts: 30
Registered: ‎03-06-2012
My Device: BlackBerry PlayBook 4G
My Carrier: AT&T

Re: Accelerometer axis orientation

I also had this problem when the TouchPad was released for webOS.

 

Basically, accelerometer data needs to be relative to the native screen orientation. If it is not relative, there needs to be a way to call up a simple offset, like "-90" or "0", depending on the device, so you can handle accelerometer input as is relative to the screen.

 

Does checking the device screen size work to tell if it is a portrait or landscape device, to apply an offset manually?

Please use plain text.
Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Accelerometer axis orientation

Please use plain text.