Google

Sunday, July 11, 2010

Android 3D Camera class


Note that 3D Camera class is not the physical camera of the phone. It is a 3D Class that provides 3D to objects in 2D.


Use the same ViewAnimation.java class from the previous post, and change the method applyTransformation as follows:

   protected void applyTransformation(float interpolatedTime, Transformation t) {
float centerX = (float)v.getWidth()/2, centerY = (float)v.getHeight()/2;
final android.graphics.Matrix matrix = t.getMatrix();
camera.save();
camera.translate(0.0f, 0.0f, (1300 - 1300.0f * interpolatedTime));
camera.rotateY(360 * interpolatedTime);
camera.getMatrix(matrix);
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
camera.restore();
}


Note that you could also experiment with the following:

        camera.rotateY(360 * interpolatedTime); 
camera.rotateX(360 * interpolatedTime);
camera.rotateZ(360 * interpolatedTime);