Skip to content Skip to sidebar Skip to footer

Rendering A Model Basic On Jpct-ae With Artoolkit In Android

i want to render model via JPCT-AE and use the ARToolkit to realizing AR Application. so , i inject the code as below into the ARToolkit Project: Matrix projMatrix = new Matri

Solution 1:

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.

What I suggest is:

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

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();

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);

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);

so the whole code would look as:

projMatrix.setIdentity();
projMatrix.setDump(ARNativeActivity.getProjectM());
projMatrix.transformToGL();
SimpleVectortranslation= projMatrix.getTranslation();
SimpleVectordir= projMatrix.getZAxis();
SimpleVectorup= 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);

I strongly reccomend to look at this tutorial about matrices and OpenGL, it is not about JPCT, but all concepts may apply also to there, and it is what I've used to place correctly models in markers with the ARSimple example as you may see in this blog entry I made.

Hope this helps!

Post a Comment for "Rendering A Model Basic On Jpct-ae With Artoolkit In Android"