diff --git a/.img/demo.gif b/.img/demo.gif new file mode 100644 index 0000000..021742c Binary files /dev/null and b/.img/demo.gif differ diff --git a/.img/demo.webp b/.img/demo.webp new file mode 100644 index 0000000..4ae347b Binary files /dev/null and b/.img/demo.webp differ diff --git a/.img/dl.png b/.img/dl.png new file mode 100644 index 0000000..c77b746 Binary files /dev/null and b/.img/dl.png differ diff --git a/README.md b/README.md index 96e7886..0351d83 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,220 @@ + + + + # ofxARCore -Experimental addon for openFrameworks to use [ARCore](https://developers.google.com/ar) on Android devices. +Experimental addon for openFrameworks to use [ARCore](https://developers.google.com/ar) on Android devices. + +
+ + +
+ -![preview](preview.gif) -## About -This openFrameworks addon implements some of the basic features from the ARCore API to be used in openFrameworks. This addon is not feature complete yet. Currently it only supports the basic camera tracking, rendering the camera image, besides basic anchor support. Even though its not feature complete, it should give a good starting point to work with AR in openFrameworks. + +## About +This addon is based on the work of [HalfdanJ](https://github.com/HalfdanJ/). This is not an official Google product. ## Developer guide -To use the addon, you need the development branch of openFrameworks from [github](http://github.com/openFrameworks/openFrameworks). Follow the [Android Studio guide](https://github.com/openframeworks/openFrameworks/blob/master/docs/android_studio.md) to learn how to get started with openFrameworks and Android. +To use the addon, you need the development branch of openFrameworks from [github](http://github.com/openFrameworks/openFrameworks). Follow the [Android Studio guide](https://github.com/openframeworks/openFrameworks/blob/master/docs/android_studio.md) to learn how to get started with openFrameworks and Android. To add the addon, add `ofxARCore` to `addons.make` in your project, or through the project generator. Additionally you will need to add the following two lines to the end of `settings.gradle` of your project: -To see basic usage of the addon, see the [example code](exampleBasic/src/ofApp.cpp) +## What is implemented + +### Anchor + +```h +// ofApp.h + +ofxARCore arcore; +vector anchors; +``` + +```cpp +// ofApp.cpp + +void ofApp::setup() { + arcore.setup(); +} + +void ofApp::update() { + anchors.push_back(arcore.getViewMatrix().getInverse()); +} + +void RafalleApp::draw() { + + for (int i = 0; i < anchors.size(); i++) { + + ofMatrix4x4 anchor = anchors[i]; + ofPushMatrix(); + ofMultMatrix(anchor); + + ofDrawBox(ofVec3f(0,0,0), 0.05); // Draws a 5cm box at anchor location + + ofPopMatrix(); + } + + + ofDisableDepthTest(); + +} + + +``` + +### Point Cloud + +```h +// ofApp.h + +vector point_cloud; +ofVbo vbo_pointcloud; +``` + +```cpp +// ofApp.cpp + +void ofApp::setup() { + for(int i = 0; i < point_cloud.size(); i++) { + point_color.push_back(ofColor::red); + } + vbo_pointcloud.setVertexData(&point_cloud[0], 3, 1000, GL_DYNAMIC_DRAW); + vbo_pointcloud.setColorData(&point_color[0], 1000, GL_DYNAMIC_DRAW); + point_color.clear(); +} + +void ofApp::update() { + point_cloud = arcore->getPointCloud(); + if (point_cloud.size() > 1) { + for (int i = 0; i < point_cloud.size(); i++) + point_color.push_back(ofColor::red); + + vbo_pointcloud.updateVertexData(&point_cloud[0], (int) point_cloud.size() * 2); + vbo_pointcloud.updateColorData(&point_color[0], (int) point_color.size() * 2); + } + + for (int i = 0; i < point_cloud.size(); i+=3) { + ofVec3f pos(point_cloud[i], point_cloud[i+1], point_cloud[i+2]); + points.push_back(pos); + } +} + +for (int i = 0; i < points.size(); i+=3) { + ofDrawBox(points[i], 0.01); // Draws a 1cm box at each point of point cloud +} + +``` + +### Augmented Images +```cpp +// ofApp.cpp + +void ofApp::draw() { + + vector augmented_images = arcore->getImageMatrices(); + + // draw a box above each detected image + for (int i = 0; i < augmented_images.size(); i++) { + + if (augmented_images[i]->is_tracking == true) { + + // get AugmentedImage position + ofMatrix4x4 anchor = augmented_images[i]->matrix; + ofPushMatrix(); + // translate to AugmentedImage position + ofMultMatrix(anchor); + + ofBoxPrimitive box; + + // set box dimentions according to arcore image width estimation + box.set(augmented_images[i]->width, 0.01, augmented_images[i]->height); + box.setPosition(0,0,0); + + // draw box above the image + box.draw(); + + + ofPopMatrix(); + } + } + +} +``` + +### Hit testing + +```cpp + +void ofApp::touchDown(int x, int y, int id) { + + ofHitPose *hitPose = arcore->getHitPose(x, y); + + if (pose != NULL) { + ofMatrix4x4 pose = hitPose->pose; + float distance = hitPose->distance; + + // translate to the hit location + ofPushMatrix(); + ofMultMatrix(pose); + + // draw a box at the hit location + ofDrawBox(0,0,0, 0.1); + + } + +} +``` + + +### Planes + +```cpp + +void ofApp::draw() { + + vector planes = arcore->getPlanes(); + + // for each plane + for (int i = 0; i < planes.size(); i++) { + + // translate to it's center + ofARPlane *plane= planes[i]; + ofPushMatrix(); + ofMultMatrix(plane->center); + + // draw a red box on it's center + ofSetColor(255,0,0,100); + ofDrawBox(0,0.025,0, 0.2, 0.05, 0.1); + + // draw the plane + ofSetColor(0,255,0,100); + plane->mesh.draw(); -## Examples -### [Basic example](exampleBasic/) -Shows how to use the addon in the most basic way, just rendering a grid centered around origin. + // draw the path (contours) + ofSetColor(0,0,255,100); + plane->path.draw(); -### [Drawing example](exampleDrawing/) -A simple demo that lets you draw in the air. + ofPopMatrix(); + } +``` -The app calculates the world coordinates from touch events on the screen, and draws a continuous white line through the air. Read more on [AR Experiments site](https://experiments.withgoogle.com/ar). -There is also a never version ported to Java available here: [github.com/googlecreativelab/ar-drawing-java](https://github.com/googlecreativelab/ar-drawing-java) +### Utils +#### Camera FOV +```cpp +// ofApp.cpp +arcore.getCameraFOV(); +``` +#### Screen DPI +```cpp +// ofApp.cpp +arcore.getDpi(); +``` diff --git a/exampleBasic/.gitignore b/exampleBasic/.gitignore deleted file mode 100644 index 06f74e3..0000000 --- a/exampleBasic/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -### Android ### -# Built application files -*.apk -*.ap_ - -# Files for the Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -### Android Patch ### -gen-external-apklibs -reports -obj -assets diff --git a/exampleBasic/AndroidManifest.xml b/exampleBasic/AndroidManifest.xml deleted file mode 100644 index 57a3b06..0000000 --- a/exampleBasic/AndroidManifest.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/exampleBasic/addons.make b/exampleBasic/addons.make deleted file mode 100644 index fc857cc..0000000 --- a/exampleBasic/addons.make +++ /dev/null @@ -1 +0,0 @@ -ofxARCore \ No newline at end of file diff --git a/exampleBasic/build.gradle b/exampleBasic/build.gradle deleted file mode 100644 index b39cefa..0000000 --- a/exampleBasic/build.gradle +++ /dev/null @@ -1,145 +0,0 @@ -def ofRoot(){ return '../../../' } - -// Load common functions -apply from: ofRoot()+"libs/openFrameworksCompiled/project/android/common-functions.gradle" - -buildscript { - apply from: "../../../libs/openFrameworksCompiled/project/android/ndk-verify.gradle" - - repositories { - jcenter() - } - dependencies { - // Using the gradle-experimental version that supports c++ - classpath 'com.android.tools.build:gradle-experimental:0.9.3' - } -} - -allprojects { - repositories { - jcenter() - maven { - url 'https://dl.google.com/dl/android/maven2/' - } - } -} - -apply plugin: 'com.android.model.application' - -model { - android { - // openFrameworks currently only supports compiling against SDK 19 - compileSdkVersion = 25 - buildToolsVersion = "25.0.3" - - defaultConfig.with { - minSdkVersion.apiLevel = 25 - targetSdkVersion.apiLevel = 25 - versionCode = 1 - versionName = "1.0" - } - } - - android.packagingOptions{ - doNotStrip "*/*/*.so" - } - - android.ndk { - moduleName = ofAppModuleName() - toolchain = buildToolchain() - stl = compilerStl() - } - - android.sources { - main { - jni { - source { - srcDirs= appSrcDirs(ofRoot()) - - includes = srcIncludes(ofRoot()) - excludes = srcExcludes(ofRoot()) - } - - // Link to openFrameworks - dependencies { - project ":openFrameworksProject" linkage "static" - } - } - - manifest { - source { - srcDirs = [ "." ] - } - } - res { - source { - srcDirs = [ "res" ] - } - } - java { - source { - srcDirs = [ "srcJava" ] - } - } - aidl { - source{ - srcDirs = ['srcJava'] - } - } - renderscript{ - source{ - srcDirs = ['srcJava'] - } - } - jniLibs { - source { - srcDirs = ['libs'] - } - } - assets { - source { - srcDirs = ['bin/data'] + addonData(ofRoot()) - } - } - } - } - - android.lintOptions { - abortOnError = false - } - - android.buildTypes { - release { - minifyEnabled = false - } - } - - // Setup the different types of flavors (arm / x86), - // and add linker flags based on that - android.productFlavors { - getAbis().each { abi -> - create(getFlavorName(abi)) { - ndk { - abiFilters.add(abi) - - cppFlags.addAll(coreCppFlags(abi, ofRoot())) - cppFlags.addAll(addonCppFlags(abi, ofRoot())) - - ldLibs.addAll(coreLdLibs(abi, ofRoot())) - ldLibs.addAll(addonLdLibs(abi, ofRoot())) - - ldFlags.addAll(coreLdFlags(abi, ofRoot())) - ldFlags.addAll(addonLdFlags(abi, ofRoot())) - } - } - } - } -} - - -dependencies { - addonJavaDependencies(ofRoot()).each { dep -> - compile(project(path: dep[1] )) - } - compile project(path: ':ofAndroidLib') -} diff --git a/exampleBasic/gradle/wrapper/gradle-wrapper.jar b/exampleBasic/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 13372ae..0000000 Binary files a/exampleBasic/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/exampleBasic/gradle/wrapper/gradle-wrapper.properties b/exampleBasic/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index d1a6bfb..0000000 --- a/exampleBasic/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Fri Mar 16 17:58:58 EDT 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/exampleBasic/gradlew b/exampleBasic/gradlew deleted file mode 100644 index 9d82f78..0000000 --- a/exampleBasic/gradlew +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/exampleBasic/gradlew.bat b/exampleBasic/gradlew.bat deleted file mode 100644 index aec9973..0000000 --- a/exampleBasic/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/exampleBasic/res/drawable/ic_launcher.png b/exampleBasic/res/drawable/ic_launcher.png deleted file mode 100644 index 70b562f..0000000 Binary files a/exampleBasic/res/drawable/ic_launcher.png and /dev/null differ diff --git a/exampleBasic/res/layout/main_layout.xml b/exampleBasic/res/layout/main_layout.xml deleted file mode 100644 index 732298c..0000000 --- a/exampleBasic/res/layout/main_layout.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/exampleBasic/res/menu/main_layout.xml b/exampleBasic/res/menu/main_layout.xml deleted file mode 100644 index 7ddcfbe..0000000 --- a/exampleBasic/res/menu/main_layout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/exampleBasic/res/values-v11/styles.xml b/exampleBasic/res/values-v11/styles.xml deleted file mode 100644 index febc4d0..0000000 --- a/exampleBasic/res/values-v11/styles.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/exampleBasic/res/values-v14/styles.xml b/exampleBasic/res/values-v14/styles.xml deleted file mode 100644 index 928e0fd..0000000 --- a/exampleBasic/res/values-v14/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/exampleBasic/res/values/strings.xml b/exampleBasic/res/values/strings.xml deleted file mode 100644 index 603a65f..0000000 --- a/exampleBasic/res/values/strings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - ofxARCore Example - Settings - \ No newline at end of file diff --git a/exampleBasic/res/values/styles.xml b/exampleBasic/res/values/styles.xml deleted file mode 100644 index 766a2c3..0000000 --- a/exampleBasic/res/values/styles.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - diff --git a/exampleBasic/settings.gradle b/exampleBasic/settings.gradle deleted file mode 100644 index 0ee2a18..0000000 --- a/exampleBasic/settings.gradle +++ /dev/null @@ -1,21 +0,0 @@ -// openFrameworks-relative root directories (don't touch) - -def ofRoot = '../../../' - -// Load common functions -apply from: ofRoot+"libs/openFrameworksCompiled/project/android/common-functions.gradle" - -javaDependencies( ofRoot ).each { dep -> - include(dep[1]) - project(dep[1]).projectDir = new File(dep[0]) -} - -addonJavaDependencies( ofRoot ).each { dep -> - println dep - include(dep[1]) - project(dep[1]).projectDir = new File(dep[0]) -} - -include ':arcore_client' -project(':arcore_client').projectDir = new File(ofRoot + 'addons/ofxARCore/ofxARCoreLib/arcore_client') - diff --git a/exampleBasic/src/main.cpp b/exampleBasic/src/main.cpp deleted file mode 100644 index 2a410c5..0000000 --- a/exampleBasic/src/main.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "ofMain.h" -#include "ofApp.h" - -int main(){ - ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context - - // this kicks off the running of my app - // can be OF_WINDOW or OF_FULLSCREEN - // pass in width and height too: - ofRunApp( new ofApp() ); - return 0; -} - - -#ifdef TARGET_ANDROID -void ofAndroidApplicationInit() -{ - //application scope init -} - -void ofAndroidActivityInit() -{ - //activity scope init - main(); -} -#endif diff --git a/exampleBasic/src/ofApp.cpp b/exampleBasic/src/ofApp.cpp deleted file mode 100644 index da5bc3f..0000000 --- a/exampleBasic/src/ofApp.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#include "ofApp.h" - -//-------------------------------------------------------------- -void ofApp::setup(){ - arcore.setup(); - initialized = false; - - ofBackground(0); - - ofSetOrientation(OF_ORIENTATION_DEFAULT, false); -} - -//-------------------------------------------------------------- -void ofApp::update(){ - arcore.update(); - if(!initialized && arcore.isInitialized()){ - initialized = true; - projectionMatrix = arcore.getProjectionMatrix(0.01f,100.0); - } - -} - -//-------------------------------------------------------------- -void ofApp::draw(){ - ofSetColor(255); - - if(initialized) { - arcore.draw(); - - ofSetMatrixMode(OF_MATRIX_PROJECTION); - ofLoadMatrix(projectionMatrix); - ofSetMatrixMode(OF_MATRIX_MODELVIEW); - ofLoadMatrix(arcore.getViewMatrix()); - - ofDrawGrid(0.1, 30, true, true, true, true); - } - -} diff --git a/exampleBasic/src/ofApp.h b/exampleBasic/src/ofApp.h deleted file mode 100644 index cc89cc4..0000000 --- a/exampleBasic/src/ofApp.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#pragma once - -#include "ofMain.h" -#include "ofxAndroid.h" -#include "ofxARCore.h" - -class ofApp : public ofxAndroidApp{ - - public: - void setup(); - void update(); - void draw(); - - ofxARCore arcore; - bool initialized; - ofMatrix4x4 projectionMatrix; -}; diff --git a/exampleBasic/srcJava/cc/openframeworks/arcoreexample/OFActivity.java b/exampleBasic/srcJava/cc/openframeworks/arcoreexample/OFActivity.java deleted file mode 100644 index b5abb4a..0000000 --- a/exampleBasic/srcJava/cc/openframeworks/arcoreexample/OFActivity.java +++ /dev/null @@ -1,48 +0,0 @@ -package cc.openframeworks.arcoreexample; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import cc.openframeworks.OFAndroid; - - -public class OFActivity extends cc.openframeworks.OFActivity{ - - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - } - - @Override - public void onDetachedFromWindow() { - } - - // Menus - // http://developer.android.com/guide/topics/ui/menus.html - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Create settings menu options from here, one by one or infalting an xml - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // This passes the menu option string to OF - // you can add additional behavior from java modifying this method - // but keep the call to OFAndroid so OF is notified of menu events - if(OFAndroid.menuItemSelected(item.getItemId())){ - - return true; - } - return super.onOptionsItemSelected(item); - } - - - @Override - public boolean onPrepareOptionsMenu (Menu menu){ - // This method is called every time the menu is opened - // you can add or remove menu options from here - return super.onPrepareOptionsMenu(menu); - } -} - diff --git a/exampleDrawing/.gitignore b/exampleDrawing/.gitignore deleted file mode 100644 index f48b69f..0000000 --- a/exampleDrawing/.gitignore +++ /dev/null @@ -1,39 +0,0 @@ -### Android ### -# Built application files -*.apk -*.ap_ - -# Files for the Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -### Android Patch ### -gen-external-apklibs -reports -obj -assets -.DS_Store -/.idea -/ardrawing.iml diff --git a/exampleDrawing/AndroidManifest.xml b/exampleDrawing/AndroidManifest.xml deleted file mode 100644 index 58bdb71..0000000 --- a/exampleDrawing/AndroidManifest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/exampleDrawing/addons.make b/exampleDrawing/addons.make deleted file mode 100644 index a8303d1..0000000 --- a/exampleDrawing/addons.make +++ /dev/null @@ -1 +0,0 @@ -ofxARCore diff --git a/exampleDrawing/bin/data/Roboto-Regular.ttf b/exampleDrawing/bin/data/Roboto-Regular.ttf deleted file mode 100755 index 2c97eea..0000000 Binary files a/exampleDrawing/bin/data/Roboto-Regular.ttf and /dev/null differ diff --git a/exampleDrawing/build.gradle b/exampleDrawing/build.gradle deleted file mode 100644 index 2292701..0000000 --- a/exampleDrawing/build.gradle +++ /dev/null @@ -1,146 +0,0 @@ -def ofRoot(){ return '../../../' } - -// Load common functions -apply from: ofRoot()+"libs/openFrameworksCompiled/project/android/common-functions.gradle" - -buildscript { - apply from: "../../../libs/openFrameworksCompiled/project/android/ndk-verify.gradle" - - repositories { - jcenter() - } - dependencies { - // Using the gradle-experimental version that supports c++ - classpath 'com.android.tools.build:gradle-experimental:0.9.3' - } -} - -allprojects { - repositories { - jcenter() - maven { - url 'https://dl.google.com/dl/android/maven2/' - } - } -} - -apply plugin: 'com.android.model.application' - -model { - android { - compileSdkVersion = 25 - buildToolsVersion = "25.0.3" - defaultConfig.with { - minSdkVersion.apiLevel = 25 - targetSdkVersion.apiLevel = 25 - versionCode = 1 - versionName = "1.0" - } - - } - - android.ndk { - moduleName = ofAppModuleName() - toolchain = buildToolchain() - stl = compilerStl() - platformVersion = "19" - } - - android.packagingOptions{ - doNotStrip "*/*/*.so" - } - - android.sources { - main { - jni { - source { - srcDirs= appSrcDirs(ofRoot()) - - includes = srcIncludes(ofRoot()) - excludes = srcExcludes(ofRoot()) - } - - // Link to openFrameworks - dependencies { - project ":openFrameworksProject" linkage "static" - } - } - - manifest { - source { - srcDirs = [ "." ] - } - } - res { - source { - srcDirs = [ "res" ] - } - } - java { - source { - srcDirs = [ "srcJava" ] - } - } - aidl { - source{ - srcDirs = ['srcJava'] - } - } - renderscript{ - source{ - srcDirs = ['srcJava'] - } - } - jniLibs { - source { - srcDirs = ['libs'] - } - } - assets { - source { - srcDirs = ['bin/data'] + addonData(ofRoot()) - } - } - } - } - - android.lintOptions { - abortOnError = false - } - - android.buildTypes { - release { - minifyEnabled = false - } - } - - // Setup the different types of flavors (arm / x86), - // and add linker flags based on that - android.productFlavors { - getAbis().each { abi -> - create(getFlavorName(abi)) { - ndk { - abiFilters.add(abi) - - cppFlags.addAll(coreCppFlags(abi, ofRoot())) - cppFlags.addAll(addonCppFlags(abi, ofRoot())) - - ldLibs.addAll(coreLdLibs(abi, ofRoot())) - ldLibs.addAll(addonLdLibs(abi, ofRoot())) - - ldFlags.addAll(coreLdFlags(abi, ofRoot())) - ldFlags.addAll(addonLdFlags(abi, ofRoot())) - } - } - } - } - -} - - -dependencies { - addonJavaDependencies(ofRoot()).each { dep -> - compile(project(path: dep[1] )) - } - compile project(path: ':ofAndroidLib') -} diff --git a/exampleDrawing/gradle/wrapper/gradle-wrapper.jar b/exampleDrawing/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 13372ae..0000000 Binary files a/exampleDrawing/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/exampleDrawing/gradle/wrapper/gradle-wrapper.properties b/exampleDrawing/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 67ce797..0000000 --- a/exampleDrawing/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Fri Mar 16 14:43:21 EDT 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/exampleDrawing/gradlew b/exampleDrawing/gradlew deleted file mode 100644 index 9d82f78..0000000 --- a/exampleDrawing/gradlew +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/exampleDrawing/gradlew.bat b/exampleDrawing/gradlew.bat deleted file mode 100644 index aec9973..0000000 --- a/exampleDrawing/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/exampleDrawing/res/drawable/ic_launcher.png b/exampleDrawing/res/drawable/ic_launcher.png deleted file mode 100644 index 70b562f..0000000 Binary files a/exampleDrawing/res/drawable/ic_launcher.png and /dev/null differ diff --git a/exampleDrawing/res/layout/main_layout.xml b/exampleDrawing/res/layout/main_layout.xml deleted file mode 100644 index b897d1b..0000000 --- a/exampleDrawing/res/layout/main_layout.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - diff --git a/exampleDrawing/res/menu/main_layout.xml b/exampleDrawing/res/menu/main_layout.xml deleted file mode 100644 index 7ddcfbe..0000000 --- a/exampleDrawing/res/menu/main_layout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/exampleDrawing/res/values-v11/styles.xml b/exampleDrawing/res/values-v11/styles.xml deleted file mode 100644 index febc4d0..0000000 --- a/exampleDrawing/res/values-v11/styles.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/exampleDrawing/res/values-v14/styles.xml b/exampleDrawing/res/values-v14/styles.xml deleted file mode 100644 index 928e0fd..0000000 --- a/exampleDrawing/res/values-v14/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/exampleDrawing/res/values/strings.xml b/exampleDrawing/res/values/strings.xml deleted file mode 100644 index e63be83..0000000 --- a/exampleDrawing/res/values/strings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - AR Drawing - Settings - \ No newline at end of file diff --git a/exampleDrawing/res/values/styles.xml b/exampleDrawing/res/values/styles.xml deleted file mode 100644 index 766a2c3..0000000 --- a/exampleDrawing/res/values/styles.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - diff --git a/exampleDrawing/settings.gradle b/exampleDrawing/settings.gradle deleted file mode 100644 index 0908d5d..0000000 --- a/exampleDrawing/settings.gradle +++ /dev/null @@ -1,16 +0,0 @@ -// openFrameworks-relative root directories (don't touch) - -def ofRoot = '../../../' - -// Load common functions -apply from: ofRoot+"libs/openFrameworksCompiled/project/android/common-functions.gradle" - -javaDependencies( ofRoot ).each { dep -> - include(dep[1]) - project(dep[1]).projectDir = new File(dep[0]) -} - -addonJavaDependencies( ofRoot ).each { dep -> - include(dep[1]) - project(dep[1]).projectDir = new File(dep[0]) -} diff --git a/exampleDrawing/src/main.cpp b/exampleDrawing/src/main.cpp deleted file mode 100644 index 21adcfb..0000000 --- a/exampleDrawing/src/main.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "ofMain.h" -#include "ofApp.h" - -int main(){ - ofSetupOpenGL(1280,720, OF_WINDOW); // <-------- setup the GL context - - // this kicks off the running of my app - // can be OF_WINDOW or OF_FULLSCREEN - // pass in width and height too: - ofRunApp( new ofApp() ); - return 0; -} - - -#ifdef TARGET_ANDROID -void ofAndroidApplicationInit() -{ - //application scope init -} - -void ofAndroidActivityInit() -{ - //activity scope init - main(); -} -#endif diff --git a/exampleDrawing/src/ofApp.cpp b/exampleDrawing/src/ofApp.cpp deleted file mode 100644 index 35e1220..0000000 --- a/exampleDrawing/src/ofApp.cpp +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2017 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "ofApp.h" - - -ofEvent clearDrawingEvent; - -//-------------------------------------------------------------- -void ofApp::setup() { - ofBackground(0); - ofSetOrientation(OF_ORIENTATION_DEFAULT, false); - font.load("Roboto-Regular.ttf", 40); - - ofAddListener(clearDrawingEvent, this, &ofApp::clearDrawing); - - initialized = false; - - // Setup ARCore - arcore.setup(); -} - -//-------------------------------------------------------------- -void ofApp::update(){ - arcore.update(); - - if(!initialized && arcore.isInitialized()){ - // Load projection matrix once when ARCore is initialized - initialized = true; - projectionMatrix = arcore.getProjectionMatrix(0.01f,100.0); - } - - if(initialized && _touchDown){ - addRibbonPoint(mouseX, mouseY, 0.002); - } -} - -//-------------------------------------------------------------- -void ofApp::draw(){ - - ofSetColor(255); - if(initialized) { - // Draw the camera image - arcore.draw(); - - if(arcore.isTracking()) { - // Load the projection and view matrix from ARCore - ofSetMatrixMode(OF_MATRIX_PROJECTION); - ofLoadMatrix(projectionMatrix); - ofSetMatrixMode(OF_MATRIX_MODELVIEW); - ofLoadMatrix(arcore.getViewMatrix()); - - // Draw the lines - for (auto line : lineMeshes) { - line.draw(OF_MESH_FILL); - } - } else { - drawMessage("Not tracking"); - } - } else { - drawMessage("Initializing ARCore"); - } -} - -//-------------------------------------------------------------- -void ofApp::drawMessage(string text){ - ofPushStyle(); - ofSetColor(0,0,0, 100); - ofDrawRectangle(0, ofGetHeight() - 200, ofGetWidth(), 300); - - ofSetColor(255); - float w = font.stringWidth(text); - font.drawString(text, ofGetWidth()/2-w/2, ofGetHeight() - 110); - ofPopStyle(); -} - - -//-------------------------------------------------------------- -// Calculate the world coordinate from screen coordinate -ofVec3f ofApp::screenToWorld(float x, float y, float z){ - ofVec2f s = ofVec3f( - (x - ofGetWidth()/2.f)/ofGetWidth(), - (y - ofGetHeight()/2.f)/ofGetHeight()); - - float zFull = z * 100.f; - float zNearToFar = ofLerp(0.01, 100.0, z); - float alpha = zFull / zNearToFar; - - auto m = arcore.getViewMatrix() * projectionMatrix; - auto p4 = ofVec4f(2.f*s.x,-2.f*s.y,alpha,1.0) * m.getInverse(); - - return ofVec3f(p4.x, p4.y, p4.z) / p4.w; -} - -//-------------------------------------------------------------- -void ofApp::addRibbonPoint(float x, float y, float z){ - ofVec3f p = screenToWorld(x, y, z); - lines[lines.size()-1].curveTo(p); - - // Resample line - ofPolyline l = lines[lines.size()-1].getResampledBySpacing(0.01); - - // Update mesh - updateLineMesh(lines[lines.size()-1], lineMeshes[lineMeshes.size()-1]); - - // When line is long, split it up (for optimization) - if(l.size() > 100){ - createNewLine(); - lines[lines.size()-1].addVertex(l.getVertices()[l.size()-2]); - lines[lines.size()-1].addVertex(l.getVertices()[l.size()-1]); - } -} - -//-------------------------------------------------------------- -// Create line mesh based on polyline -void ofApp::updateLineMesh(ofPolyline & line, ofVboMesh & mesh, int offset){ - auto viewmatrix = arcore.getViewMatrix().getInverse(); - - float thickness = 0.005; - mesh.clear(); - - int n = line.size(); - for(int i=1;i lines ; - vector< ofVboMesh > lineMeshes; - vector< int > lineOffsets; - - ofTrueTypeFont font; -}; diff --git a/exampleDrawing/srcJava/cc/openframeworks/ardrawing/OFActivity.java b/exampleDrawing/srcJava/cc/openframeworks/ardrawing/OFActivity.java deleted file mode 100644 index cae91d2..0000000 --- a/exampleDrawing/srcJava/cc/openframeworks/ardrawing/OFActivity.java +++ /dev/null @@ -1,11 +0,0 @@ -package cc.openframeworks.ardrawing; -import android.view.View; - - -public class OFActivity extends cc.openframeworks.OFActivity{ - - public static native void clearDrawing(); - - public void clear(View b){ clearDrawing(); } -} - diff --git a/ofxARCoreLib/build.gradle b/ofxARCoreLib/build.gradle index a843854..6c92f5c 100755 --- a/ofxARCoreLib/build.gradle +++ b/ofxARCoreLib/build.gradle @@ -14,17 +14,18 @@ allprojects { maven { url 'https://dl.google.com/dl/android/maven2/' } + } } apply plugin: 'com.android.model.library' model { android { - compileSdkVersion = 25 - buildToolsVersion = "25.0.3" + compileSdkVersion = 26 + buildToolsVersion = "26.0.0" defaultConfig.with { - minSdkVersion.apiLevel = 25 - targetSdkVersion.apiLevel = 25 + minSdkVersion.apiLevel = 26 + targetSdkVersion.apiLevel = 26 versionCode = 1 versionName = "1.0" } @@ -38,5 +39,13 @@ model { dependencies { compile 'com.google.ar:core:1+' + compile 'com.android.support:appcompat-v7:25.0.0' + compile 'com.android.support:design:25.+' + + compile 'com.android.support:recyclerview-v7:22.1.1' + compile 'com.android.support:cardview-v7:22.1.1' + + compile 'com.thebluealliance:spectrum:0.7.1' + compile project(path: ':ofAndroidLib') } diff --git a/ofxARCoreLib/src/main/java/cc/ofxarcorelib/ofxARCoreLib.java b/ofxARCoreLib/src/main/java/cc/ofxarcorelib/ofxARCoreLib.java index 55010eb..36e41e7 100755 --- a/ofxARCoreLib/src/main/java/cc/ofxarcorelib/ofxARCoreLib.java +++ b/ofxARCoreLib/src/main/java/cc/ofxarcorelib/ofxARCoreLib.java @@ -16,190 +16,563 @@ import android.app.Activity; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.hardware.camera2.CameraAccessException; +import android.hardware.camera2.CameraCharacteristics; +import android.hardware.camera2.CameraManager; +import android.os.Build; +import android.support.annotation.RequiresApi; +import android.util.DisplayMetrics; +import android.util.Log; +import android.util.SizeF; +import android.util.SparseArray; import android.view.Surface; import android.widget.Toast; import com.google.ar.core.Anchor; +import com.google.ar.core.AugmentedImage; +import com.google.ar.core.AugmentedImageDatabase; import com.google.ar.core.Config; import com.google.ar.core.Frame; +import com.google.ar.core.HitResult; +import com.google.ar.core.Plane; import com.google.ar.core.Pose; import com.google.ar.core.Session; import com.google.ar.core.TrackingState; +import com.google.ar.core.PointCloud; +import com.google.ar.core.exceptions.CameraNotAvailableException; import com.google.ar.core.exceptions.NotTrackingException; +import com.google.ar.core.exceptions.UnavailableApkTooOldException; +import com.google.ar.core.exceptions.UnavailableArcoreNotInstalledException; +import com.google.ar.core.exceptions.UnavailableDeviceNotCompatibleException; +import com.google.ar.core.exceptions.UnavailableSdkTooOldException; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import cc.openframeworks.OFAndroid; import cc.openframeworks.OFAndroidObject; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; public class ofxARCoreLib extends OFAndroidObject { - private static final String TAG = "ofxARCoreLib"; - - private Config mDefaultConfig; - private Session mSession; - - private boolean mIsReady = false; - private int mTexId; - - private FloatBuffer mTextureUV = FloatBuffer.allocate(8); - private FloatBuffer mTextureUVTransformed = FloatBuffer.allocate(8); - private boolean mTextureUVDirty; - - private float[] mViewMatrix = new float[16]; - private float[] mProjectionMatrix = new float[16]; - private float[] mAnchorMatrix = new float[16]; - - private TrackingState mTrackingState = TrackingState.STOPPED; - - private Pose mPose; - private ArrayList mAnchors = new ArrayList<>(); - - public void setup(int texId, final int width, final int height){ - Context context = OFAndroid.getContext(); - - mTexId = texId; - - ((Activity)context).runOnUiThread(new Runnable() { - @Override - public void run() { - Context context = OFAndroid.getContext(); - - mSession = new Session((Activity) context); - - // Create default config, check is supported, create session from that config. - mDefaultConfig = new Config(mSession); - if (!mSession.isSupported(mDefaultConfig)) { - Toast.makeText(context, "This device does not support AR", Toast.LENGTH_LONG).show(); - return; - } - mSession.configure(mDefaultConfig); - - mSession.setCameraTextureName(mTexId); - mSession.setDisplayGeometry(Surface.ROTATION_0, width, height); - - // Allocate UV coordinate buffers - ByteBuffer bbTexCoords = ByteBuffer.allocateDirect(4 * 2 * 4); - bbTexCoords.order(ByteOrder.nativeOrder()); - mTextureUV = bbTexCoords.asFloatBuffer(); - mTextureUV.put(QUAD_TEXCOORDS); - mTextureUV.position(0); - - ByteBuffer bbTexCoordsTransformed = ByteBuffer.allocateDirect(4 * 2 * 4); - bbTexCoordsTransformed.order(ByteOrder.nativeOrder()); - mTextureUVTransformed = bbTexCoordsTransformed.asFloatBuffer(); - - mSession.resume(); - - } - }); - } - - public boolean isInitialized(){ - return mIsReady; - } - - public boolean isTracking(){ - return mTrackingState == TrackingState.TRACKING; - } - - public float[] getViewMatrix(){ - return mViewMatrix; - } - - public float[] getProjectionMatrix(float near, float far){ - if(mIsReady) mSession.update().getCamera().getProjectionMatrix(mProjectionMatrix, 0, near, far); - return mProjectionMatrix; - } - - public float[] getTextureUv(){ - float[] ret = new float[8]; - mTextureUVTransformed.position(0); - mTextureUVTransformed.get(ret); - return ret; - } - - public void addAnchor(){ - if(!mIsReady) return; - try { - Anchor a = mSession.createAnchor(mPose); - mAnchors.add(a); - } catch (NotTrackingException e) { - e.printStackTrace(); - } - } - - public float[] getAnchorPoseMatrix(int index){ - if(mAnchors.size() <= index) return mAnchorMatrix; - mAnchors.get(index).getPose().toMatrix(mAnchorMatrix, 0); - return mAnchorMatrix; - } - - public boolean textureUvDirty(){ - if(mTextureUVDirty){ - mTextureUVDirty = false; - return true; - } - return false; - } - - public void update(){ - if(mSession == null) return; - - Frame frame = null; - try { - frame = mSession.update(); - if (frame.hasDisplayGeometryChanged()) { - mTextureUVTransformed.position(0); - frame.transformDisplayUvCoords(mTextureUV, mTextureUVTransformed); - mTextureUVDirty = true; - } - - // If not tracking, return - mTrackingState = frame.getCamera().getTrackingState(); - if (mTrackingState != TrackingState.TRACKING) { - return; - } - - mPose = frame.getCamera().getPose(); - frame.getCamera().getViewMatrix(mViewMatrix, 0); - - mIsReady = true; + private static final String TAG = "ofxARCoreLib"; + + private Config mDefaultConfig; + private Session mSession; + private SparseArray _detectedPlanes = new SparseArray(); + private boolean mIsReady = false; + private int mTexId; + + private FloatBuffer mTextureUV = FloatBuffer.allocate(8); + private FloatBuffer mTextureUVTransformed = FloatBuffer.allocate(8); + private boolean mTextureUVDirty; + + private float[] mViewMatrix = new float[16]; + private float[] mProjectionMatrix = new float[16]; + private float[] mAnchorMatrix = new float[16]; + private ArrayList augImg_matrices = new ArrayList();// = new float[16]; + + private TrackingState mTrackingState = TrackingState.STOPPED; + + private Pose mPose; + private ArrayList mAnchors = new ArrayList<>(); + private Frame frame = null; + + + // boehm-e + public float horizontalAngle; + public float verticalAngle; + public float screenDpi; + + // boehm-e point cloud + private PointCloud pointcloud_data = null; + private FloatBuffer pcloud_buffer; + private float[] pcloud_array; + + // boehm-e plane + private ArrayList planes = new ArrayList();// = new float[16]; + float[] _planeMatrix = new float[16]; + float[] _planeVertices = new float[12]; + + private boolean enableAugmentedImages; + + + public void setup(int texId, final int width, final int height, int enableAugmentedImages){ + Context context = OFAndroid.getContext(); + + if (enableAugmentedImages == 1) { + this.enableAugmentedImages = true; + } else { + this.enableAugmentedImages = false; + } + + + // boehm-e + // calculate camera fov + + CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); + calculateFOV(manager); + + // calculate dpi + DisplayMetrics displaymetrics = new DisplayMetrics(); + + activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); + + screenDpi = context.getResources().getDisplayMetrics().xdpi; + + + + mTexId = texId; + + final boolean _enableAugmentedImages = this.enableAugmentedImages; + + ((Activity)context).runOnUiThread(new Runnable() { + @Override + public void run() { + Context context = OFAndroid.getContext(); + + try { + mSession = new Session((Activity) context); + + } catch (UnavailableArcoreNotInstalledException e) { + Log.d("DEBUG ERWAN", "ERROR UnavailableArcoreNotInstalledException"); + e.printStackTrace(); + } catch (UnavailableApkTooOldException e) { + Log.d("DEBUG ERWAN", "ERROR UnavailableApkTooOldException"); + e.printStackTrace(); + } catch (UnavailableSdkTooOldException e) { + Log.d("DEBUG ERWAN", "ERROR UnavailableSdkTooOldException"); + e.printStackTrace(); + } catch (UnavailableDeviceNotCompatibleException e) { + Log.d("DEBUG ERWAN", "ERROR UnavailableDeviceNotCompatibleException"); + e.printStackTrace(); + } + + // Create default config, check is supported, create session from that config. + mDefaultConfig = new Config(mSession); + if (!mSession.isSupported(mDefaultConfig)) { + Toast.makeText(context, "This device does not support AR", Toast.LENGTH_LONG).show(); + return; + } + + // boehm-e AugmentedImageDatabase + if (_enableAugmentedImages == true) { + AugmentedImageDatabase db = createAugmentedImageDatabase(); + for (int i=0; i hits = frame.hitTest(x, y); + float minDist = 1000; + HitResult hit = null; + for (int i=0; i planes) { + if (!planes.isEmpty()) { + for (Plane plane : planes) { + plane.getCenterPose().toMatrix(this._planeMatrix, 0); + if (plane.getSubsumedBy() == null && this._detectedPlanes.get(plane.hashCode()) == null) { + this._detectedPlanes.append(plane.hashCode(), plane); + } else if (plane.getSubsumedBy() != null) { + this._detectedPlanes.delete(plane.hashCode()); + } else { + } + } + } + } + + private static void getPlaneVertices(Plane plane, float[] planeVertices) { + planeVertices[0] = plane.getExtentX() / 2.0f; + planeVertices[1] = 0.0f; + planeVertices[2] = plane.getExtentZ() / 2.0f; + planeVertices[3] = (-plane.getExtentX()) / 2.0f; + planeVertices[4] = 0.0f; + planeVertices[5] = plane.getExtentZ() / 2.0f; + planeVertices[6] = (-plane.getExtentX()) / 2.0f; + planeVertices[7] = 0.0f; + planeVertices[8] = (-plane.getExtentZ()) / 2.0f; + planeVertices[9] = plane.getExtentX() / 2.0f; + planeVertices[10] = 0.0f; + planeVertices[11] = (-plane.getExtentZ()) / 2.0f; + } + + public void update(){ + if(mSession == null) return; + + try { + frame = mSession.update(); + + + if (frame.hasDisplayGeometryChanged()) { + mTextureUVTransformed.position(0); + frame.transformDisplayUvCoords(mTextureUV, mTextureUVTransformed); + mTextureUVDirty = true; + } + + // If not tracking, return + mTrackingState = frame.getCamera().getTrackingState(); + if (mTrackingState != TrackingState.TRACKING) { + return; + } + + mPose = frame.getCamera().getPose(); + frame.getCamera().getViewMatrix(mViewMatrix, 0); + + + + /* point cloud @kashimAstro */ + pointcloud_data = frame.acquirePointCloud(); + pcloud_buffer = pointcloud_data.getPoints(); + pcloud_array = new float[pcloud_buffer.limit()]; + pcloud_buffer.get(pcloud_array); + + mIsReady = true; // final float lightIntensity = frame.getLightEstimate().getPixelIntensity(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - - private static final float[] QUAD_TEXCOORDS = new float[]{ - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f, - }; - - private void updateTexture(){ - mSession.setCameraTextureName(mTexId); - } - - @Override - protected void appPause() { - if(mSession == null) return; - mSession.pause(); - } - - @Override - protected void appResume() { - if(mSession != null) - mSession.resume(); - } - - @Override - protected void appStop() { - - } + + // Plane detection boehm-e + Collection arcore_planes = frame.getUpdatedTrackables(Plane.class); + + updatePlanes(arcore_planes); + planes.clear(); + + for (int j=0; j transformed_mesh = new ArrayList(); + + for (int i =0; i updatedAugmentedImages = + frame.getUpdatedTrackables(AugmentedImage.class); + + + + int index = 0; + for (AugmentedImage img : updatedAugmentedImages) { + if (img.getTrackingState() == TrackingState.TRACKING && img.getTrackingMethod() == AugmentedImage.TrackingMethod.FULL_TRACKING) { + String name = img.getName(); + Pose pose = img.getCenterPose(); + float width = img.getExtentX(); + float height = img.getExtentZ(); + float[] new_matrix = new float[20]; + pose.toMatrix(new_matrix, 0); + new_matrix[16] = width; + new_matrix[17] = height; + new_matrix[18] = img.getIndex(); + new_matrix[19] = 1; // tracking + augImg_matrices.set(img.getIndex(), new_matrix); + + } else { + + float[] new_matrix = new float[20]; + new_matrix[18] = img.getIndex(); + new_matrix[19] = 0; // NOT TRACKING + augImg_matrices.set(img.getIndex(), new_matrix); + } + index++; + } + } + + + } catch (Throwable e) { + e.printStackTrace(); + } + } + + private static final float[] QUAD_TEXCOORDS = new float[]{ + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 1.0f, 0.0f, + }; + + private void updateTexture(){ + mSession.setCameraTextureName(mTexId); + } + + + + + + // boehm-e + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + private void calculateFOV(CameraManager cManager) { + try { + for (final String cameraId : cManager.getCameraIdList()) { + CameraCharacteristics characteristics = cManager.getCameraCharacteristics(cameraId); + int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING); + if (cOrientation == CameraCharacteristics.LENS_FACING_BACK) { + float[] maxFocus = characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS); + SizeF size = characteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE); + float w = size.getWidth(); + float h = size.getHeight(); + horizontalAngle = w; +// horizontalAngle = (float) (2*Math.atan(w/(maxFocus[0]*2))); + verticalAngle = (float) (2*Math.atan(h/(maxFocus[0]*2))); + return; + } + } + } catch (CameraAccessException e) { + e.printStackTrace(); + } + } + + public float getFOV() { + Log.d("ofxARCoreLib.java", "HORIZONTAL FOV : " + horizontalAngle); + float fov = (float) horizontalAngle; + + return fov; +// return horizontalAngle; + } + + public float getDPI() { + Log.d("ofxARCoreLib.java", "SCREEN DPI : " + screenDpi); + + float dpi = (float) screenDpi; + + return dpi; + } + + + // boehm_e AugmentedImageDatabase + public AugmentedImageDatabase createAugmentedImageDatabase() { + AugmentedImageDatabase imageDatabase = new AugmentedImageDatabase(this.mSession); + Bitmap bitmap; + + + try { + for(String imgName : OFAndroid.getContext().getAssets().list("AugmentedImageDatabase")){ + String imgPath = "AugmentedImageDatabase/"+imgName; + InputStream inputStream = OFAndroid.getContext().getAssets().open(imgPath); + bitmap = BitmapFactory.decodeStream(inputStream); + int index = imageDatabase.addImage(imgName, bitmap); + + Log.d("DEBUG ERWAN", "ADDED IMAGE : "+imgPath); + } + } catch (IOException e) { + Log.d("DEBUG ERWAN", "fail to load image"); + e.printStackTrace(); + } + + return imageDatabase; + } + + + + + + @Override + protected void appPause() { + if(mSession == null) return; + mSession.pause(); + } + + @Override + protected void appResume() { + if(mSession != null) { + try { + mSession.resume(); + } catch (CameraNotAvailableException e) { + e.printStackTrace(); + } + } + } + + @Override + protected void appStop() { + + } } diff --git a/preview.gif b/preview.gif deleted file mode 100644 index d3f47c3..0000000 Binary files a/preview.gif and /dev/null differ diff --git a/src/ofxARCore.cpp b/src/ofxARCore.cpp index f0723d2..848daca 100644 --- a/src/ofxARCore.cpp +++ b/src/ofxARCore.cpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include #include "ofxARCore.h" #include "ofxAndroidUtils.h" @@ -60,10 +62,14 @@ ofxARCore::~ofxARCore(){ ofRemoveListener(ofxAndroidEvents().resume,this,&ofxARCore::resumeApp); } -void ofxARCore::setup(){ +void ofxARCore::setup(bool enableAugmentedImages){ _sessionInitialized = false; + this->enableAugmentedImages = enableAugmentedImages; + std::string path = "AugmentedImageDatabase"; + arcoreImagesDir = new ofDirectory(path); + ofxAndroidRequestPermission(OFX_ANDROID_PERMISSION_CAMERA); // Request camera permissions if(ofxAndroidCheckPermission(OFX_ANDROID_PERMISSION_CAMERA)) { @@ -95,13 +101,13 @@ void ofxARCore::setupSession(){ } JNIEnv *env = ofGetJNIEnv(); - jmethodID javaSetupMethod = env->GetMethodID(javaClass, "setup", "(III)V"); + jmethodID javaSetupMethod = env->GetMethodID(javaClass, "setup", "(IIII)V"); if (!javaSetupMethod) { ofLogError("ofxARCore") << "setup(): couldn't get java setup for ofxARCore"; return; } - env->CallVoidMethod(javaTango, javaSetupMethod, texId, ofGetWidth(), ofGetHeight()); + env->CallVoidMethod(javaTango, javaSetupMethod, texId, ofGetWidth(), ofGetHeight(), this->enableAugmentedImages); _sessionInitialized = true; } @@ -137,6 +143,16 @@ GLuint ofxARCore::setupTexture(){ return texId[0]; } +void ofxARCore::reloadTexture() { + GLuint texId = setupTexture(); + JNIEnv *env = ofGetJNIEnv(); + jmethodID javaSetupMethod = env->GetMethodID(javaClass, "setup2", "(I)V"); + if (!javaSetupMethod) { + ofLogError("ofxARCore") << "setup(): couldn't get java setup for ofxARCore"; + return; + } + env->CallVoidMethod(javaTango, javaSetupMethod, texId); +} void ofxARCore::pauseApp(){ JNIEnv *env = ofGetJNIEnv(); @@ -144,6 +160,10 @@ void ofxARCore::pauseApp(){ } void ofxARCore::resumeApp(){ + + setupSession(); + reloadTexture(); + JNIEnv *env = ofGetJNIEnv(); env->CallVoidMethod(javaTango, env->GetMethodID(javaClass, "appResume", "()V")); @@ -163,7 +183,7 @@ void ofxARCore::update(){ // Check if textureUVs are marked dirty bool textureUvDirty = env->CallBooleanMethod(javaTango, - env->GetMethodID(javaClass, "textureUvDirty", "()Z")); + env->GetMethodID(javaClass, "textureUvDirty", "()Z")); if(textureUvDirty){ jmethodID method = env->GetMethodID(javaClass, "getTextureUv", "()[F"); @@ -186,6 +206,49 @@ bool ofxARCore::isInitialized(){ return env->CallBooleanMethod(javaTango, method); } +float ofxARCore::getCameraFOV() { + + JNIEnv *env = ofGetJNIEnv(); + jmethodID javaGetFovMethod = env->GetMethodID(javaClass,"getFOV","()F"); + if(!javaGetFovMethod){ + ofLogError("javaGetFovMethod") << "javaGetFovMethod(): couldn't get java"; + return false; + } + jfloat fov = env->CallFloatMethod (javaTango, javaGetFovMethod); + ofLog() << "FOVVV " << fov; + + return fov; +} + +/* point cloud and plane */ +std::vector ofxARCore::getPointCloud() { + JNIEnv *env = ofGetJNIEnv(); + jfloatArray data = (jfloatArray) env->CallObjectMethod(javaTango, + env->GetMethodID(javaClass,"getPointCloud","()[F")); + + jsize size = env->GetArrayLength(data); + std::vector result; + result.resize((int)size); + env->GetFloatArrayRegion(data, 0, size, (jfloat*)&result[0]); + return result; +} + + +float ofxARCore::getDpi() { + + JNIEnv *env = ofGetJNIEnv(); + jmethodID javaGetDpiMethod = env->GetMethodID(javaClass,"getDPI","()F"); + if(!javaGetDpiMethod){ + ofLogError("javaGetDpiMethod ") << "javaGetDpiMethod (): couldn't get java"; + return false; + } + jfloat dpi = env->CallFloatMethod (javaTango, javaGetDpiMethod); + ofLog() << "DPI " << dpi; + + return dpi; + +} + bool ofxARCore::isTracking(){ JNIEnv *env = ofGetJNIEnv(); jmethodID method = env->GetMethodID(javaClass,"isTracking","()Z"); @@ -204,6 +267,108 @@ ofMatrix4x4 ofxARCore::getViewMatrix(){ return m; } + +// boehm-e | hit pose of +ofHitPose *ofxARCore::getHitPose(int x, int y) { + JNIEnv *env = ofGetJNIEnv(); + jfloatArray data = (jfloatArray) env->CallObjectMethod(javaTango, + env->GetMethodID(javaClass,"hitTest","(II)[F"), + x, y); + jboolean isCopy; + jfloat *body = env->GetFloatArrayElements(data, &isCopy); + + + int hit_ok = body[17]; + bool has_hit = hit_ok == 1; + + if (has_hit == false) { + return NULL; + } + ofMatrix4x4 m; + m.set(body); + ofHitPose *pose = new ofHitPose{m, body[16]}; + return pose; +} + + +// boehm-e | augmented images of +std::vector ofxARCore::getImageMatrices(){ + + std::vector matrices; + + JNIEnv *env = ofGetJNIEnv(); + jobjectArray objArray = (jobjectArray) env->CallObjectMethod(javaTango, env->GetMethodID(javaClass, "getImageMatrices", "()[[F")); + + int arraySize = env->GetArrayLength(objArray); + for (int i=0; i < arraySize; i++) + { + jboolean isCopy; + jobject array = env->GetObjectArrayElement(objArray, i); + + jfloat *body = env->GetFloatArrayElements((jfloatArray)array, &isCopy); + ofMatrix4x4 m; + m.set(body); + + int index = body[18]; + + std::string name = ofSplitString(arcoreImagesDir->getSorted().getPath(index), "/")[1]; + + int is_tracking = body[19]; + bool tracking = is_tracking == 1; + matrices.push_back(new ofAugmentedImage{m, body[16], body[17], index, tracking, name}); + + } + return matrices; +} + + +// boehm-e | augmented images of +std::vector ofxARCore::getPlanes(){ + + std::vector planes; + + JNIEnv *env = ofGetJNIEnv(); + jobjectArray objArray = (jobjectArray) env->CallObjectMethod(javaTango, env->GetMethodID(javaClass, "getPlanes", "()[[F")); + + int arraySize = env->GetArrayLength(objArray); + for (int i=0; i < arraySize; i++) + { + jboolean isCopy; + jobject array = env->GetObjectArrayElement(objArray, i); + + jfloat *body = env->GetFloatArrayElements((jfloatArray)array, &isCopy); + ofMatrix4x4 m; + m.set(body); + + ofMesh mesh; + ofPath path; + + ofLog() << "DEBUG CPP PLANE " << env->GetArrayLength((jfloatArray )array) << std::endl; + for (int i=16; iGetArrayLength((jfloatArray )array); i+=3) { +// if (i==16) { +// path.moveTo(body[i], body[i+1]); +// } else { +// path.lineTo(body[i], body[i+1]); +// } + mesh.addVertex(ofPoint(body[i], body[i+1], body[i+2])); +// mesh.addVertex(ofPoint(body[i+2], 0.0, body[i+3])); +// mesh.addVertex(m.getTranslation()); +// mesh.addIndex(i-16); +// mesh.addIndex(i-15); +// mesh.addIndex(i-14); + } + for (int j=0; jCallObjectMethod(javaTango, @@ -241,4 +406,6 @@ ofMatrix4x4 ofxARCore::getAnchor(int i){ } + + #endif \ No newline at end of file diff --git a/src/ofxARCore.h b/src/ofxARCore.h index ce8aa6a..0fdb9f4 100644 --- a/src/ofxARCore.h +++ b/src/ofxARCore.h @@ -26,30 +26,60 @@ #include "ofMatrix4x4.h" #include "ofTexture.h" +typedef struct ofAugmentedImage { + ofMatrix4x4 matrix; + float width; + float height; + int index; + bool is_tracking; + std::string name; +} ofAugmentedImage; + +typedef struct ofHitPose { + ofMatrix4x4 matrix; + float distance; +} ofHitPose; + +typedef struct ofARPlane { + ofMesh mesh; + ofPath path; + ofMatrix4x4 center; +} ofARPlane; class ofxARCore : ofThread{ + public: - ofxARCore(); + ofxARCore(); ~ofxARCore(); - void setup(); + void setup(bool enableAugmentedImages); bool isInitialized(); bool isTracking(); + // boehm-e + float getCameraFOV(); + float getDpi(); + void update(); void draw(); void pauseApp(); void resumeApp(); + void reloadTexture(); void addAnchor(); ofMatrix4x4 getAnchor(int i=0); ofMatrix4x4 getViewMatrix(); + std::vector getImageMatrices(); + std::vector getPlanes(); + ofHitPose *getHitPose(int x, int y); ofMatrix4x4 getProjectionMatrix(float near=0.1f, float far=100.0f); + std::vector getPointCloud(); /* get point cloud arcore */ + ofTexture texture; private: @@ -59,8 +89,10 @@ class ofxARCore : ofThread{ ofMesh quad; jclass javaClass; jobject javaTango; + ofDirectory *arcoreImagesDir; bool _sessionInitialized; + bool enableAugmentedImages; }; #endif \ No newline at end of file