3

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

enter image description here

But what I need is

enter image description here

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

But I think this can be done.

timemanx
  • 4,493
  • 6
  • 34
  • 43

1 Answers1

2

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);
timemanx
  • 4,493
  • 6
  • 34
  • 43
  • @Vivekanand The code is in the question. Use it after making the changes in the answer. – timemanx Mar 24 '13 at 06:36
  • I'm sorry for being so informal, its because of the desperate situation. I dont really want the complete code some tutorial of to how the implementation is done would be appreciated, thanks – Vivekanand Mar 25 '13 at 06:33
  • @ShubhadeepChaudhuri, can u please share the code for creating 3d cube – Reprator Oct 22 '17 at 18:33