diff --git a/augmented-reality-jni-example/app/src/main/jni/scene.cc b/augmented-reality-jni-example/app/src/main/jni/scene.cc index e58987a9..e677175d 100644 --- a/augmented-reality-jni-example/app/src/main/jni/scene.cc +++ b/augmented-reality-jni-example/app/src/main/jni/scene.cc @@ -119,7 +119,8 @@ void Scene::Render(const glm::mat4& cur_pose_transformation) { gesture_camera_->SetAnchorPosition(position); frustum_->SetTransformationMatrix(cur_pose_transformation); - + // Set the frustum scale to 4:3, this doesn't necessarily match the physical + // camera's aspect ratio, this is just for visualization purposes. frustum_->SetScale( glm::vec3(1.0f, camera_image_plane_ratio_, image_plane_distance_)); frustum_->Render(ar_camera_projection_matrix_, diff --git a/point-cloud-jni-example/app/src/main/jni/point_cloud_drawable.cc b/point-cloud-jni-example/app/src/main/jni/point_cloud_drawable.cc index eb433be5..be9f17eb 100644 --- a/point-cloud-jni-example/app/src/main/jni/point_cloud_drawable.cc +++ b/point-cloud-jni-example/app/src/main/jni/point_cloud_drawable.cc @@ -72,7 +72,7 @@ void PointCloudDrawable::Render(glm::mat4 projection_mat, glm::mat4 view_mat, glVertexAttribPointer(vertices_handle_, 3, GL_FLOAT, GL_FALSE, 0, nullptr); glBindBuffer(GL_ARRAY_BUFFER, 0); - glDrawArrays(GL_POINTS, 0, vertices.size()); + glDrawArrays(GL_POINTS, 0, vertices.size() / 3); glUseProgram(0); tango_gl::util::CheckGlError("Pointcloud::Render"); diff --git a/rgb-depth-sync-example/app/src/main/jni/Application.mk b/rgb-depth-sync-example/app/src/main/jni/Application.mk index 6344573a..a1b73431 100644 --- a/rgb-depth-sync-example/app/src/main/jni/Application.mk +++ b/rgb-depth-sync-example/app/src/main/jni/Application.mk @@ -16,4 +16,4 @@ APP_ABI := armeabi-v7a APP_STL := gnustl_static -APP_PLATFORM := android-19 \ No newline at end of file +APP_PLATFORM := android-19 diff --git a/tango-gl/camera.cpp b/tango-gl/camera.cpp index 9e6beddb..8a656700 100644 --- a/tango-gl/camera.cpp +++ b/tango-gl/camera.cpp @@ -46,4 +46,22 @@ void Camera::SetFieldOfView(float fov) { Camera::~Camera() { } +glm::mat4 Camera::ProjectionMatrixForCameraIntrinsics(float width, float height, + float fx, float fy, + float cx, float cy, + float near, float far) { + const float xscale = near / fx; + const float yscale = near / fy; + + const float xoffset = (cx - (width / 2.0)) * xscale; + // OpenGL coordinates has y pointing downwards so we negate this term. + const float yoffset = -(cy - (height / 2.0)) * yscale; + + return glm::frustum(xscale * -width / 2.0f - xoffset, + xscale * width / 2.0f - xoffset, + yscale * -height / 2.0f - yoffset, + yscale * height / 2.0f - yoffset, + near, far); +} + } // namespace tango_gl diff --git a/tango-gl/include/tango-gl/camera.h b/tango-gl/include/tango-gl/camera.h index d52faf52..86bf5f9a 100644 --- a/tango-gl/include/tango-gl/camera.h +++ b/tango-gl/include/tango-gl/camera.h @@ -32,6 +32,23 @@ class Camera : public Transform { glm::mat4 GetViewMatrix(); glm::mat4 GetProjectionMatrix(); + + /** + * Create an OpenGL perspective matrix from window size, camera intrinsics, and clip settings. + * + * @param width - The width of the camera image. + * @param height - The height of the camera image. + * @param fx - The x-axis focal length of the camera. + * @param fy - The y-axis focal length of the camera. + * @param cx - The x-coordinate principal point in pixels. + * @param cy - The y-coordinate principal point in pixels. + * @param near - The desired near z-clipping plane. + * @param far - The desired far z-clipping plane. + */ + static glm::mat4 ProjectionMatrixForCameraIntrinsics(float width, float height, + float fx, float fy, + float cx, float cy, + float near, float far); private: float field_of_view_; float aspect_ratio_; diff --git a/tango-gl/shaders.cpp b/tango-gl/shaders.cpp index b47aed63..b24991bc 100644 --- a/tango-gl/shaders.cpp +++ b/tango-gl/shaders.cpp @@ -18,7 +18,9 @@ namespace tango_gl { namespace shaders { std::string GetBasicVertexShader() { - return "attribute vec4 vertex;\n" + return "precision mediump float;\n" + "precision mediump int;\n" + "attribute vec4 vertex;\n" "uniform mat4 mvp;\n" "uniform vec4 color;\n" "varying vec4 v_color;\n" @@ -37,7 +39,9 @@ std::string GetBasicFragmentShader() { } std::string GetColorVertexShader() { - return "attribute vec4 vertex;\n" + return "precision mediump float;\n" + "precision mediump int;\n" + "attribute vec4 vertex;\n" "attribute vec4 color;\n" "uniform mat4 mvp;\n" "varying vec4 v_color;\n" diff --git a/tango_client_api/include/tango_client_api.h b/tango_client_api/include/tango_client_api.h index cf7b729f..3402943b 100644 --- a/tango_client_api/include/tango_client_api.h +++ b/tango_client_api/include/tango_client_api.h @@ -241,7 +241,7 @@ typedef struct TangoImageBuffer { int64_t frame_number; /// Pixel format of data. TangoImageFormatType format; - /// Pixels in RGBA8888 format. + /// Pixels in the format of this image buffer. uint8_t* data; } TangoImageBuffer; @@ -1318,6 +1318,20 @@ TangoErrorType TangoService_Experimental_freeTrajectory( TangoErrorType TangoService_Experimental_loadAreaDescription( const TangoUUID uuid); +/// Experimental API only, subject to change. +/// Loads an area description with the specified file path. This allows an +/// application to load an ADF for relocalization after connecting to the +/// service. It should only be called after calling TangoService_connect(), and +/// then only if the connect configuration did not specify an ADF to load, and +/// did not enable learning mode. +/// @param file_path The file path for the ADF to load. +/// @return Returns TANGO_SUCCESS if the ADF is successfully loaded for +/// relocalization. Returns TANGO_INVALID if the file path is invalid, or an ADF +/// is already being learned. Returns TANGO_ERROR if communication fails or if +/// the service needs to be initialized. +TangoErrorType TangoService_Experimental_loadAreaDescriptionFromFile( + const char* file_path); + #ifdef __cplusplus } #endif diff --git a/tango_client_api/lib/libtango_client_api.so b/tango_client_api/lib/libtango_client_api.so index 03b8b0c4..e8c0ef2d 100755 Binary files a/tango_client_api/lib/libtango_client_api.so and b/tango_client_api/lib/libtango_client_api.so differ