チーム制作 5 [ 分担作業(画像を裏返すクラス) ]
[ 画像の表示 ]
3Dっぽく画像を裏返すイメージ。
参考にしようと見たページでしてたのはViewを裏返し
2枚用意した画像を見える状態にするか隠すかを変更するもの。
他にも色々検索してはホームページを見る作業で数日経過+q+
どうすればいいかK氏に相談したところ同じことをMatrixに適用してはどうかということ。
そこで抜き出してくれたのが以下のようなもの
//matrix.reset();
//rotate3DMatrix(matrix, duration, bitmap.getWidth()/2,
// bitmap.getHeight()/2, 100);
//matrix.postScale(scale, scale);
/**
* 引数のtargetMatrixを3D回転したように変更する。
* @param targetMatrix
* @param degrees 角度
* @param centerX 3D回転する際の中心のx座標?
* @param centerY 3D回転する際の中心のy座標?
* @param depthZ ?
* @return
*/
public void rotate3DMatrix(Matrix targetMatrix,
float angle,float centerX, float centerY,float depthZ){
Camera camera = new Camera();
camera.save();
camera.translate(0.0f, 0.0f, depthZ);
camera.rotateY(angle);
camera.getMatrix(targetMatrix);
camera.restore();
targetMatrix.preTranslate(-centerX, -centerY);
targetMatrix.postTranslate(centerX, centerY);
}
そしてこれを見てもこのときの自分には意味不明。よくわからず。
その間にK氏は真ん中に表示するだけのクラス[ StayGoki ]を作成。
StayGoki.java
------------------------------
public class StayGoki extends SuperGoki{
protected Context context;
protected float currentX;
protected float currentY;
protected float angle;
protected float scale;
private final Matrix matrix = new Matrix();
private final Matrix inverse = new Matrix();
private int dx = 20;
// context,gokiSurfase,currentX,currentY,angle,scaleを指定する
// コンストラクタ。
public StayGoki(Context context){
super(context);
this.currentX = 30;
this.currentY = 50;
this.angle = 0;
this.scale = 2.0f;
}
// canvasのsave,restore,背景描画は、GokiSurfaceで行っており、
// ここで記述するのは、このGokiの分の絵だけ。
// このGokiは、いるだけなので、
// 現行では、現在位置を起点にして、dxだけ左右に振っているだけ。
public void draw(Canvas canvas) {
this.currentX += dx;
this.dx = -dx;
matrix.setScale(scale, scale);
matrix.postTranslate(currentX, currentY);
// matrixの逆変換をinverseに設定する(touchのため)。
matrix.invert(inverse);
canvas.drawBitmap(getAntennaBitmap(0), matrix, null);
canvas.drawBitmap(getBodyBitmap(0), matrix, null);
}
@Override
public int getID() {
return 0;
}
}
-----------------------------------------------------
これを見て表示方法は把握。
あとはこのmatrixを上記のメソッドを使用して回転を実装するだけ。
だけ・・・