09-11-2012 01:35 PM
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
09-12-2012 06:59 AM - edited 09-12-2012 07:00 AM
Hi,
You can find the axis direction from this link:
https://developer.blackberry.com/html5/apis/accele
In BBJAVA device axis direction can be find from this link:
I observe that BB10 has same axis as BBJAVA has.
Thanks,
Megha.
09-12-2012 07:27 AM
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
09-12-2012 07:41 AM
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/refer
09-12-2012 07:57 AM
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
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.
Kind regards,
Steve
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?
09-19-2012 04:28 PM