From 4cb6520bd0f0b65b29b02d8fa95afea689ae592b Mon Sep 17 00:00:00 2001 From: ziadb Date: Wed, 11 Jul 2018 10:16:49 -0400 Subject: SkArCamera* files Bug: skia: Change-Id: I711143c53bf66ebc8130b2401738da3cde644fbe Reviewed-on: https://skia-review.googlesource.com/140560 Reviewed-by: Robert Phillips Commit-Queue: Robert Phillips --- platform_tools/android/apps/arcore/CMakeLists.txt | 4 +- .../apps/arcore/src/main/cpp/SkArCamera.cpp | 38 ++++++++++++ .../android/apps/arcore/src/main/cpp/SkArCamera.h | 68 ++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.cpp create mode 100644 platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.h (limited to 'platform_tools') diff --git a/platform_tools/android/apps/arcore/CMakeLists.txt b/platform_tools/android/apps/arcore/CMakeLists.txt index 92c5968c95..6bfe1b7bef 100644 --- a/platform_tools/android/apps/arcore/CMakeLists.txt +++ b/platform_tools/android/apps/arcore/CMakeLists.txt @@ -33,7 +33,9 @@ add_library(hello_ar_native SHARED "src/main/cpp/point_cloud_renderer.cc" "src/main/cpp/util.cc" "src/main/cpp/pending_anchor.cc" - "src/main/cpp/anchor_wrapper.cc") + "src/main/cpp/anchor_wrapper.cc" + + "src/main/cpp/SkArCamera.cpp") target_include_directories(hello_ar_native PRIVATE #BASIC AR NATIVE CODE diff --git a/platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.cpp b/platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.cpp new file mode 100644 index 0000000000..f27aebbffa --- /dev/null +++ b/platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.cpp @@ -0,0 +1,38 @@ +/* + * Copyright 2018 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include +#include "SkArCamera.h" +#include "SkArUtil.h" + +std::unique_ptr SkArCamera::Make(SkArSession* session, SkArFrame* frame) { + return std::unique_ptr(new SkArCamera(session, frame)); +} + +SkArCamera::~SkArCamera() { + ArCamera_release(fArCamera); +} + +SkArCamera::SkArCamera(SkArSession* session, SkArFrame* frame) : fArCamera(nullptr) { + ArFrame_acquireCamera(session->getArSession(), frame->getArFrame(), &fArCamera); +} + +void SkArCamera::getViewMatrix(const SkArSession* session, float outColMajor[16]) { + ArCamera_getViewMatrix(session->getArSession(), fArCamera, outColMajor); +} + +void SkArCamera::getProjectionMatrix(const SkArSession* session, float nearClip, + float farClip, float outColMajor[16]) { + ArCamera_getProjectionMatrix(session->getArSession(), fArCamera, nearClip, farClip, + outColMajor); +} + +SkArTrackingState SkArCamera::getTrackingState(const SkArSession* session) { + ArTrackingState arTrackingState; + ArCamera_getTrackingState(session->getArSession(), fArCamera, &arTrackingState); + return SkArUtil::MakeSkArTrackingState(arTrackingState); +} diff --git a/platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.h b/platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.h new file mode 100644 index 0000000000..0cf8f3c449 --- /dev/null +++ b/platform_tools/android/apps/arcore/src/main/cpp/SkArCamera.h @@ -0,0 +1,68 @@ +/* + * Copyright 2018 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkArCamera_DEFINED +#define SkArCamera_DEFINED + +#include +#include "SkArTrackingState.h" + +class ArCamera; +class SkArFrame; +class SkArSession; + +/** + * Provides information about the camera that is used to capture images. Such information + * includes projection matrices, pose of camera... + */ + +class SkArCamera { + +public: + /** + * Factory method used to construct an SkArCamera from the current frame, using the current + * session + * @param session raw pointer to the current SkArSession + * @param frame raw pointer to the current SkArFrame + * @return unique pointer to an SkArCamera. Never nullptr + */ + static std::unique_ptr Make(SkArSession* session, SkArFrame* frame); + + ~SkArCamera(); + + /** + * Fills outColMajor with the values of the camera's current View matrix in column-major order + * @param session current SkArSession + * @param outColMajor 16-float array that will contain the View matrix content + */ + void getViewMatrix(const SkArSession* session, float outColMajor[16]); + + /** + * Fills outColMajor with the values of the camera's current Projection matrix in + * column-major order + * @param session current SkArSession + * @param nearClip wanted near clip value for the camera + * @param farClip wanted far clip value for the camera + * @param outColMajor 16-float array that will contain the Projection matrix content + */ + void getProjectionMatrix(const SkArSession* session, float nearClip, float farClip, + float outColMajor[16]); + + /** + * Used to check the current SkArTrackingState of the camera + * @param session current SkArSession + * @return tracking state of the SkArCamera described by the SkArTrackingState enum + */ + SkArTrackingState getTrackingState(const SkArSession* session); + +private: + SkArCamera(SkArSession* session, SkArFrame* frame); + + // This is a raw pointer. Its lifetime matches that of this class (SkArCamera) + ArCamera* fArCamera; +}; +#endif // SkArCamera_DEFINED -- cgit v1.2.3