[Artoolkit] ARSimpleNativeCarsProj for Multi Markers Tracking
效果简直了,但代码架构有点坑,慢慢道来。

libc++_shared.so应该是c++的库;libARWrapperNativeCaresExample.so也有对应的c++文件;那么,libARWrapper.so从哪里来?下一章节讲。

ARSimpleNativeCarsActivity
Java层的封装,注意ARActivity。

public abstract class ARActivity extends Activity implements CameraEventListener {}
public class ARSimpleNativeCarsActivity extends ARActivity {
private SimpleNativeRenderer simpleNativeRenderer = new SimpleNativeRenderer();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onStop() {
SimpleNativeRenderer.demoShutdown();
super.onStop();
}
@Override
protected ARRenderer supplyRenderer() { // ARACTIVITY到底是何方神圣?它的设计理念是什么?
return simpleNativeRenderer;
}
@Override
protected FrameLayout supplyFrameLayout() {
return (FrameLayout) this.findViewById(R.id.mainLayout);
}
}
[ARActivity] 的理解很重要!不过,先来看 [SimpleNativeRenderer]。 <-- 【一对好兄弟!】
public class SimpleNativeRenderer extends ARRenderer { // 重在实现 ARRenderer 的接口
// Load the native libraries.
static {
System.loadLibrary("c++_shared");
System.loadLibrary("ARWrapper");
System.loadLibrary("ARWrapperNativeCarsExample");
}
private FPSCounter counter = new FPSCounter();
/****************************************************************/
public static native void demoInitialise();
public static native void demoShutdown(); // --> 在哪里用到了呢?
public static native void demoSurfaceCreated();
public static native void demoSurfaceChanged(int w, int h);
public static native void demoDrawFrame();
/****************************************************************/
/**
* By overriding {@link #configureARScene}, the markers and other settings can be configured
* after the native library is initialised, but prior to the rendering actually starting.
* Note that this does not run on the OpenGL thread. Use onSurfaceCreated/demoSurfaceCreated
* to do OpenGL initialisation.
*/
@Override
public boolean configureARScene() {
SimpleNativeRenderer.demoInitialise();
return true;
}
@Override
public void onSurfaceChanged(GL10 gl, int w, int h) {
super.onSurfaceChanged(gl, w, h);
SimpleNativeRenderer.demoSurfaceChanged(w, h);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated(gl, config);
SimpleNativeRenderer.demoSurfaceCreated();
}
@Override
public void draw(GL10 gl) {
SimpleNativeRenderer.demoDrawFrame();
if (counter.frame()) Log.i("demo", counter.toString());
}
}
The ARActivity class is an extension of the Activity class, used for displaying the camera feed and AR content. Make sure any activities in your project used to display AR content are extensions of ARActivity.
The ARRenderer is a singleton class used for rendering the camera image and AR content on screen.
接下来,让我欣赏下NDK的实现:
NDK
1. 主要是加载marker, model。( ** 与NFT应该有所不同,需进一步分析 ** )
JNIEXPORT void JNICALL JNIFUNCTION_DEMO(demoInitialise(JNIEnv* env, jobject object)) {
const char *model0file = "Data/models/Porsche_911_GT3.obj"; // 3D model
const char *model1file = "Data/models/Ferrari_Modena_Spider.obj";
//////////////////////////////////////////////////////////////////////////////////////////////////////
models[].patternID = arwAddMarker("single;Data/hiro.patt;80"); // Marker
arwSetMarkerOptionBool(models[].patternID, ARW_MARKER_OPTION_SQUARE_USE_CONT_POSE_ESTIMATION, false);
arwSetMarkerOptionBool(models[].patternID, ARW_MARKER_OPTION_FILTERED, true);
models[].obj = glmReadOBJ2(model0file, , ); // context 0, don't read textures yet.
if (!models[].obj) {
LOGE("Error loading model from file '%s'.", model0file);
exit(-);
}
glmScale(models[].obj, 0.035f);
//glmRotate(models[0].obj, 3.14159f / 2.0f, 1.0f, 0.0f, 0.0f);
glmCreateArrays(models[].obj, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE);
models[].visible = false;
//////////////////////////////////////////////////////////////////////////////////////////////////////
models[].patternID = arwAddMarker("single;Data/kanji.patt;80");
arwSetMarkerOptionBool(models[].patternID, ARW_MARKER_OPTION_SQUARE_USE_CONT_POSE_ESTIMATION, false);
arwSetMarkerOptionBool(models[].patternID, ARW_MARKER_OPTION_FILTERED, true);
models[].obj = glmReadOBJ2(model1file, , ); // context 0, don't read textures yet.
if (!models[].obj) {
LOGE("Error loading model from file '%s'.", model1file);
exit(-);
}
glmScale(models[].obj, 0.035f);
//glmRotate(models[1].obj, 3.14159f / 2.0f, 1.0f, 0.0f, 0.0f);
glmCreateArrays(models[].obj, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE);
models[].visible = false;
}
2. 似乎也没做什么。
JNIEXPORT void JNICALL JNIFUNCTION_DEMO(demoSurfaceCreated(JNIEnv* env, jobject object)) {
glStateCacheFlush(); // Make sure we don't hold outdated OpenGL state.
for (int i = ; i < NUM_MODELS; i++) {
if (models[i].obj) {
glmDelete(models[i].obj, ); // init GLMmodel这个结构体 -->
models[i].obj = NULL;
}
}
}
typedef struct ARModel {
int patternID;
ARdouble transformationMatrix[];
bool visible;
GLMmodel* obj;
} ARModel;
3. 有了unity,是不是就可以忽略这些了呢?需求证。
JNIEXPORT void JNICALL JNIFUNCTION_DEMO(demoDrawFrame(JNIEnv* env, jobject obj)) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set the projection matrix to that provided by ARToolKit.
float proj[];
arwGetProjectionMatrix(proj);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(proj);
glMatrixMode(GL_MODELVIEW);
glStateCacheEnableDepthTest();
glStateCacheEnableLighting();
glEnable(GL_LIGHT0);
for (int i = ; i < NUM_MODELS; i++) {
models[i].visible = arwQueryMarkerTransformation(models[i].patternID, models[i].transformationMatrix);
if (models[i].visible) {
glLoadMatrixf(models[i].transformationMatrix);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glmDrawArrays(models[i].obj, );
}
}
}
看来,arBaseLib的分析是重点。
[Artoolkit] ARSimpleNativeCarsProj for Multi Markers Tracking的更多相关文章
- 本人AI知识体系导航 - AI menu
Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯 徐亦达老板 Dirichlet Process 学习 ...
- 【AR实验室】ARToolKit之Example篇
0x00 - 前言 PS : 我突然意识到ARToolKit本质可能就是一个可以实时求解相机内外参的解决方案. 拿到一个新的SDK,90%的人应该都会先跑一下Example.拿到ARToolKit的S ...
- [Artoolkit] ARToolKit's SDK Structure on Android
Most applications on Android are developed in Java, and Android provides a rich framework of classes ...
- [Artoolkit] Framework Analysis of nftSimple
What is nftSimple? Loads NFT dataset names from a configuration file. The example uses the “Pinball. ...
- [Artoolkit] Marker of nftSimple
重点看:markers.dat 的解析原理 1. int main(int argc, char** argv) { ]; const char *cparam_name = "Data2/ ...
- [译] AR SDK的种类比你想得要多!这里介绍七个棒棒哒
作者:Eddie Offermann 原文:There are dozens more Augmented Reality SDKs than you think! Here are seven gr ...
- [Artoolkit] kpmMatching & Tracking of nftSimple
1. kpmMatching thread main() --> loadNFTData() --> trackingInitInit() --> In static void *t ...
- 【AR实验室】ARToolKit之制作自己的Marker/NFT
0x00 - 前言 看过example后,就会想自己动动手,这里改改那里修修.我们先试着添加自己喜欢的marker/nft进行识别. 比如我做了一个法拉利的marker: 还有网上找了一个法拉利log ...
- [Artoolkit] Marker Training
Link: Documentation About the Traditional Template Square Marker Limitations (重要) Traditional Templa ...
随机推荐
- linux 校准时间
ntpdate cn.pool.ntp.org //查看硬件时间可以是用hwclock,hwclock --show 或者hwclock -r [root@localhost ~]# hwclock ...
- java:@SuppressWarnings注解
简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的警告, ...
- iOS 跳转到系统指定设置界面
在需要调转的按钮动作中添加如下的代码,就会跳转到设置中自己的app的设置界面,这里会有通知和位置权限的设置 NSURL * url = [NSURLURLWithString:UIApplicatio ...
- .NET 并行编程——数据并行
本文内容 并行编程 数据并行 环境 计算 PI 矩阵相乘 把目录中的全部图片复制到另一个目录 列出指定目录中的所有文件,包括其子目录 最近,对多线程编程,并行编程,异步编程,这三个概念有点晕了,之前我 ...
- ASP.NET CORE 之 在IIS上部署MVC项目
与ASP.NET时代不同,ASP.NET Core不再是由IIS工作进程(w3wp.exe)托管,而是使用自托管Web服务器(Kestrel)运行,IIS则是作为反向代理的角色转发请求到Kestrel ...
- 《Unix&Linux大学教程》学习笔记6——Unix文件系统
1:Unix文件类型——3种 普通文件(常规文件):文本文件(纯文本.脚本.源程序.配置文件.html等).二进制文件(多媒体文件.数据库等) 目录:用于组织文件 伪文件:不存储数据,目的是提供一种服 ...
- <转>vmp3.0.9全保护拆分解析
以下为了避免插件干扰,故采用x64dbg原版进行分析. 首先我通过检测到调试器的弹窗进行栈回溯,定位到该关键点:CALL eax 由于才接触Vmp,所以是把各个保护拆分开来进行的分析,会比较简单一 ...
- SNF.CodeGenerator代码生成器前夕-代码生成器初始配置
如果你是第一次使用SNF快速开发平台的话,第一次运行代码生成器的话,可以需要以下信息来帮助你快速进行配置和使用. 代码生成器在使用之前有几个地方需要配置,如果是第一次登录会提示无授权,弹出一个框填入授 ...
- MUI中等待框的H5实现
MUI没有内置的那个弹出转圈圈的那个等待框,那个nativeui.showwaiting是只能用于app中的,不能用在H5网页中的,网上找了下,找到个别人已经写好的,自己 测试了下没问题,先记下来 @ ...
- 如何在TextView类中创建超链接 Linkify
Linkify是一个辅助类,通过RegEx样式匹配,自动地在TextView类(和继承的类)中创建超链接.符合特定的RegEx样式的文本会被转变成可点击的超链接,这些超链接隐式的调用startActi ...