绘制在画布上两个3D字符串?画布、字符串、两个

2023-09-07 09:19:10 作者:不肯过活

我要借鉴canvas.Strings 2字符串必须在相同的坐标,然后第二个字符串可以得出一定是旋转的第一串绕轴Y.The结果45度必须是这样的结果:

I have to draw 2 Strings on canvas.Strings must be drawn with the same coordinates and second string must be result of rotating first string 45 degrees around axis Y.The result must looks like this:

这是我的code:

Matrix matrix = new Matrix();
matrix = canvas.getMatrix();
mCamera = new Camera();


canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);

matrix.preTranslate(30, 100);
//      matrix.postTranslate(-30, -100);

canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 0, 0, greenPaint);

但是,上述code的结果是:

But result of above code is:

您可以看到,坐标串都不同。所以我做了什么错了吗?我想,这是不正确的参数为基质。preTranslate引起()

You can see that coordinates of strings are different.So what did I do wrong?I guess that it is be caused by incorrect arguments for matrix.preTranslate().

更新

我改变我的code这样的:

I change my code like:

canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(-30, -100);
matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 0, 0, greenPaint);

或类似:

canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(-30, -100);
//matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 0, 0, greenPaint);

或类似:

canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);

matrix.preTranslate(-30, -100);
//      matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 30, 100, greenPaint);

和所有三个以上codeS,结果是这样的:

And for all three above codes, result looks like this:

我想这第二个文本绘制超出范围或状态栏的后面,所以它是不可见的。

I guess that second text is drawn out of range or behind the status bar and so it is not visible.

然后改变我的code到:

Then change my code to:

mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(-30, -100);
matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 30, 100, greenPaint);

结果:

推荐答案

感谢replies.I解决了疑难问题必须使用 canvas.concat()而不是 canvas.setMatrix 。这是正确的code:

Thanks for replies.I solved the problem.I have to use canvas.concat() instead of canvas.setMatrix.This is correct code:

Matrix matrix = new Matrix();
mCamera = new Camera();

canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(60);
mCamera.getMatrix(matrix);

matrix.preTranslate(-30, -100);
matrix.postTranslate(30, 100);
canvas.concat(matrix);
canvas.drawText("In the name of God", 30, 100, greenPaint);