private void setTangoListeners() {
// Select coordinate frame pairs
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE));
private void setTangoListeners() {
// Select coordinate frame pairs
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE));
// Add a listener for Tango pose data
mTango.connectListener(framePairs, new OnTangoUpdateListener() {
@Override
public void onPoseAvailable(TangoPoseData pose) {
// Format Translation and Rotation data
final String translationMsg = String.format(sTranslationFormat,
pose.translation[0], pose.translation[1],
pose.translation[2]);
final String rotationMsg = String.format(sRotationFormat,
pose.rotation[0], pose.rotation[1], pose.rotation[2],
pose.rotation[3]);
// Output to LogCat
String logMsg = translationMsg + " | " + rotationMsg;
Log.i(TAG, logMsg);
final double deltaTime = (pose.timestamp - mPreviousTimeStamp)
* SECS_TO_MILLISECS;
mPreviousTimeStamp = pose.timestamp;
mTimeToNextUpdate -= deltaTime;
// Throttle updates to the UI based on UPDATE_INTERVAL_MS.
if (mTimeToNextUpdate < 0.0) {
mTimeToNextUpdate = UPDATE_INTERVAL_MS;
// Display data in TextViews. This must be done inside a
// runOnUiThread call because
// it affects the UI, which will cause an error if performed
// from the Tango
// service thread
runOnUiThread(new Runnable() {
@Override
public void run() {
mRotationTextView.setText(rotationMsg);
mTranslationTextView.setText(translationMsg);
}
});
}
}
The above code gives us translation and rotation coordinate in 3D. As we move or change the orientation of tango tablet the mtango. setclicklistener is called and the inside code run and update the coordinates..
What I am not able to understand is that how is the coordinate is getting updated when setclicklistener
is called? can anyone explain me the working of the code inside the onposeavailable()
?