渲染上JPCT-AE模型基本与Android的ARToolkit [英] Rendering a model basic on JPCT-AE with ARToolkit in Android

查看:1290
本文介绍了渲染上JPCT-AE模型基本与Android的ARToolkit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想渲染通过JPCT-AE模式和使用用于将ARToolKit来实现AR应用。

i want to render model via JPCT-AE and use the ARToolkit to realizing AR Application.

所以,我注入code如下成用于将ARToolKit项目:

so , i inject the code as below into the ARToolkit Project:

    Matrix projMatrix = new Matrix();
    projMatrix.setDump(ARNativeActivity.getProjectM());
    projMatrix.transformToGL();
    SimpleVector translation = projMatrix.getTranslation();
    SimpleVector dir = projMatrix.getZAxis();
    SimpleVector up = projMatrix.getYAxis();
    cameraController.setPosition(translation);
    cameraController.setOrientation(dir, up);

    Matrix transformM = new Matrix();
    transformM .setDump(ARNativeActivity.getTransformationM());
    transformM .transformToGL();

    model.clearTranslation();
    model.translate(transformM .getTranslation());

    dump.setRow(3,0.0f,0.0f,0.0f,1.0f);
    model.clearRotation();
    model.setRotationMatrix(transformM );  

然后,该模型可以呈现在屏幕上,但总是在屏幕躺在大关,不论我用model.rotateX / Y / Z((浮点)Math.PI / 2);

And then , the model can be render on the screen but always lie on the mark in the screen, ever i using model.rotateX/Y/Z( (float)Math.PI/2 );

其实,从用于将ARToolKit :: ARNativeActivity.getTransformationMatrix()输出矩阵是正确的,然后我分裂这个4 * 4Matrix到平移矩阵和旋转矩阵,并设置成这样的模式:

Actually, the matrix output from the ARToolkit::ARNativeActivity.getTransformationMatrix() is correct, and then i split this 4*4Matrix into translation Matrix and Rotation Matrix and set into the model like this:

model.translate(transformM .getTranslation());
model.setRotationMatrix(transformM ); 

但仍然没有工作。

But still no work.

推荐答案

我会建议更好地组织你的code,以及矩阵的工作分开进行转换,使您的模型,并进行转换,在模型中放置标记。

I would suggest to organize better your code, and work with matrices to separate the transformations to make to your model and the transformations to place the model in the marker.

我的建议是:

首先,使用一个额外的矩阵。它可以被称为modelMatrix,因为它将存储做模型(缩放,旋转和平移)转化

First, use an additional matrix. It may be called modelMatrix, as it will store the transformation done to the model (scale, rotation and translation).

然后,声明所有矩阵这个方法(它是唯一的表现的原因,但推荐)外,每帧只是setIdentity给他们:

Then, declare all matrices outside this method (it is for performance reasons only, but is recommended), and on each frame simply setIdentity to them:

projMatrix.setIdentity();
transformM.setIdentity();
modelM.setIdentity();

后,使对modelM矩阵模型转换。这种变换将适用于模型,放置在标记之后

later, make the model transformations on the modelM matrix. This transformations will apply to the model, after placed on the marker.

modelM.rotateZ((float) Math.toRadians(-angle+180));
modelM.translate(movementX, movementY, 0);

然后,由trasnformM乘以modelM矩阵(这意味着你得到所有转换完成,而移动和旋转它们作为transformM描述,这在我们的情况下,意味着做模型中的所有的转化都是在上面移动标记)。

then, multiply the modelM matrix by the trasnformM (this means you get all the transformations done, and move and rotate them as the transformM describes, which in our case means that all the transformations done to the model are moved on top of the marker).

//now multiply trasnformationMat * modelMat
modelM.matMul(trasnformM);

最后,应用旋转和平移给你的模型:

And finally, apply the rotation and translation to your model:

model.setRotationMatrix(modelM);
model.setTranslationMatrix(modelM);

所以整个code将如下:

so the whole code would look as:

projMatrix.setIdentity();
projMatrix.setDump(ARNativeActivity.getProjectM());
projMatrix.transformToGL();
SimpleVector translation = projMatrix.getTranslation();
SimpleVector dir = projMatrix.getZAxis();
SimpleVector up = projMatrix.getYAxis();
cameraController.setPosition(translation);
cameraController.setOrientation(dir, up);

model.clearTranslation();
model.clearRotation();

transformM.setIdentity();
transformM .setDump(ARNativeActivity.getTransformationM());
transformM .transformToGL();

modelM.setIdentity()
//do whatever you want to your model
modelM.rotateZ((float)Math.toRadians(180));

modelM.matMul(transformM);

model.setRotationMatrix(modelM );  
model.setTranslationMatrix(modelM);

我强烈reccomend看约矩阵和OpenGL <这个教程/ A>,它是不是JPCT,但所有的概念,可申请也有,这是我用正确放置模型与ARSimple例如标记,你可能在<一见href=\"https://passospetits.word$p$pss.com/2015/12/28/augmented-reality-3d-with-jpct-ae-and-artoolkit/\"相对=nofollow>这篇博客我做

希望这有助于!

这篇关于渲染上JPCT-AE模型基本与Android的ARToolkit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆