android 3D旋轉效果實現

來源:互聯網
上載者:User

標籤:

一說到3D,可能第一反應就是使用OpenGL ES。。。。但是,實現這麼個小功能,要動用這玩意,莫名的恐懼啊!!!!至今也沒弄明白這個怎麼玩。。。

好吧,幸虧還有個Camera類可以協助我們,據說底層實現實現也是使用的是OpenGL ES 

注意:使用的是android.graphics.Camera  

話不多說了,直接上代碼:

public class _3DAnimation extends Animation {    private  float mFromDegrees;    private  float mToDegrees;    private  float mCenterX;    private  float mCenterY;    private Camera mCamera;    public  _3DAnimation(float fromDegress,float toDegress){        this.mFromDegrees=fromDegress;        this.mToDegrees=toDegress;    }    @Override    public void initialize(int width, int height, int parentWidth, int parentHeight) {        super.initialize(width, height, parentWidth, parentHeight);        this.mCenterX=width/2;        this.mCenterY=height/2;        mCamera=new Camera();    }    @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {        super.applyTransformation(interpolatedTime, t);        final float fromDegrees = mFromDegrees;        float degrees = fromDegrees + (mToDegrees - mFromDegrees) * interpolatedTime;        final Matrix matrix = t.getMatrix();        //interpolatedTime 0~1變化        mCamera.save();        mCamera.rotateY(degrees);        mCamera.getMatrix(matrix);        mCamera.restore();        matrix.preTranslate(-mCenterX, -mCenterY);//相機位於(0,0),移動圖片,相機位於圖片中心        matrix.postTranslate(mCenterX, mCenterY);    }}

 

android 3D旋轉效果實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.