Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
45818fe
fix HalfdanJ/ofxARCore/issues/19
boehm-e Apr 3, 2019
951bfc4
getAppName
boehm-e Apr 3, 2019
8f634be
getAppName
boehm-e Apr 3, 2019
a4f5343
adding pointcloud
boehm-e Apr 19, 2019
4fab0d5
adding autofocus
boehm-e Apr 25, 2019
48ef25c
corrections for ofZach #20
boehm-e Apr 29, 2019
dd9d8fb
migrate to sdk 26
boehm-e Apr 29, 2019
12c9c8a
prevent crashing when grant camera permissions
boehm-e May 3, 2019
e062216
add errror logs to arcore check install
boehm-e May 8, 2019
be58572
adding augmentedimages to ofxarcore
boehm-e May 10, 2019
6e9f2c8
updating doc & remove unupdated examples
boehm-e May 10, 2019
bd8ba0a
updating doc & remove unupdated examples
boehm-e May 10, 2019
cc0a75f
updating doc & remove unupdated examples
boehm-e May 10, 2019
ba93e32
updating doc & remove unupdated examples
boehm-e May 10, 2019
d891bc5
updating doc & remove unupdated examples
boehm-e May 10, 2019
e29506e
updating doc & remove unupdated examples
boehm-e May 10, 2019
e5bcd8d
updating doc & remove unupdated examples
boehm-e May 10, 2019
baf9ef4
updating doc & remove unupdated examples
boehm-e May 10, 2019
a2343fa
updating doc & remove unupdated examples
boehm-e May 10, 2019
810532a
updating doc & remove unupdated examples
boehm-e May 10, 2019
0e91b29
updating doc & remove unupdated examples
boehm-e May 10, 2019
1dd8a24
updating doc & remove unupdated examples
boehm-e May 10, 2019
da176af
updating doc & remove unupdated examples
boehm-e May 10, 2019
7e10492
updating doc & remove unupdated examples
boehm-e May 10, 2019
edec3d2
updating doc & remove unupdated examples
boehm-e May 10, 2019
11e5c05
updating doc & remove unupdated examples
boehm-e May 10, 2019
9e6a698
updating doc & remove unupdated examples
boehm-e May 10, 2019
a1ce5dd
updating doc & remove unupdated examples
boehm-e May 10, 2019
7429ddf
updating doc & remove unupdated examples
boehm-e May 10, 2019
b500a1e
updating doc & remove unupdated examples
boehm-e May 10, 2019
71e4c60
updating doc & remove unupdated examples
boehm-e May 10, 2019
6ab1574
updating doc & remove unupdated examples
boehm-e May 10, 2019
0a43a97
updating doc & remove unupdated examples
boehm-e May 10, 2019
71fbd0b
updating doc & remove unupdated examples
boehm-e May 10, 2019
bc4360a
updating doc & remove unupdated examples
boehm-e May 10, 2019
e5dc9c5
updating doc & remove unupdated examples
boehm-e May 10, 2019
0ce3fd2
updating doc & remove unupdated examples
boehm-e May 10, 2019
591fdd9
updating doc & remove unupdated examples
boehm-e May 10, 2019
092660b
updating doc & remove unupdated examples
boehm-e May 10, 2019
d956539
updating doc & remove unupdated examples
boehm-e May 10, 2019
e3c9fc5
updating doc & remove unupdated examples
boehm-e May 10, 2019
9f89568
adding option to enable augmented iamges
boehm-e May 12, 2019
02047b7
adding HitPose
boehm-e May 12, 2019
258545b
comment future work with plane
boehm-e May 13, 2019
ba179fe
adding plane api
boehm-e May 14, 2019
bffdae3
adding plane api
boehm-e May 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .img/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .img/demo.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .img/dl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
215 changes: 202 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,220 @@
<a href="https://play.google.com/store/apps/details?id=cc.openframeworks.ardrawing">
<img src=".img/dl.png" width="200"/>
</a>

# 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.

<div style="position: relative; width: 90%; height: 100%; margin-left:5%; margin-right: 5%;display: flex; justify-content: center; float: left;">
<img align="left" src=".img/demo.gif" style="padding-left:1%; padding-right:1%" width="45%" />
<img align="left" src=".img/demo.webp" style="padding-left:1%; padding-right:1%" width="50%" />
</div>


![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<ofMatrix4x4> 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<float> 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<ofAugmentedImage*> 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<ofARPlane*> 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();
```
36 changes: 0 additions & 36 deletions exampleBasic/.gitignore

This file was deleted.

28 changes: 0 additions & 28 deletions exampleBasic/AndroidManifest.xml

This file was deleted.

1 change: 0 additions & 1 deletion exampleBasic/addons.make

This file was deleted.

Loading