09-11-2012 01:35 PM
When calling the following function:
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).
09-12-2012 06:59 AM - edited 09-12-2012 07:00 AM
You can find the axis direction from this link:
In BBJAVA device axis direction can be find from this link:
I observe that BB10 has same axis as BBJAVA has.
09-12-2012 07:27 AM
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.
bool landscapeHardware = false;
bool landscapeHardware = true;
if ( landscapeHardware != landscapeGame )
accelerometer_read_forces( &y, &x, &z );
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).
09-12-2012 07:41 AM
If you want to know current orientation of the BB10 device you can find it using this api. https://developer.blackberry.com/native/beta/refer
09-12-2012 07:57 AM
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.
09-12-2012 07:59 AM
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.
09-12-2012 08:03 AM
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.
09-19-2012 01:27 PM
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?