3D立方体使用画布。需要一点点的改进 [英] 3d cube using canvas. Need a little improvement

查看:128
本文介绍了3D立方体使用画布。需要一点点的改进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code使这个3D立方体

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);

这是什么给了

不过,我需要的是

这是因为当摄像机旋转的图像,图像的一些部分被隐藏起来。 像这样的

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

但我认为这是可以做到。

But I think this can be done.

推荐答案

这是pretty的方便实际。图像必须减半翻译它的宽度/高度沿着它旋转的轴。

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

所以下面的变化做了

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

这篇关于3D立方体使用画布。需要一点点的改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆