Question

I'm currently learning some drawing techniques in Android by overwriting the onDraw method of my custom view. I just recently wanted to draw a circle and flip the circle on its y axis. Just like a coin flip. But somehow, it looks like the circle is wobbling around something but not on the y axis itself. See video:

www.youtube.com/watch?v=lehDAYKZ6vk&feature=youtu.be

Here is the peace of code I’m using in my onDraw method:

canvas.save();

mCamera.save();
mCamera.rotateY(rotation);

mCamera.getMatrix(mMatrix);

float CenterX = circle.getX();
float CenterY = circle.getY();

mMatrix.preTranslate(-CenterX, -CenterY); 

mMatrix.postTranslate(CenterX, CenterY);

mCamera.restore();
canvas.concat(mMatrix);

canvas.restore();

The code is almost identical to the one in the following tutorial:

www.inter-fuser.com/2009/08/android-animations-3d-flip.html

In the tutorial above, the flip animation seem to work without wobbling even with the same piece of code.

Am I doing something wrong? Are there any other solutions to achieve the flip?

It seems like the perspective of the canvas will be drawn wrong.

Thanks in advance!

Était-ce utile?

La solution

Resolved the problem by setting

mCamera.setLocation(0,0,-100) 

The rotation perspective will be drawn correctly now.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top