在画布上绘制两个3D字符串? [英] Drawing two 3D strings on Canvas?
问题描述
我必须在canvas上绘制2个字符串。字符必须用相同的坐标来绘制,第二个字符串必须是第一个字符串绕轴Y旋转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:
>
这是我的代码:
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);
但上述代码的结果是:
您可以看到字符串的坐标是不同的。我做错了什么?我想这是由 matrix.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()
.
更新:
我更改我的代码:
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);
对于上述三个代码,结果如下:
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.
然后将我的代码更改为:
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);
结果:
推荐答案
感谢回复。我解决了问题。我必须使用 canvas.concat()
而不是 canvas.setMatrix
。这是正确的代码:
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);
这篇关于在画布上绘制两个3D字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!