3d cube using canvas. Need a little improvement

无人久伴 提交于 2019-12-06 06:24:45

问题


I made this 3d cube using the following code

Matrix mMatrix = canvas.getMatrix();

canvas.save();
camera.save();
camera.rotateY(-angle);
camera.getMatrix(mMatrix);
mMatrix.preTranslate(-width, 0);
mMatrix.postTranslate(width, 0);
canvas.concat(mMatrix);
canvas.drawBitmap(bmp1, 0, 0, null);
camera.restore();
canvas.restore();

camera.rotateY(90 - angle);
camera.getMatrix(mMatrix);
mMatrix.preTranslate(-width, 0);
mMatrix.postTranslate(width2, 0);
canvas.concat(mMatrix);
canvas.drawBitmap(bmp2, width, 0, null);

This is what it gives

But what I need is

It's because when Camera rotates the images, some part of the image gets hidden. Like this

But I think this can be done.


回答1:


It was pretty easy actually. The image had to be translated by half it's width/height along the axis it was being rotated.

So the following changes did it

mMatrix.preTranslate(-width, -height / 2);
mMatrix.postTranslate(width, height / 2);


来源:https://stackoverflow.com/questions/12205462/3d-cube-using-canvas-need-a-little-improvement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!