[ resolved]rendering a model on correct mark position in ARToolkit

Started by cefengxu, November 02, 2015, 10:09:34 AM

Previous topic - Next topic

cefengxu

Hi raft :

the model can be rendering according to you support .

However , the model can not be rendered in correct position ( the rotation is no right , as shown as attached)

case 1 : using the function : model.rotateXYZ(float r) : result : the model could no be in correct angle , some time the model  even missing ;
case 2 : the matrix output from ARToolkit is correct Definitely , because i have verified via rendering a cube through OpenGL ES ;
case 3 : such bug still exists in JPCT-AE;

but i still do not know how to do. so  do you have some idea about it ?

the code was shown as belown:


public void onDrawFrame(GL10 unused) {
//...
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);
//...
for (Animated3D a : group) {
a.animate(index, animation);
Matrix dump = new Matrix();
dump.setDump(ARNativeActivity.getTransformationM());
dump.transformToGL();
a.clearTranslation();
a.translate(dump.getTranslation());
a.setRotationMatrix(dump);
Log.i("jpct_test", "runing in loop 2");
}
//...
world.renderScene(frameBuffer);
world.draw(frameBuffer);
frameBuffer.display();
}

raft

it's possibly because of coordinate space difference between blender and jPCT. you need to rotate your model accroding to that after you applied those transforms (check wiki for details). or better load your model into Bones with proper rotation. scripts accept rotation parameter for that

cefengxu

i used the jpct-ae to load a md2 model but the result is the same( the model still lied on the mark  but the position is right).

i think it should be caused by the camera up / direction , but i not sure, i cann't handle this~~~~~~~~~

may be i have to will try again later , thanks

raft

yes, md2 models are also in a different coordinate space

try this after calling a.setRotationMatrix(..)

a.rotateX( (float) Math.PI / 2 );
a.rotateZ( (float) Math.PI );

cefengxu


raft

looks like your obejcts are rotating around some weird pivot. are you calling setRotationPivot on any of your objects?


cefengxu

yes , it  seems be call from Bones / SkeletonDebugger.java

private static Object3D createPyramide(SimpleVector from, SimpleVector to, float scale) {
    p.setRotationPivot(SimpleVector.ORIGIN);
}

raft

it has no effect on your objects.

try calling this on each of your obejcts before entering that loop, it's enough to call this method once

a.setRotationPivot(SimpleVector.ORIGIN);

cefengxu

actually, the matrix output from the ARToolkit::ARNativeActivity.getTransformationMatrix() is correct and the result of matrix  be such like this:

Orange Color : the rotation info  Green  Color: the translation info

  0.9592849       0.042872142   -0.27916315    0.0
  0.161977        -0.8932123         0.41944835    0.0
-0.23136866   -0.44758964      -0.86379063    0.0
-58.357327     38.013783            381.9324        1.0


so i think i just set the translation and  rotation for the model and the result should be right. and then i set up to  jpct-matrix and set into the model like this:

Matrix dump = new Matrix();
dump.setDump(ARNativeActivity.getTransformationM());
dump.transformToGL();
                 
a.clearTranslation();
a.translate(dump.getTranslation());      //   the translation could be sure that it's right because the model can translate through the mark on the screen
                 
a.clearRotation();


a.setRotationMatrix(dump);   // and then the model lied on the mark


dump.rotateX/Y/Z((float)Math.PI/2);    i try to use matrix rotation to rotate the model before process  a.setRotationMatrix(dump) , but no work , the model some time will missing

raft

mm, that may be the cause, i.e, you are setting the rotation matrix which has translation. I'm not sure how rotation should behave that way. @EgonOlsen can clarify this.

you can try clearing translation in rotation matrix before setting in on object.
matrix.setRow(3,0,0,0)

this should do it I believe

cefengxu

matrix.setRow(3,0f,0f,0f,0f); this is the same and no use, because the function: a.setRotationMatrix(dump);
just using the  3*3 matrix in dump to process the rotation.

raft


cefengxu

at the end , i have to change the rotation of the model in blender firstly, and then the rendering result is correct......

Thanks

EgonOlsen

You can do that in code as well. As I mentioned in the other thread, you can load the model, apply the rotation and call rotateMesh() to make it permanent. However, raft is right about the translation in the rotation matrix. It actually doesn't belong there and it WILL be used in the transformation process. I've no idea why it seems to work anyway, but as long as it does... ;)

raft

rotateMesh() will possibly break the animation. it actually rotates the mesh as the name implies, right?
that's why Bones support rotating the model at the time of loading, like:

-rotation x180,y90