www.jpct.net

Bones - Skeletal and Pose Animations for jPCT/jPCT-AE => Bones => Topic started by: cefengxu on November 02, 2015, 10:09:34 am

Title: [ resolved]rendering a model on correct mark position in ARToolkit
Post by: cefengxu on November 02, 2015, 10:09:34 am
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();
}
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: raft 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
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: cefengxu 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
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: raft on November 02, 2015, 06:37:20 pm
yes, md2 models are also in a different coordinate space (http://www.jpct.net/wiki/index.php?title=Coordinate_system)

try this after calling a.setRotationMatrix(..)

Code: [Select]
a.rotateX( (float) Math.PI / 2 );
a.rotateZ( (float) Math.PI );
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: cefengxu on November 03, 2015, 02:57:06 am
have tried , and then the model was missing~~~
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: raft 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?

Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: cefengxu 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);
}
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: raft 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);
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: cefengxu 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
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: raft 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
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: cefengxu 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.
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: raft on November 03, 2015, 01:24:35 pm
well, I'm not totally sure about that
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: cefengxu 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
Title: Re: [ Question ]rendering a model on correct mark position in ARToolkit
Post by: EgonOlsen 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... ;)
Title: Re: [ resolved]rendering a model on correct mark position in ARToolkit
Post by: raft 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