From 62ec52a8243c2607c5f6648db060996d22625b69 Mon Sep 17 00:00:00 2001 From: Jason Guo Date: Mon, 8 Aug 2016 12:28:17 -0700 Subject: [PATCH] release-tania-borealis --- .../app/src/main/AndroidManifest.xml | 0 .../AugmentedRealityActivity.java | 136 ++++++++---- .../AugmentedRealityRenderer.java | 13 +- .../java/augmentedreality/package-info.java | 0 .../src/main/res/drawable-xxhdpi/earth.jpeg | Bin .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../app/src/main/res/drawable-xxhdpi/moon.jpg | Bin .../app/src/main/res/layout/activity_main.xml | 0 .../app/src/main/res/values/strings.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../hello_video/src/main/AndroidManifest.xml | 0 .../java/hellovideo/HelloVideoActivity.java | 78 +++---- .../java/hellovideo/HelloVideoRenderer.java | 0 .../java/hellovideo/package-info.java | 0 .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../src/main/res/layout/activity_main.xml | 0 .../src/main/res/values/strings.xml | 0 .../src/main/res/values/styles.xml | 0 .../app/src/main/AndroidManifest.xml | 0 .../examples/java/floorplan/Floorplan.java | 0 .../java/floorplan/FloorplanActivity.java | 113 ++++++---- .../java/floorplan/FloorplanRenderer.java | 30 +-- .../examples/java/floorplan/PlanBuilder.java | 0 .../java/floorplan/WallMeasurement.java | 5 - .../examples/java/floorplan/package-info.java | 0 .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../app/src/main/res/drawable-xxhdpi/wall.png | Bin .../app/src/main/res/layout/activity_main.xml | 0 .../app/src/main/res/values-v11/styles.xml | 0 .../app/src/main/res/values-v14/styles.xml | 0 .../app/src/main/res/values-w820dp/dimens.xml | 0 .../app/src/main/res/values/dimens.xml | 0 .../app/src/main/res/values/strings.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../app/src/main/AndroidManifest.xml | 0 .../java/modelcorrespondence/HouseModel.java | 0 .../ModelCorrespondenceActivity.java | 171 +++++++++------ .../ModelCorrespondenceRenderer.java | 15 +- .../modelcorrespondence/package-info.java | 0 .../main/res/drawable-xxhdpi/crosshair.png | Bin .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../app/src/main/res/drawable-xxhdpi/plus.png | Bin .../app/src/main/res/drawable/progress_bg.xml | 0 .../app/src/main/res/layout/activity_main.xml | 0 .../app/src/main/res/raw/farmhouse.stl | Bin .../app/src/main/res/values-v11/styles.xml | 0 .../app/src/main/res/values-v14/styles.xml | 0 .../app/src/main/res/values-w820dp/dimens.xml | 0 .../app/src/main/res/values/colors.xml | 0 .../app/src/main/res/values/dimens.xml | 0 .../app/src/main/res/values/strings.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../opengl_ar/src/main/AndroidManifest.xml | 0 .../OpenGlAugmentedRealityActivity.java | 198 ++++++++++++------ .../OpenGlAugmentedRealityRenderer.java | 12 +- .../java/openglar/OpenGlCameraPreview.java | 0 .../examples/java/openglar/OpenGlHelper.java | 0 .../examples/java/openglar/OpenGlMesh.java | 0 .../examples/java/openglar/OpenGlSphere.java | 0 .../examples/java/openglar/package-info.java | 0 .../src/main/res/drawable-xxhdpi/earth.jpeg | Bin .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../src/main/res/drawable-xxhdpi/moon.jpg | Bin .../src/main/res/layout/activity_main.xml | 0 .../src/main/res/values-v11/styles.xml | 0 .../src/main/res/values-v14/styles.xml | 0 .../src/main/res/values-w820dp/dimens.xml | 0 .../opengl_ar/src/main/res/values/strings.xml | 0 .../opengl_ar/src/main/res/values/styles.xml | 0 .../app/src/main/AndroidManifest.xml | 0 .../planefitting/PlaneFittingActivity.java | 135 ++++++++---- .../planefitting/PlaneFittingRenderer.java | 13 +- .../java/planefitting/package-info.java | 0 .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../main/res/drawable-xxhdpi/instructions.png | Bin .../app/src/main/res/layout/activity_main.xml | 0 .../app/src/main/res/values-v11/styles.xml | 0 .../app/src/main/res/values-v14/styles.xml | 0 .../app/src/main/res/values-w820dp/dimens.xml | 0 .../app/src/main/res/values/dimens.xml | 0 .../app/src/main/res/values/strings.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../app/src/main/AndroidManifest.xml | 0 .../pointtopoint/PointToPointActivity.java | 143 ++++++++----- .../pointtopoint/PointToPointRenderer.java | 11 +- .../java/pointtopoint/package-info.java | 0 .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../app/src/main/res/layout/activity_main.xml | 0 .../app/src/main/res/values-v11/styles.xml | 0 .../app/src/main/res/values-v14/styles.xml | 0 .../app/src/main/res/values-w820dp/dimens.xml | 0 .../app/src/main/res/values/dimens.xml | 0 .../app/src/main/res/values/strings.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../app/src/main/AndroidManifest.xml | 0 .../java/videooverlay/MainActivity.java | 0 .../java/videooverlay/package-info.java | 0 .../main/res/drawable-hdpi/ic_launcher.png | Bin .../main/res/drawable-mdpi/ic_launcher.png | Bin .../main/res/drawable-xhdpi/ic_launcher.png | Bin .../main/res/drawable-xxhdpi/ic_launcher.png | Bin .../app/src/main/res/layout/activity_main.xml | 0 .../app/src/main/res/values-v11/styles.xml | 0 .../app/src/main/res/values-v14/styles.xml | 0 .../app/src/main/res/values-w820dp/dimens.xml | 0 .../app/src/main/res/values/dimens.xml | 0 .../app/src/main/res/values/strings.xml | 0 .../app/src/main/res/values/styles.xml | 0 108 files changed, 664 insertions(+), 409 deletions(-) mode change 100755 => 100644 java_augmented_reality_example/app/src/main/AndroidManifest.xml mode change 100755 => 100644 java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityActivity.java mode change 100755 => 100644 java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityRenderer.java mode change 100755 => 100644 java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/package-info.java mode change 100755 => 100644 java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/earth.jpeg mode change 100755 => 100644 java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/moon.jpg mode change 100755 => 100644 java_augmented_reality_example/app/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_augmented_reality_example/app/src/main/res/values/strings.xml mode change 100755 => 100644 java_augmented_reality_example/app/src/main/res/values/styles.xml mode change 100755 => 100644 java_basic_examples/hello_video/src/main/AndroidManifest.xml mode change 100755 => 100644 java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoActivity.java mode change 100755 => 100644 java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoRenderer.java mode change 100755 => 100644 java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/package-info.java mode change 100755 => 100644 java_basic_examples/hello_video/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_basic_examples/hello_video/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_basic_examples/hello_video/src/main/res/values/strings.xml mode change 100755 => 100644 java_basic_examples/hello_video/src/main/res/values/styles.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/AndroidManifest.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/Floorplan.java mode change 100755 => 100644 java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanActivity.java mode change 100755 => 100644 java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanRenderer.java mode change 100755 => 100644 java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/PlanBuilder.java mode change 100755 => 100644 java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/WallMeasurement.java mode change 100755 => 100644 java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/package-info.java mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/drawable-xxhdpi/wall.png mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/values-v11/styles.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/values-v14/styles.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/values-w820dp/dimens.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/values/dimens.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/values/strings.xml mode change 100755 => 100644 java_floor_plan_example/app/src/main/res/values/styles.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/AndroidManifest.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/HouseModel.java mode change 100755 => 100644 java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceActivity.java mode change 100755 => 100644 java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceRenderer.java mode change 100755 => 100644 java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/package-info.java mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/crosshair.png mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/plus.png mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/drawable/progress_bg.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/raw/farmhouse.stl mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/values-v11/styles.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/values-v14/styles.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/values-w820dp/dimens.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/values/colors.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/values/dimens.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/values/strings.xml mode change 100755 => 100644 java_model_correspondence_example/app/src/main/res/values/styles.xml mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/AndroidManifest.xml mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityActivity.java mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityRenderer.java mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlCameraPreview.java mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlHelper.java mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlMesh.java mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlSphere.java mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/package-info.java mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/earth.jpeg mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/moon.jpg mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-v11/styles.xml mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-v14/styles.xml mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-w820dp/dimens.xml mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/values/strings.xml mode change 100755 => 100644 java_opengl_augmented_reality_example/opengl_ar/src/main/res/values/styles.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/AndroidManifest.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingActivity.java mode change 100755 => 100644 java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingRenderer.java mode change 100755 => 100644 java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/package-info.java mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/drawable-xxhdpi/instructions.png mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/values-v11/styles.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/values-v14/styles.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/values-w820dp/dimens.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/values/dimens.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/values/strings.xml mode change 100755 => 100644 java_plane_fitting_example/app/src/main/res/values/styles.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/AndroidManifest.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointActivity.java mode change 100755 => 100644 java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointRenderer.java mode change 100755 => 100644 java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/package-info.java mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/values-v11/styles.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/values-v14/styles.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/values-w820dp/dimens.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/values/dimens.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/values/strings.xml mode change 100755 => 100644 java_point_to_point_example/app/src/main/res/values/styles.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/AndroidManifest.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/java/com/projecttango/examples/java/videooverlay/MainActivity.java mode change 100755 => 100644 java_video_overlay_example/app/src/main/java/com/projecttango/examples/java/videooverlay/package-info.java mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/drawable-hdpi/ic_launcher.png mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/drawable-mdpi/ic_launcher.png mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/drawable-xhdpi/ic_launcher.png mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/layout/activity_main.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/values-v11/styles.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/values-v14/styles.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/values-w820dp/dimens.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/values/dimens.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/values/strings.xml mode change 100755 => 100644 java_video_overlay_example/app/src/main/res/values/styles.xml diff --git a/java_augmented_reality_example/app/src/main/AndroidManifest.xml b/java_augmented_reality_example/app/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityActivity.java b/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityActivity.java old mode 100755 new mode 100644 index 680f8cb3..00aad00f --- a/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityActivity.java +++ b/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityActivity.java @@ -29,6 +29,7 @@ import android.app.Activity; import android.opengl.GLSurfaceView; +import android.opengl.Matrix; import android.os.Bundle; import android.util.Log; import android.view.Surface; @@ -175,9 +176,16 @@ private TangoConfig setupTangoConfig(Tango tango) { // low latency IMU integration. TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT); config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, true); + // NOTE: Low latency integration is necessary to achieve a precise alignment of // virtual objects with the RBG image and produce a good AR effect. config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true); + + // Drift correction allows motion tracking to recover after it loses tracking. + // + // The drift corrected pose is is available through the frame pair with + // base frame AREA_DESCRIPTION and target frame DEVICE. + config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true); return config; } @@ -246,52 +254,72 @@ public void onPreFrame(long sceneTime, double deltaTime) { // Prevent concurrent access to {@code mIsFrameAvailableTangoThread} from the Tango // callback thread and service disconnection from an onPause event. - synchronized (AugmentedRealityActivity.this) { - // Don't execute any tango API actions if we're not connected to the service. - if (!mIsConnected) { - return; - } - - // Set-up scene camera projection to match RGB camera intrinsics. - if (!mRenderer.isSceneCameraConfigured()) { - mRenderer.setProjectionMatrix(mIntrinsics); - } + try { + synchronized (AugmentedRealityActivity.this) { + // Don't execute any tango API actions if we're not connected to the service + if (!mIsConnected) { + return; + } - // Connect the camera texture to the OpenGL Texture if necessary - // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the - // texture with a different ID. - if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { - mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, - mRenderer.getTextureId()); - mConnectedTextureIdGlThread = mRenderer.getTextureId(); - Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); - } + // Set-up scene camera projection to match RGB camera intrinsics. + if (!mRenderer.isSceneCameraConfigured()) { + mRenderer.setProjectionMatrix( + projectionMatrixFromCameraIntrinsics(mIntrinsics)); + } + // Connect the camera texture to the OpenGL Texture if necessary + // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the + // texture with a different ID. + if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { + mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, + mRenderer.getTextureId()); + mConnectedTextureIdGlThread = mRenderer.getTextureId(); + Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); + } - // If there is a new RGB camera frame available, update the texture with it - if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { - mRgbTimestampGlThread = - mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); - } + // If there is a new RGB camera frame available, update the texture with it + if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { + mRgbTimestampGlThread = + mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); + } - // If a new RGB frame has been rendered, update the camera pose to match. - if (mRgbTimestampGlThread > mCameraPoseTimestamp) { - // Calculate the camera color pose at the camera frame update time in - // OpenGL engine. - TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( - mRgbTimestampGlThread, - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, - TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, - Surface.ROTATION_0); - if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { - // Update the camera pose from the renderer - mRenderer.updateRenderCameraPose(lastFramePose); - mCameraPoseTimestamp = lastFramePose.timestamp; - } else { - Log.w(TAG, "Can't get device pose at time: " + - mRgbTimestampGlThread); + // If a new RGB frame has been rendered, update the camera pose to match. + if (mRgbTimestampGlThread > mCameraPoseTimestamp) { + // Calculate the camera color pose at the camera frame update time in + // OpenGL engine. + // + // When drift correction mode is enabled in config file, we must query + // the device with respect to Area Description pose in order to use the + // drift corrected pose. + // + // Note that if you don't want to use the drift corrected pose, the + // normal device with respect to start of service pose is available. + TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( + mRgbTimestampGlThread, + TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, + TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, + Surface.ROTATION_0); + if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { + // Update the camera pose from the renderer + mRenderer.updateRenderCameraPose(lastFramePose); + mCameraPoseTimestamp = lastFramePose.timestamp; + } else { + // When the pose status is not valid, it indicates the tracking has + // been lost. In this case, we simply stop rendering. + // + // This is also the place to display UI to suggest the user walk + // to recover tracking. + Log.w(TAG, "Can't get device pose at time: " + + mRgbTimestampGlThread); + } } } + + // Avoid crashing the application due to unhandled exceptions + } catch (TangoErrorException e) { + Log.e(TAG, "Tango API call error within the OpenGL render thread", e); + } catch (Throwable t) { + Log.e(TAG, "Exception on the OpenGL thread", t); } } @@ -313,4 +341,30 @@ public boolean callPreFrame() { mSurfaceView.setSurfaceRenderer(mRenderer); } + + /** + * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene. + */ + private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) { + // Uses frustumM to create a projection matrix taking into account calibrated camera + // intrinsic parameter. + // Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/ + float near = 0.1f; + float far = 100; + + float xScale = near / (float) intrinsics.fx; + float yScale = near / (float) intrinsics.fy; + float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale; + // Color camera's coordinates has y pointing downwards so we negate this term. + float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale; + + float m[] = new float[16]; + Matrix.frustumM(m, 0, + xScale * (float) -intrinsics.width / 2.0f - xOffset, + xScale * (float) intrinsics.width / 2.0f - xOffset, + yScale * (float) -intrinsics.height / 2.0f - yOffset, + yScale * (float) intrinsics.height / 2.0f - yOffset, + near, far); + return m; + } } diff --git a/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityRenderer.java b/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityRenderer.java old mode 100755 new mode 100644 index d3def91f..e651125b --- a/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityRenderer.java +++ b/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityRenderer.java @@ -45,10 +45,6 @@ import javax.microedition.khronos.opengles.GL10; -import com.projecttango.rajawali.DeviceExtrinsics; -import com.projecttango.rajawali.Pose; -import com.projecttango.rajawali.ScenePoseCalculator; - /** * Renderer that implements a basic augmented reality scene using Rajawali. * It creates a scene with a background quad taking the whole screen, where the color camera is @@ -197,14 +193,11 @@ public boolean isSceneCameraConfigured() { } /** - * Sets the projection matrix for the scen camera to match the parameters of the color camera, + * Sets the projection matrix for the scene camera to match the parameters of the color camera, * provided by the {@code TangoCameraIntrinsics}. */ - public void setProjectionMatrix(TangoCameraIntrinsics intrinsics) { - Matrix4 projectionMatrix = ScenePoseCalculator.calculateProjectionMatrix( - intrinsics.width, intrinsics.height, - intrinsics.fx, intrinsics.fy, intrinsics.cx, intrinsics.cy); - getCurrentCamera().setProjectionMatrix(projectionMatrix); + public void setProjectionMatrix(float[] matrixFloats) { + getCurrentCamera().setProjectionMatrix(new Matrix4(matrixFloats)); } @Override diff --git a/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/package-info.java b/java_augmented_reality_example/app/src/main/java/com/projecttango/examples/java/augmentedreality/package-info.java old mode 100755 new mode 100644 diff --git a/java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/earth.jpeg b/java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/earth.jpeg old mode 100755 new mode 100644 diff --git a/java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/moon.jpg b/java_augmented_reality_example/app/src/main/res/drawable-xxhdpi/moon.jpg old mode 100755 new mode 100644 diff --git a/java_augmented_reality_example/app/src/main/res/layout/activity_main.xml b/java_augmented_reality_example/app/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_augmented_reality_example/app/src/main/res/values/strings.xml b/java_augmented_reality_example/app/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_augmented_reality_example/app/src/main/res/values/styles.xml b/java_augmented_reality_example/app/src/main/res/values/styles.xml old mode 100755 new mode 100644 diff --git a/java_basic_examples/hello_video/src/main/AndroidManifest.xml b/java_basic_examples/hello_video/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoActivity.java b/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoActivity.java old mode 100755 new mode 100644 index dc63a12e..149f46ec --- a/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoActivity.java +++ b/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoActivity.java @@ -234,47 +234,53 @@ public void preRender() { return; } - // Synchronize against concurrently disconnecting the service triggered from the - // UI thread. - synchronized (HelloVideoActivity.this) { - // Connect the Tango SDK to the OpenGL texture ID where we are going to - // render the camera. - // NOTE: This must be done after both the texture is generated and the Tango - // service is connected. - if (mConnectedTextureIdGlThread == INVALID_TEXTURE_ID) { - mConnectedTextureIdGlThread = mRenderer.getTextureId(); - mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, - mRenderer.getTextureId()); - Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); - } + try { + // Synchronize against concurrently disconnecting the service triggered from the + // UI thread. + synchronized (HelloVideoActivity.this) { + // Connect the Tango SDK to the OpenGL texture ID where we are going to + // render the camera. + // NOTE: This must be done after both the texture is generated and the Tango + // service is connected. + if (mConnectedTextureIdGlThread == INVALID_TEXTURE_ID) { + mConnectedTextureIdGlThread = mRenderer.getTextureId(); + mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, + mRenderer.getTextureId()); + Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); + } - // If there is a new RGB camera frame available, update the texture and - // scene camera pose. - if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { - double rgbTimestamp = - mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); - // {@code rgbTimestamp} contains the exact timestamp at which the - // rendered RGB frame was acquired. + // If there is a new RGB camera frame available, update the texture and + // scene camera pose. + if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { + double rgbTimestamp = + mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); + // {@code rgbTimestamp} contains the exact timestamp at which the + // rendered RGB frame was acquired. - // In order to see more details on how to use this timestamp to modify - // the scene camera and achieve an augmented reality effect, please - // refer to java_augmented_reality_example and/or - // java_augmented_reality_opengl_example projects. + // In order to see more details on how to use this timestamp to modify + // the scene camera and achieve an augmented reality effect, please + // refer to java_augmented_reality_example and/or + // java_augmented_reality_opengl_example projects. - // Log and display timestamp for informational purposes - Log.d(TAG, "Frame updated. Timestamp: " + rgbTimestamp); + // Log and display timestamp for informational purposes + Log.d(TAG, "Frame updated. Timestamp: " + rgbTimestamp); - // Updating the UI needs to be in a separate thread. Do it through a - // final local variable to avoid concurrency issues. - final String timestampText = String.format(sTimestampFormat, - rgbTimestamp); - runOnUiThread(new Runnable() { - @Override - public void run() { - mTimestampTextView.setText(timestampText); - } - }); + // Updating the UI needs to be in a separate thread. Do it through a + // final local variable to avoid concurrency issues. + final String timestampText = String.format(sTimestampFormat, + rgbTimestamp); + runOnUiThread(new Runnable() { + @Override + public void run() { + mTimestampTextView.setText(timestampText); + } + }); + } } + } catch (TangoErrorException e) { + Log.e(TAG, "Tango API call error within the OpenGL thread", e); + } catch (Throwable t) { + Log.e(TAG, "Exception on the OpenGL thread", t); } } }); diff --git a/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoRenderer.java b/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoRenderer.java old mode 100755 new mode 100644 diff --git a/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/package-info.java b/java_basic_examples/hello_video/src/main/java/com/projecttango/examples/java/hellovideo/package-info.java old mode 100755 new mode 100644 diff --git a/java_basic_examples/hello_video/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_basic_examples/hello_video/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_basic_examples/hello_video/src/main/res/layout/activity_main.xml b/java_basic_examples/hello_video/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_basic_examples/hello_video/src/main/res/values/strings.xml b/java_basic_examples/hello_video/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_basic_examples/hello_video/src/main/res/values/styles.xml b/java_basic_examples/hello_video/src/main/res/values/styles.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/AndroidManifest.xml b/java_floor_plan_example/app/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/Floorplan.java b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/Floorplan.java old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanActivity.java b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanActivity.java old mode 100755 new mode 100644 index 65271665..b2341e80 --- a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanActivity.java +++ b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanActivity.java @@ -21,6 +21,7 @@ import com.google.atap.tangoservice.TangoCameraIntrinsics; import com.google.atap.tangoservice.TangoConfig; import com.google.atap.tangoservice.TangoCoordinateFramePair; +import com.google.atap.tangoservice.TangoErrorException; import com.google.atap.tangoservice.TangoEvent; import com.google.atap.tangoservice.TangoException; import com.google.atap.tangoservice.TangoOutOfDateException; @@ -267,51 +268,59 @@ public void onPreFrame(long sceneTime, double deltaTime) { // Prevent concurrent access to {@code mIsFrameAvailableTangoThread} from the Tango // callback thread and service disconnection from an onPause event. - synchronized (FloorplanActivity.this) { - // Don't execute any tango API actions if we're not connected to the service - if (!mIsConnected) { - return; - } + try { + synchronized (FloorplanActivity.this) { + // Don't execute any tango API actions if we're not connected to the service + if (!mIsConnected) { + return; + } - // Set-up scene camera projection to match RGB camera intrinsics - if (!mRenderer.isSceneCameraConfigured()) { - mRenderer.setProjectionMatrix(mIntrinsics); - } + // Set-up scene camera projection to match RGB camera intrinsics + if (!mRenderer.isSceneCameraConfigured()) { + mRenderer.setProjectionMatrix( + projectionMatrixFromCameraIntrinsics(mIntrinsics)); + } - // Connect the camera texture to the OpenGL Texture if necessary - // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the - // texture with a different ID. - if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { - mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, - mRenderer.getTextureId()); - mConnectedTextureIdGlThread = mRenderer.getTextureId(); - Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); - } + // Connect the camera texture to the OpenGL Texture if necessary + // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the + // texture with a different ID. + if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { + mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, + mRenderer.getTextureId()); + mConnectedTextureIdGlThread = mRenderer.getTextureId(); + Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); + } - // If there is a new RGB camera frame available, update the texture with it - if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { - mRgbTimestampGlThread = - mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); - } + // If there is a new RGB camera frame available, update the texture with it + if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { + mRgbTimestampGlThread = + mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); + } - // If a new RGB frame has been rendered, update the camera pose to match. - if (mRgbTimestampGlThread > mCameraPoseTimestamp) { - // Calculate the camera color pose at the camera frame update time in - // OpenGL engine. - TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( - mRgbTimestampGlThread, - TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, - TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); - if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { - // Update the camera pose from the renderer - mRenderer.updateRenderCameraPose(lastFramePose); - mCameraPoseTimestamp = lastFramePose.timestamp; - } else { - Log.w(TAG, "Can't get device pose at time: " + - mRgbTimestampGlThread); + // If a new RGB frame has been rendered, update the camera pose to match. + if (mRgbTimestampGlThread > mCameraPoseTimestamp) { + // Calculate the camera color pose at the camera frame update time in + // OpenGL engine. + TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( + mRgbTimestampGlThread, + TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, + TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); + if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { + // Update the camera pose from the renderer + mRenderer.updateRenderCameraPose(lastFramePose); + mCameraPoseTimestamp = lastFramePose.timestamp; + } else { + Log.w(TAG, "Can't get device pose at time: " + + mRgbTimestampGlThread); + } } } + // Avoid crashing the application due to unhandled exceptions + } catch (TangoErrorException e) { + Log.e(TAG, "Tango API call error within the OpenGL render thread", e); + } catch (Throwable t) { + Log.e(TAG, "Exception on the OpenGL thread", t); } } @@ -332,6 +341,32 @@ public boolean callPreFrame() { }); } + /** + * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene. + */ + private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) { + // Uses frustumM to create a projection matrix taking into account calibrated camera + // intrinsic parameter. + // Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/ + float near = 0.1f; + float far = 100; + + float xScale = near / (float) intrinsics.fx; + float yScale = near / (float) intrinsics.fy; + float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale; + // Color camera's coordinates has y pointing downwards so we negate this term. + float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale; + + float m[] = new float[16]; + Matrix.frustumM(m, 0, + xScale * (float) -intrinsics.width / 2.0f - xOffset, + xScale * (float) intrinsics.width / 2.0f - xOffset, + yScale * (float) -intrinsics.height / 2.0f - yOffset, + yScale * (float) intrinsics.height / 2.0f - yOffset, + near, far); + return m; + } + /** * This method handles when the user clicks the screen. It will try to fit a plane to the * clicked point using depth data. The floor plan will be rebuilt and the result will be shown diff --git a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanRenderer.java b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanRenderer.java old mode 100755 new mode 100644 index 4e5d9930..2ae8e94e --- a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanRenderer.java +++ b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/FloorplanRenderer.java @@ -46,11 +46,6 @@ import javax.microedition.khronos.opengles.GL10; -import com.projecttango.rajawali.Pose; -import com.projecttango.rajawali.ScenePoseCalculator; -import com.projecttango.tangosupport.TangoSupport; - - /** * Very simple augmented reality example which displays cubes fixed in place for every * WallMeasurement and a continuous line for the perimeter of the floor plan. @@ -73,6 +68,18 @@ public class FloorplanRenderer extends RajawaliRenderer { private ATexture mTangoCameraTexture; private boolean mSceneCameraConfigured; + /** + * Small utility class to hold a position and orientation pair. + */ + class Pose { + public Pose(Vector3 p, Quaternion q) { + position = p; + orientation = q; + } + public Quaternion orientation; + public Vector3 position; + } + public FloorplanRenderer(Context context) { super(context); } @@ -136,8 +143,8 @@ protected void onRender(long elapsedRealTime, double deltaTime) { object3D.setDoubleSided(true); object3D.rotate(Vector3.Axis.X, 180); // Place the 3D object in the location of the detected plane. - object3D.setPosition(pose.getPosition()); - object3D.rotate(pose.getOrientation()); + object3D.setPosition(pose.position); + object3D.rotate(pose.orientation); getCurrentScene().addChild(object3D); mMeasurementObjectList.add(object3D); @@ -207,14 +214,11 @@ public boolean isSceneCameraConfigured() { } /** - * Sets the projection matrix for the scen camera to match the parameters of the color camera, + * Sets the projection matrix for the scene camera to match the parameters of the color camera, * provided by the {@code TangoCameraIntrinsics}. */ - public void setProjectionMatrix(TangoCameraIntrinsics intrinsics) { - Matrix4 projectionMatrix = ScenePoseCalculator.calculateProjectionMatrix( - intrinsics.width, intrinsics.height, - intrinsics.fx, intrinsics.fy, intrinsics.cx, intrinsics.cy); - getCurrentCamera().setProjectionMatrix(projectionMatrix); + public void setProjectionMatrix(float[] matrix) { + getCurrentCamera().setProjectionMatrix(new Matrix4(matrix)); } @Override diff --git a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/PlanBuilder.java b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/PlanBuilder.java old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/WallMeasurement.java b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/WallMeasurement.java old mode 100755 new mode 100644 index ea95f56b..7aadd14d --- a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/WallMeasurement.java +++ b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/WallMeasurement.java @@ -17,11 +17,6 @@ import android.opengl.Matrix; -import org.rajawali3d.math.Matrix4; -import org.rajawali3d.math.vector.Vector3; - -import com.projecttango.rajawali.ScenePoseCalculator; - /** * Representation of wall as a measured plane. */ diff --git a/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/package-info.java b/java_floor_plan_example/app/src/main/java/com/projecttango/examples/java/floorplan/package-info.java old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_floor_plan_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/drawable-xxhdpi/wall.png b/java_floor_plan_example/app/src/main/res/drawable-xxhdpi/wall.png old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/layout/activity_main.xml b/java_floor_plan_example/app/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/values-v11/styles.xml b/java_floor_plan_example/app/src/main/res/values-v11/styles.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/values-v14/styles.xml b/java_floor_plan_example/app/src/main/res/values-v14/styles.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/values-w820dp/dimens.xml b/java_floor_plan_example/app/src/main/res/values-w820dp/dimens.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/values/dimens.xml b/java_floor_plan_example/app/src/main/res/values/dimens.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/values/strings.xml b/java_floor_plan_example/app/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_floor_plan_example/app/src/main/res/values/styles.xml b/java_floor_plan_example/app/src/main/res/values/styles.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/AndroidManifest.xml b/java_model_correspondence_example/app/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/HouseModel.java b/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/HouseModel.java old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceActivity.java b/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceActivity.java old mode 100755 new mode 100644 index e7b3c6a6..3725aaa4 --- a/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceActivity.java +++ b/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceActivity.java @@ -251,83 +251,92 @@ private void connectRenderer() { public void onPreFrame(long sceneTime, double deltaTime) { // Prevent concurrent access to {@code mIsFrameAvailableTangoThread} from the Tango // callback thread and service disconnection from an onPause event. - synchronized (ModelCorrespondenceActivity.this) { - // Don't execute any tango API actions if we're not connected to the service - if (!mIsConnected) { - return; - } + try { + synchronized (ModelCorrespondenceActivity.this) { + // Don't execute any tango API actions if we're not connected to the service + if (!mIsConnected) { + return; + } - // Set-up scene camera projection to match RGB camera intrinsics - if (!mRenderer.isSceneCameraConfigured()) { - mRenderer.setProjectionMatrix(mIntrinsics); - } + // Set-up scene camera projection to match RGB camera intrinsics + if (!mRenderer.isSceneCameraConfigured()) { + mRenderer.setProjectionMatrix( + projectionMatrixFromCameraIntrinsics(mIntrinsics)); + } - // Connect the camera texture to the OpenGL Texture if necessary - // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the - // texture with a different ID. - if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { - mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, - mRenderer.getTextureId()); - mConnectedTextureIdGlThread = mRenderer.getTextureId(); - Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); - } + // Connect the camera texture to the OpenGL Texture if necessary + // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the + // texture with a different ID. + if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { + mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, + mRenderer.getTextureId()); + mConnectedTextureIdGlThread = mRenderer.getTextureId(); + Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); + } - // If there is a new RGB camera frame available, update the texture with it - if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { - mRgbTimestampGlThread = - mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); - } + // If there is a new RGB camera frame available, update the texture with it + if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { + mRgbTimestampGlThread = + mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); + } - // If a new RGB frame has been rendered, update the camera pose to match. - if (mRgbTimestampGlThread > mCameraPoseTimestamp) { - // Calculate the camera color pose at the camera frame update time in - // OpenGL engine. - TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( - mRgbTimestampGlThread, - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, - TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); - - if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { - // Update the camera pose from the renderer - mRenderer.updateRenderCameraPose(lastFramePose); - mCameraPoseTimestamp = lastFramePose.timestamp; - // While the correspondence is not done, fix the model to the upper - // right corner of the screen by following the camera. - if (!mCorrespondenceDone) { - TangoSupport.TangoMatrixTransformData transform = - TangoSupport.getMatrixTransformAtTime( - mCameraPoseTimestamp, - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, - TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL); - if (transform.statusCode == TangoPoseData.POSE_VALID) { - // Place it in the top left corner, and rotate and scale it - // accordingly. - float[] rgbTHouse = calculateModelTransformFixedToCam(); - // Combine the two transforms. - float[] openGlTHouse = new float[16]; - Matrix.multiplyMM(openGlTHouse, 0, transform.matrix, - 0, rgbTHouse, 0); - mOpenGlTHouse = openGlTHouse; - mModelUpdated = true; - } else { - Log.w(TAG, "Can't get camera transform at time: " + - mCameraPoseTimestamp); + // If a new RGB frame has been rendered, update the camera pose to match. + if (mRgbTimestampGlThread > mCameraPoseTimestamp) { + // Calculate the camera color pose at the camera frame update time in + // OpenGL engine. + TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( + mRgbTimestampGlThread, + TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, + TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); + + if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { + // Update the camera pose from the renderer + mRenderer.updateRenderCameraPose(lastFramePose); + mCameraPoseTimestamp = lastFramePose.timestamp; + // While the correspondence is not done, fix the model to the upper + // right corner of the screen by following the camera. + if (!mCorrespondenceDone) { + TangoSupport.TangoMatrixTransformData transform = + TangoSupport.getMatrixTransformAtTime( + mCameraPoseTimestamp, + TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, + TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL); + if (transform.statusCode == TangoPoseData.POSE_VALID) { + // Place it in the top left corner, and rotate and scale it + // accordingly. + float[] rgbTHouse = calculateModelTransformFixedToCam(); + // Combine the two transforms. + float[] openGlTHouse = new float[16]; + Matrix.multiplyMM(openGlTHouse, 0, transform.matrix, + 0, rgbTHouse, 0); + mOpenGlTHouse = openGlTHouse; + mModelUpdated = true; + } else { + Log.w(TAG, "Can't get camera transform at time: " + + mCameraPoseTimestamp); + } } + } else { + Log.w(TAG, "Can't get device pose at time: " + + mRgbTimestampGlThread); } - } else { - Log.w(TAG, "Can't get device pose at time: " + - mRgbTimestampGlThread); } - } - // If the model was updated then it must be re rendered. - if (mModelUpdated) { - mRenderer.updateModelRendering(mHouseModel, mOpenGlTHouse, mDestPointList); - mModelUpdated = false; + // If the model was updated then it must be re rendered. + if (mModelUpdated) { + mRenderer.updateModelRendering(mHouseModel, mOpenGlTHouse, + mDestPointList); + mModelUpdated = false; + } } + // Avoid crashing the application due to unhandled exceptions + } catch (TangoErrorException e) { + Log.e(TAG, "Tango API call error within the OpenGL render thread", e); + } catch (Throwable t) { + Log.e(TAG, "Exception on the OpenGL thread", t); } } @@ -348,6 +357,32 @@ public boolean callPreFrame() { }); } + /** + * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene. + */ + private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) { + // Uses frustumM to create a projection matrix taking into account calibrated camera + // intrinsic parameter. + // Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/ + float near = 0.1f; + float far = 100; + + float xScale = near / (float) intrinsics.fx; + float yScale = near / (float) intrinsics.fy; + float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale; + // Color camera's coordinates has y pointing downwards so we negate this term. + float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale; + + float m[] = new float[16]; + Matrix.frustumM(m, 0, + xScale * (float) -intrinsics.width / 2.0f - xOffset, + xScale * (float) intrinsics.width / 2.0f - xOffset, + yScale * (float) -intrinsics.height / 2.0f - yOffset, + yScale * (float) intrinsics.height / 2.0f - yOffset, + near, far); + return m; + } + /** * This method handles when the user clicks the add point button. It will try to find a point * using the point cloud and the TangoSupportLibrary in the aimed location with the crosshair. diff --git a/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceRenderer.java b/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceRenderer.java old mode 100755 new mode 100644 index f7621ed3..86f303b6 --- a/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceRenderer.java +++ b/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/ModelCorrespondenceRenderer.java @@ -15,7 +15,6 @@ */ package com.projecttango.examples.java.modelcorrespondence; -import com.google.atap.tangoservice.TangoCameraIntrinsics; import com.google.atap.tangoservice.TangoPoseData; import android.content.Context; @@ -25,10 +24,8 @@ import org.rajawali3d.Object3D; import org.rajawali3d.lights.DirectionalLight; -import org.rajawali3d.loader.ALoader; import org.rajawali3d.loader.LoaderSTL; import org.rajawali3d.loader.ParsingException; -import org.rajawali3d.loader.async.IAsyncLoaderCallback; import org.rajawali3d.materials.Material; import org.rajawali3d.materials.methods.DiffuseMethod; import org.rajawali3d.materials.methods.SpecularMethod; @@ -46,9 +43,6 @@ import javax.microedition.khronos.opengles.GL10; -import com.projecttango.rajawali.ScenePoseCalculator; -import com.projecttango.tangosupport.TangoSupport; - /** * Simple example augmented reality renderer which displays spheres fixed in place for every * point measurement and a 3D model of a house in the position given by the found correspondence. @@ -155,14 +149,11 @@ public boolean isSceneCameraConfigured() { } /** - * Sets the projection matrix for the scen camera to match the parameters of the color camera, + * Sets the projection matrix for the scene camera to match the parameters of the color camera, * provided by the {@code TangoCameraIntrinsics}. */ - public void setProjectionMatrix(TangoCameraIntrinsics intrinsics) { - Matrix4 projectionMatrix = ScenePoseCalculator.calculateProjectionMatrix( - intrinsics.width, intrinsics.height, - intrinsics.fx, intrinsics.fy, intrinsics.cx, intrinsics.cy); - getCurrentCamera().setProjectionMatrix(projectionMatrix); + public void setProjectionMatrix(float[] matrixFloats) { + getCurrentCamera().setProjectionMatrix(new Matrix4(matrixFloats)); } /** diff --git a/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/package-info.java b/java_model_correspondence_example/app/src/main/java/com/projecttango/examples/java/modelcorrespondence/package-info.java old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/crosshair.png b/java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/crosshair.png old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/plus.png b/java_model_correspondence_example/app/src/main/res/drawable-xxhdpi/plus.png old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/drawable/progress_bg.xml b/java_model_correspondence_example/app/src/main/res/drawable/progress_bg.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/layout/activity_main.xml b/java_model_correspondence_example/app/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/raw/farmhouse.stl b/java_model_correspondence_example/app/src/main/res/raw/farmhouse.stl old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/values-v11/styles.xml b/java_model_correspondence_example/app/src/main/res/values-v11/styles.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/values-v14/styles.xml b/java_model_correspondence_example/app/src/main/res/values-v14/styles.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/values-w820dp/dimens.xml b/java_model_correspondence_example/app/src/main/res/values-w820dp/dimens.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/values/colors.xml b/java_model_correspondence_example/app/src/main/res/values/colors.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/values/dimens.xml b/java_model_correspondence_example/app/src/main/res/values/dimens.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/values/strings.xml b/java_model_correspondence_example/app/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_model_correspondence_example/app/src/main/res/values/styles.xml b/java_model_correspondence_example/app/src/main/res/values/styles.xml old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/AndroidManifest.xml b/java_opengl_augmented_reality_example/opengl_ar/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityActivity.java b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityActivity.java old mode 100755 new mode 100644 index 9b4997eb..9ba07761 --- a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityActivity.java +++ b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityActivity.java @@ -182,9 +182,17 @@ private TangoConfig setupTangoConfig(Tango tango) { // low latency IMU integration. TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT); config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, true); + // NOTE: Low latency integration is necessary to achieve a precise alignment of // virtual objects with the RBG image and produce a good AR effect. config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true); + + // Drift correction allows motion tracking to recover after it loses tracking. + // + // The drift corrected pose is is available through the frame pair with + // base frame AREA_DESCRIPTION and target frame DEVICE. + config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true); + return config; } @@ -252,78 +260,104 @@ private void setupRenderer() { public void preRender() { // This is the work that you would do on your main OpenGL render thread. - // We need to be careful to not run any Tango-dependent code in the - // OpenGL thread unless we know the Tango service to be properly set-up - // and connected. - if (!mIsConnected) { - return; - } + try { + // Synchronize against concurrently disconnecting the service triggered + // from the UI thread. + synchronized (OpenGlAugmentedRealityActivity.this) { + // We need to be careful to not run any Tango-dependent code in the + // OpenGL thread unless we know the Tango service to be properly + // set-up and connected. + if (!mIsConnected) { + return; + } - // Synchronize against concurrently disconnecting the service triggered - // from the UI thread. - synchronized (OpenGlAugmentedRealityActivity.this) { - // Connect the Tango SDK to the OpenGL texture ID where we are - // going to render the camera. - // NOTE: This must be done after both the texture is generated - // and the Tango service is connected. - if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { - mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, - mRenderer.getTextureId()); - mConnectedTextureIdGlThread = mRenderer.getTextureId(); - Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); - mRenderer.setProjectionMatrix(mIntrinsics); - } - // If there is a new RGB camera frame available, update the texture and - // scene camera pose. - if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { - // {@code mRgbTimestampGlThread} contains the exact timestamp at - // which the rendered RGB frame was acquired. - mRgbTimestampGlThread = - mTango.updateTexture(TangoCameraIntrinsics. - TANGO_CAMERA_COLOR); - - // Get the transform from color camera to Start of Service - // at the timestamp of the RGB image in OpenGL coordinates. - TangoSupport.TangoMatrixTransformData transform = - TangoSupport.getMatrixTransformAtTime(mRgbTimestampGlThread, - TangoPoseData - .COORDINATE_FRAME_START_OF_SERVICE, - TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL); - if (transform.statusCode == TangoPoseData.POSE_VALID) { - - mRenderer.updateViewMatrix(transform.matrix); - double deltaTime = mRgbTimestampGlThread - - lastRenderedTimeStamp; - lastRenderedTimeStamp = mRgbTimestampGlThread; - - // Set the earth rotation around itself. - float[] openGlTEarth = new float[16]; - Matrix.rotateM(mEarthMoonCenterTEarth, 0, (float) - deltaTime * 360 / 10, 0, 1, 0); - Matrix.multiplyMM(openGlTEarth, 0, mOpenGLTEarthMoonCenter, - 0, mEarthMoonCenterTEarth, 0); - - // Set moon rotation around the earth and moon center. - float[] openGlTMoon = new float[16]; - Matrix.rotateM(mEarthMoonCenterTMoonRotation, 0, (float) - deltaTime * 360 / 50, 0, 1, 0); - float[] mEarthTMoon = new float[16]; - Matrix.multiplyMM(mEarthTMoon, 0, - mEarthMoonCenterTMoonRotation, 0, - mEarthMoonCenterTTranslation, 0); - Matrix.multiplyMM(openGlTMoon, 0, - mOpenGLTEarthMoonCenter, - 0, mEarthTMoon, 0); - - mRenderer.setEarthTransform(openGlTEarth); - mRenderer.setMoonTransform(openGlTMoon); - } else { - Log.w(TAG, "Could not get a valid transform at time " + - mRgbTimestampGlThread); + // Connect the Tango SDK to the OpenGL texture ID where we are + // going to render the camera. + // NOTE: This must be done after both the texture is generated + // and the Tango service is connected. + if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { + mTango.connectTextureId( + TangoCameraIntrinsics.TANGO_CAMERA_COLOR, + mRenderer.getTextureId()); + mConnectedTextureIdGlThread = mRenderer.getTextureId(); + Log.d(TAG, "connected to texture id: " + + mRenderer.getTextureId()); + + // Set-up scene camera projection to match RGB camera intrinsics + mRenderer.setProjectionMatrix( + projectionMatrixFromCameraIntrinsics(mIntrinsics)); + } + // If there is a new RGB camera frame available, update the texture + // and scene camera pose. + if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { + // {@code mRgbTimestampGlThread} contains the exact timestamp at + // which the rendered RGB frame was acquired. + mRgbTimestampGlThread = + mTango.updateTexture(TangoCameraIntrinsics. + TANGO_CAMERA_COLOR); + + // Get the transform from color camera to Start of Service + // at the timestamp of the RGB image in OpenGL coordinates. + // + // When drift correction mode is enabled in config file, we need + // to query the device with respect to Area Description pose in + // order to use the drift corrected pose. + // + // Note that if you don't want to use the drift corrected pose, + // the normal device with respect to start of service pose is + // still available. + TangoSupport.TangoMatrixTransformData transform = + TangoSupport.getMatrixTransformAtTime( + mRgbTimestampGlThread, + TangoPoseData + .COORDINATE_FRAME_AREA_DESCRIPTION, + TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL); + if (transform.statusCode == TangoPoseData.POSE_VALID) { + + mRenderer.updateViewMatrix(transform.matrix); + double deltaTime = mRgbTimestampGlThread + - lastRenderedTimeStamp; + lastRenderedTimeStamp = mRgbTimestampGlThread; + + // Set the earth rotation around itself. + float[] openGlTEarth = new float[16]; + Matrix.rotateM(mEarthMoonCenterTEarth, 0, (float) + deltaTime * 360 / 10, 0, 1, 0); + Matrix.multiplyMM(openGlTEarth, 0, mOpenGLTEarthMoonCenter, + 0, mEarthMoonCenterTEarth, 0); + + // Set moon rotation around the earth and moon center. + float[] openGlTMoon = new float[16]; + Matrix.rotateM(mEarthMoonCenterTMoonRotation, 0, (float) + deltaTime * 360 / 50, 0, 1, 0); + float[] mEarthTMoon = new float[16]; + Matrix.multiplyMM(mEarthTMoon, 0, + mEarthMoonCenterTMoonRotation, 0, + mEarthMoonCenterTTranslation, 0); + Matrix.multiplyMM(openGlTMoon, 0, + mOpenGLTEarthMoonCenter, + 0, mEarthTMoon, 0); + + mRenderer.setEarthTransform(openGlTEarth); + mRenderer.setMoonTransform(openGlTMoon); + } else { + // When the pose status is not valid, it indicates tracking + // has been lost. In this case, we simply stop rendering. + // + // This is also the place to display UI to suggest the user + // walk to recover tracking. + Log.w(TAG, "Could not get a valid transform at time " + + mRgbTimestampGlThread); + } } } + // Avoid crashing the application due to unhandled exceptions + } catch (TangoErrorException e) { + Log.e(TAG, "Tango API call error within the OpenGL render thread", e); + } catch (Throwable t) { + Log.e(TAG, "Exception on the OpenGL thread", t); } } }); @@ -338,4 +372,30 @@ public void preRender() { mSurfaceView.setRenderer(mRenderer); } + + /** + * Use Tango camera intrinsics to calculate the projection Matrix for the OpenGL scene. + */ + private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) { + // Uses frustumM to create a projection matrix taking into account calibrated camera + // intrinsic parameter. + // Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/ + float near = 0.1f; + float far = 100; + + float xScale = near / (float) intrinsics.fx; + float yScale = near / (float) intrinsics.fy; + float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale; + // Color camera's coordinates has y pointing downwards so we negate this term. + float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale; + + float m[] = new float[16]; + Matrix.frustumM(m, 0, + xScale * (float) -intrinsics.width / 2.0f - xOffset, + xScale * (float) intrinsics.width / 2.0f - xOffset, + yScale * (float) -intrinsics.height / 2.0f - yOffset, + yScale * (float) intrinsics.height / 2.0f - yOffset, + near, far); + return m; + } } diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityRenderer.java b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityRenderer.java old mode 100755 new mode 100644 index e65cacaf..e0fe7d56 --- a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityRenderer.java +++ b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlAugmentedRealityRenderer.java @@ -109,16 +109,12 @@ public int getTextureId() { } /** - * Create the Projection matrix matching the Tango RGB camera in order to be able to do + * Set the Projection matrix matching the Tango RGB camera in order to be able to do * Augmented Reality. */ - public void setProjectionMatrix(TangoCameraIntrinsics intrinsics) { - float[] projectionMatrix = new float[16]; - double vFov = 2 * Math.atan(intrinsics.height / (2 * intrinsics.fy)); - Matrix.perspectiveM(projectionMatrix, 0, (float) Math.toDegrees(vFov), (float) - intrinsics.width / intrinsics.height, 0.1f, 1000); - mEarthSphere.setProjectionMatrix(projectionMatrix); - mMoonSphere.setProjectionMatrix(projectionMatrix); + public void setProjectionMatrix(float[] matrixFloats) { + mEarthSphere.setProjectionMatrix(matrixFloats); + mMoonSphere.setProjectionMatrix(matrixFloats); } /** diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlCameraPreview.java b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlCameraPreview.java old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlHelper.java b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlHelper.java old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlMesh.java b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlMesh.java old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlSphere.java b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/OpenGlSphere.java old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/package-info.java b/java_opengl_augmented_reality_example/opengl_ar/src/main/java/com/projecttango/examples/java/openglar/package-info.java old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/earth.jpeg b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/earth.jpeg old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/moon.jpg b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/drawable-xxhdpi/moon.jpg old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/layout/activity_main.xml b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-v11/styles.xml b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-v11/styles.xml old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-v14/styles.xml b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-v14/styles.xml old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-w820dp/dimens.xml b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values-w820dp/dimens.xml old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values/strings.xml b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values/styles.xml b/java_opengl_augmented_reality_example/opengl_ar/src/main/res/values/styles.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/AndroidManifest.xml b/java_plane_fitting_example/app/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingActivity.java b/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingActivity.java old mode 100755 new mode 100644 index 8be9fa81..f57f634b --- a/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingActivity.java +++ b/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingActivity.java @@ -36,15 +36,12 @@ import android.view.View; import android.widget.Toast; -import org.rajawali3d.math.Matrix4; -import org.rajawali3d.math.vector.Vector3; import org.rajawali3d.scene.ASceneFrameCallback; import org.rajawali3d.surface.RajawaliSurfaceView; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; -import com.projecttango.rajawali.ScenePoseCalculator; import com.projecttango.tangosupport.TangoPointCloudManager; import com.projecttango.tangosupport.TangoSupport; import com.projecttango.tangosupport.TangoSupport.IntersectionPointPlaneModelPair; @@ -158,6 +155,13 @@ private void connectTango() { config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true); config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true); config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, true); + + // Drift correction allows motion tracking to recover after it loses tracking. + // + // The drift corrected pose is is available through the frame pair with + // base frame AREA_DESCRIPTION and target frame DEVICE. + config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true); + mTango.connect(config); // No need to add any coordinate frame pairs since we are not @@ -209,50 +213,71 @@ public void onPreFrame(long sceneTime, double deltaTime) { // onRender callbacks had a chance to run and before scene objects are rendered // into the scene. - synchronized (PlaneFittingActivity.this) { - // Don't execute any tango API actions if we're not connected to the service - if (!mIsConnected) { - return; - } + try { + synchronized (PlaneFittingActivity.this) { + // Don't execute any tango API actions if we're not connected to the service + if (!mIsConnected) { + return; + } - // Set-up scene camera projection to match RGB camera intrinsics - if (!mRenderer.isSceneCameraConfigured()) { - mRenderer.setProjectionMatrix(mIntrinsics); - } + // Set-up scene camera projection to match RGB camera intrinsics + if (!mRenderer.isSceneCameraConfigured()) { + mRenderer.setProjectionMatrix( + projectionMatrixFromCameraIntrinsics(mIntrinsics)); + } - // Connect the camera texture to the OpenGL Texture if necessary - // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the - // texture with a different ID. - if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { - mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, - mRenderer.getTextureId()); - mConnectedTextureIdGlThread = mRenderer.getTextureId(); - Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); - } + // Connect the camera texture to the OpenGL Texture if necessary + // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the + // texture with a different ID. + if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { + mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, + mRenderer.getTextureId()); + mConnectedTextureIdGlThread = mRenderer.getTextureId(); + Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); + } - // If there is a new RGB camera frame available, update the texture with it - if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { - mRgbTimestampGlThread = - mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); - } + // If there is a new RGB camera frame available, update the texture with it + if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { + mRgbTimestampGlThread = + mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); + } - if (mRgbTimestampGlThread > mCameraPoseTimestamp) { - // Calculate the camera color pose at the camera frame update time in - // OpenGL engine. - TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( - mRgbTimestampGlThread, - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, - TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); - if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { - // Update the camera pose from the renderer - mRenderer.updateRenderCameraPose(lastFramePose); - mCameraPoseTimestamp = lastFramePose.timestamp; - } else { - Log.w(TAG, "Can't get device pose at time: " + - mRgbTimestampGlThread); + if (mRgbTimestampGlThread > mCameraPoseTimestamp) { + // Calculate the camera color pose at the camera frame update time in + // OpenGL engine. + // + // When drift correction mode is enabled in config file, we need + // to query the device with respect to Area Description pose in + // order to use the drift corrected pose. + // + // Note that if you don't want to use the drift corrected pose, the + // normal device with respect to start of service pose is still + // available. + TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( + mRgbTimestampGlThread, + TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, + TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); + if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { + // Update the camera pose from the renderer + mRenderer.updateRenderCameraPose(lastFramePose); + mCameraPoseTimestamp = lastFramePose.timestamp; + } else { + // When the pose status is not valid, it indicates the tracking has + // been lost. In this case, we simply stop rendering. + // + // This is also the place to display UI to suggest the user walk + // to recover tracking. + Log.w(TAG, "Can't get device pose at time: " + + mRgbTimestampGlThread); + } } } + // Avoid crashing the application due to unhandled exceptions + } catch (TangoErrorException e) { + Log.e(TAG, "Tango API call error within the OpenGL render thread", e); + } catch (Throwable t) { + Log.e(TAG, "Exception on the OpenGL thread", t); } } @@ -273,6 +298,32 @@ public boolean callPreFrame() { }); } + /** + * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene. + */ + private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) { + // Uses frustumM to create a projection matrix taking into account calibrated camera + // intrinsic parameter. + // Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/ + float near = 0.1f; + float far = 100; + + float xScale = near / (float) intrinsics.fx; + float yScale = near / (float) intrinsics.fy; + float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale; + // Color camera's coordinates has y pointing downwards so we negate this term. + float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale; + + float m[] = new float[16]; + Matrix.frustumM(m, 0, + xScale * (float) -intrinsics.width / 2.0f - xOffset, + xScale * (float) intrinsics.width / 2.0f - xOffset, + yScale * (float) -intrinsics.height / 2.0f - yOffset, + yScale * (float) intrinsics.height / 2.0f - yOffset, + near, far); + return m; + } + @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP) { @@ -337,7 +388,7 @@ private float[] doFitPlane(float u, float v, double rgbTimestamp) { // Get the transform from depth camera to OpenGL world at the timestamp of the cloud. TangoSupport.TangoMatrixTransformData transform = TangoSupport.getMatrixTransformAtTime(xyzIj.timestamp, - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, + TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH, TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, TangoSupport.TANGO_SUPPORT_ENGINE_TANGO); diff --git a/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingRenderer.java b/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingRenderer.java old mode 100755 new mode 100644 index d51005ed..d66b6438 --- a/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingRenderer.java +++ b/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/PlaneFittingRenderer.java @@ -39,10 +39,6 @@ import javax.microedition.khronos.opengles.GL10; -import com.projecttango.rajawali.DeviceExtrinsics; -import com.projecttango.rajawali.Pose; -import com.projecttango.rajawali.ScenePoseCalculator; - /** * Very simple example augmented reality renderer which displays a cube fixed in place. * The position of the cube in the OpenGL world is updated using the {@code updateObjectPose} @@ -181,14 +177,11 @@ public boolean isSceneCameraConfigured() { } /** - * Sets the projection matrix for the scen camera to match the parameters of the color camera, + * Sets the projection matrix for the scene camera to match the parameters of the color camera, * provided by the {@code TangoCameraIntrinsics}. */ - public void setProjectionMatrix(TangoCameraIntrinsics intrinsics) { - Matrix4 projectionMatrix = ScenePoseCalculator.calculateProjectionMatrix( - intrinsics.width, intrinsics.height, - intrinsics.fx, intrinsics.fy, intrinsics.cx, intrinsics.cy); - getCurrentCamera().setProjectionMatrix(projectionMatrix); + public void setProjectionMatrix(float[] matrix) { + getCurrentCamera().setProjectionMatrix(new Matrix4(matrix)); } @Override diff --git a/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/package-info.java b/java_plane_fitting_example/app/src/main/java/com/projecttango/examples/java/planefitting/package-info.java old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_plane_fitting_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/drawable-xxhdpi/instructions.png b/java_plane_fitting_example/app/src/main/res/drawable-xxhdpi/instructions.png old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/layout/activity_main.xml b/java_plane_fitting_example/app/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/values-v11/styles.xml b/java_plane_fitting_example/app/src/main/res/values-v11/styles.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/values-v14/styles.xml b/java_plane_fitting_example/app/src/main/res/values-v14/styles.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/values-w820dp/dimens.xml b/java_plane_fitting_example/app/src/main/res/values-w820dp/dimens.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/values/dimens.xml b/java_plane_fitting_example/app/src/main/res/values/dimens.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/values/strings.xml b/java_plane_fitting_example/app/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_plane_fitting_example/app/src/main/res/values/styles.xml b/java_plane_fitting_example/app/src/main/res/values/styles.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/AndroidManifest.xml b/java_point_to_point_example/app/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointActivity.java b/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointActivity.java old mode 100755 new mode 100644 index 58aa5fb0..ce534f3e --- a/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointActivity.java +++ b/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointActivity.java @@ -46,8 +46,6 @@ import java.util.Stack; import java.util.concurrent.atomic.AtomicBoolean; -import com.projecttango.rajawali.DeviceExtrinsics; -import com.projecttango.rajawali.ScenePoseCalculator; import com.projecttango.tangosupport.TangoPointCloudManager; import com.projecttango.tangosupport.TangoSupport; @@ -72,9 +70,6 @@ public class PointToPointActivity extends Activity implements View.OnTouchListen // This is the rate at which we query for distance data. private static final int UPDATE_UI_INTERVAL_MS = 100; - public static final TangoCoordinateFramePair FRAME_PAIR = new TangoCoordinateFramePair( - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, - TangoPoseData.COORDINATE_FRAME_DEVICE); private static final int INVALID_TEXTURE_ID = 0; private RajawaliSurfaceView mSurfaceView; @@ -181,6 +176,13 @@ private void connectTango() { TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true); config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true); config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, true); + + // Drift correction allows motion tracking to recover after it loses tracking. + // + // The drift corrected pose is is available through the frame pair with + // base frame AREA_DESCRIPTION and target frame DEVICE. + config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true); + mTango.connect(config); // No need to add any coordinate frame pairs since we are not @@ -233,53 +235,74 @@ public void onPreFrame(long sceneTime, double deltaTime) { // onRender callbacks had a chance to run and before scene objects are rendered // into the scene. - // Prevent concurrent access to {@code mIsFrameAvailableTangoThread} from the Tango - // callback thread and service disconnection from an onPause event. - synchronized (PointToPointActivity.this) { - // Don't execute any tango API actions if we're not connected to the service - if (!mIsConnected) { - return; - } + try { + // Prevent concurrent access to {@code mIsFrameAvailableTangoThread} from the + // Tango callback thread and service disconnection from an onPause event. + synchronized (PointToPointActivity.this) { + // Don't execute any tango API actions if we're not connected to the service + if (!mIsConnected) { + return; + } - // Set-up scene camera projection to match RGB camera intrinsics - if (!mRenderer.isSceneCameraConfigured()) { - mRenderer.setProjectionMatrix(mIntrinsics); - } + // Set-up scene camera projection to match RGB camera intrinsics + if (!mRenderer.isSceneCameraConfigured()) { + mRenderer.setProjectionMatrix( + projectionMatrixFromCameraIntrinsics(mIntrinsics)); + } - // Connect the camera texture to the OpenGL Texture if necessary - // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the - // texture with a different ID. - if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { - mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, - mRenderer.getTextureId()); - mConnectedTextureIdGlThread = mRenderer.getTextureId(); - Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); - } + // Connect the camera texture to the OpenGL Texture if necessary + // NOTE: When the OpenGL context is recycled, Rajawali may re-generate the + // texture with a different ID. + if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) { + mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, + mRenderer.getTextureId()); + mConnectedTextureIdGlThread = mRenderer.getTextureId(); + Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId()); + } - // If there is a new RGB camera frame available, update the texture with it - if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { - mRgbTimestampGlThread = - mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); - } + // If there is a new RGB camera frame available, update the texture with it + if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) { + mRgbTimestampGlThread = + mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR); + } - // If a new RGB frame has been rendered, update the camera pose to match. - if (mRgbTimestampGlThread > mCameraPoseTimestamp) { - // Calculate the camera color pose at the camera frame update time in - // OpenGL engine. - TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( - mRgbTimestampGlThread, - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, - TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, - TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); - if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { - // Update the camera pose from the renderer - mRenderer.updateRenderCameraPose(lastFramePose); - mCameraPoseTimestamp = lastFramePose.timestamp; - } else { - Log.w(TAG, "Can't get device pose at time: " + - mRgbTimestampGlThread); + // If a new RGB frame has been rendered, update the camera pose to match. + if (mRgbTimestampGlThread > mCameraPoseTimestamp) { + // Calculate the camera color pose at the camera frame update time in + // OpenGL engine. + // + // When drift correction mode is enabled in config file, we need + // to query the device with respect to Area Description pose in + // order to use the drift corrected pose. + // + // Note that if you don't want to use the drift corrected pose, the + // normal device with respect to start of service pose is still + // available. + TangoPoseData lastFramePose = TangoSupport.getPoseAtTime( + mRgbTimestampGlThread, + TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, + TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, + TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, 0); + if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) { + // Update the camera pose from the renderer + mRenderer.updateRenderCameraPose(lastFramePose); + mCameraPoseTimestamp = lastFramePose.timestamp; + } else { + // When the pose status is not valid, it indicates the tracking has + // been lost. In this case, we simply stop rendering. + // + // This is also the place to display UI to suggest the user walk + // to recover tracking. + Log.w(TAG, "Can't get device pose at time: " + + mRgbTimestampGlThread); + } } } + // Avoid crashing the application due to unhandled exceptions + } catch (TangoErrorException e) { + Log.e(TAG, "Tango API call error within the OpenGL render thread", e); + } catch (Throwable t) { + Log.e(TAG, "Exception on the OpenGL thread", t); } } @@ -300,6 +323,32 @@ public boolean callPreFrame() { }); } + /** + * Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene. + */ + private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) { + // Uses frustumM to create a projection matrix taking into account calibrated camera + // intrinsic parameter. + // Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/ + float near = 0.1f; + float far = 100; + + float xScale = near / (float) intrinsics.fx; + float yScale = near / (float) intrinsics.fy; + float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale; + // Color camera's coordinates has y pointing downwards so we negate this term. + float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale; + + float m[] = new float[16]; + Matrix.frustumM(m, 0, + xScale * (float) -intrinsics.width / 2.0f - xOffset, + xScale * (float) intrinsics.width / 2.0f - xOffset, + yScale * (float) -intrinsics.height / 2.0f - yOffset, + yScale * (float) intrinsics.height / 2.0f - yOffset, + near, far); + return m; + } + @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP) { @@ -366,7 +415,7 @@ private float[] getDepthAtTouchPosition(float u, float v, double rgbTimestamp) { // Get the transform from depth camera to OpenGL world at the timestamp of the cloud. TangoSupport.TangoMatrixTransformData transform = TangoSupport.getMatrixTransformAtTime(xyzIj.timestamp, - TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, + TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH, TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL, TangoSupport.TANGO_SUPPORT_ENGINE_TANGO); diff --git a/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointRenderer.java b/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointRenderer.java old mode 100755 new mode 100644 index c4078b83..005d0501 --- a/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointRenderer.java +++ b/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/PointToPointRenderer.java @@ -39,10 +39,6 @@ import javax.microedition.khronos.opengles.GL10; -import com.projecttango.rajawali.DeviceExtrinsics; -import com.projecttango.rajawali.Pose; -import com.projecttango.rajawali.ScenePoseCalculator; - /** * Very simple example point to point renderer which displays a line fixed in place. * Whenever the user clicks on the screen, the line is re-rendered with an endpoint @@ -165,11 +161,8 @@ public boolean isSceneCameraConfigured() { * Sets the projection matrix for the scen camera to match the parameters of the color camera, * provided by the {@code TangoCameraIntrinsics}. */ - public void setProjectionMatrix(TangoCameraIntrinsics intrinsics) { - Matrix4 projectionMatrix = ScenePoseCalculator.calculateProjectionMatrix( - intrinsics.width, intrinsics.height, - intrinsics.fx, intrinsics.fy, intrinsics.cx, intrinsics.cy); - getCurrentCamera().setProjectionMatrix(projectionMatrix); + public void setProjectionMatrix(float[] matrixFloats) { + getCurrentCamera().setProjectionMatrix(new Matrix4(matrixFloats)); } @Override diff --git a/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/package-info.java b/java_point_to_point_example/app/src/main/java/com/projecttango/examples/java/pointtopoint/package-info.java old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_point_to_point_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/layout/activity_main.xml b/java_point_to_point_example/app/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/values-v11/styles.xml b/java_point_to_point_example/app/src/main/res/values-v11/styles.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/values-v14/styles.xml b/java_point_to_point_example/app/src/main/res/values-v14/styles.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/values-w820dp/dimens.xml b/java_point_to_point_example/app/src/main/res/values-w820dp/dimens.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/values/dimens.xml b/java_point_to_point_example/app/src/main/res/values/dimens.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/values/strings.xml b/java_point_to_point_example/app/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_point_to_point_example/app/src/main/res/values/styles.xml b/java_point_to_point_example/app/src/main/res/values/styles.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/AndroidManifest.xml b/java_video_overlay_example/app/src/main/AndroidManifest.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/java/com/projecttango/examples/java/videooverlay/MainActivity.java b/java_video_overlay_example/app/src/main/java/com/projecttango/examples/java/videooverlay/MainActivity.java old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/java/com/projecttango/examples/java/videooverlay/package-info.java b/java_video_overlay_example/app/src/main/java/com/projecttango/examples/java/videooverlay/package-info.java old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/drawable-hdpi/ic_launcher.png b/java_video_overlay_example/app/src/main/res/drawable-hdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/drawable-mdpi/ic_launcher.png b/java_video_overlay_example/app/src/main/res/drawable-mdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/drawable-xhdpi/ic_launcher.png b/java_video_overlay_example/app/src/main/res/drawable-xhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/java_video_overlay_example/app/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/layout/activity_main.xml b/java_video_overlay_example/app/src/main/res/layout/activity_main.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/values-v11/styles.xml b/java_video_overlay_example/app/src/main/res/values-v11/styles.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/values-v14/styles.xml b/java_video_overlay_example/app/src/main/res/values-v14/styles.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/values-w820dp/dimens.xml b/java_video_overlay_example/app/src/main/res/values-w820dp/dimens.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/values/dimens.xml b/java_video_overlay_example/app/src/main/res/values/dimens.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/values/strings.xml b/java_video_overlay_example/app/src/main/res/values/strings.xml old mode 100755 new mode 100644 diff --git a/java_video_overlay_example/app/src/main/res/values/styles.xml b/java_video_overlay_example/app/src/main/res/values/styles.xml old mode 100755 new mode 100644