Author Topic: [ resolved]rendering a model on correct mark position in ARToolkit  (Read 1687 times)

Offline cefengxu

  • int
  • **
  • Posts: 65
    • View Profile
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:

Code: [Select]
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();
}
« Last Edit: November 05, 2015, 07:47:27 am by cefengxu »

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #1 on: November 02, 2015, 02:31:14 pm »
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

Offline cefengxu

  • int
  • **
  • Posts: 65
    • View Profile
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #2 on: November 02, 2015, 04:55:06 pm »
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

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #3 on: November 02, 2015, 06:37:20 pm »
yes, md2 models are also in a different coordinate space

try this after calling a.setRotationMatrix(..)

Code: [Select]
a.rotateX( (float) Math.PI / 2 );
a.rotateZ( (float) Math.PI );

Offline cefengxu

  • int
  • **
  • Posts: 65
    • View Profile
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #4 on: November 03, 2015, 02:57:06 am »
have tried , and then the model was missing~~~

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #5 on: November 03, 2015, 08:52:17 am »
looks like your obejcts are rotating around some weird pivot. are you calling setRotationPivot on any of your objects?


Offline cefengxu

  • int
  • **
  • Posts: 65
    • View Profile
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #6 on: November 03, 2015, 12:36:35 pm »
yes , it  seems be call from Bones / SkeletonDebugger.java

Code: [Select]
private static Object3D createPyramide(SimpleVector from, SimpleVector to, float scale) {
    p.setRotationPivot(SimpleVector.ORIGIN);
}

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #7 on: November 03, 2015, 12:51:02 pm »
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

Code: [Select]
a.setRotationPivot(SimpleVector.ORIGIN);

Offline cefengxu

  • int
  • **
  • Posts: 65
    • View Profile
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #8 on: November 03, 2015, 12:53:34 pm »
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

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #9 on: November 03, 2015, 12:59:36 pm »
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.
Code: [Select]
matrix.setRow(3,0,0,0)
this should do it I believe

Offline cefengxu

  • int
  • **
  • Posts: 65
    • View Profile
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #10 on: November 03, 2015, 01:21:00 pm »
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.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #11 on: November 03, 2015, 01:24:35 pm »
well, I'm not totally sure about that

Offline cefengxu

  • int
  • **
  • Posts: 65
    • View Profile
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #12 on: November 05, 2015, 07:46:35 am »
at the end , i have to change the rotation of the model in blender firstly, and then the rendering result is correct......

Thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: [ Question ]rendering a model on correct mark position in ARToolkit
« Reply #13 on: November 05, 2015, 07:49:26 am »
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... ;)

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: [ resolved]rendering a model on correct mark position in ARToolkit
« Reply #14 on: November 05, 2015, 09:37:57 am »
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:

Code: [Select]
-rotation x180,y90