zoukankan      html  css  js  c++  java
  • android 自定义动画1 Rotate3dAnimation

    android 里的2d动画有tween 和frame, 像镜面反转这种动画它内部没有提供支持, 上网查了一下.有人写了这个效果, 但是写得怎一个乱字了得, 又查了一下api demo里就有, 你们还弄什么乱七八糟的啊.http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/animation/Rotate3dAnimation.html如下:

    Rotate3dAnimation.java

    The file containing the source code shown below is located in the corresponding directory in <sdk>/samples/android-<version>/...

    译: 下列包含源码的文件位于相应的<sdk>/samples/android-<version>/...目录下

    package com.example.android.apis.animation;

    import android.view.animation.Animation;
    import android.view.animation.Transformation;
    import android.graphics.Camera;
    import android.graphics.Matrix;

    /**
     * An animation that rotates the view on the Y axis between two specified angles.
     * This animation also adds a translation on the Z axis (depth) to improve the effect.
    译: 一个在指定了两个角度的在Y轴旋转的动画类.
    这个类也添加了一个z轴的属性用来提高效果.
     */

    publicclassRotate3dAnimationextendsAnimation{
       
    privatefinalfloat mFromDegrees;
       
    privatefinalfloat mToDegrees;
       
    privatefinalfloat mCenterX;
       
    privatefinalfloat mCenterY;
       
    privatefinalfloat mDepthZ;
       
    privatefinalboolean mReverse;
       
    privateCamera mCamera;

       
    /**
         * Creates a new 3D rotation on the Y axis. The rotation is defined by its
         * start angle and its end angle. Both angles are in degrees. The rotation
         * is performed around a center point on the 2D space, definied by a pair
         * of X and Y coordinates, called centerX and centerY. When the animation
         * starts, a translation on the Z axis (depth) is performed. The length
         * of the translation can be specified, as well as whether the translation
         * should be reversed in time.
    在Y轴创建了一个新的3D的旋转动画,这个旋转动画定义了它的开始角度和结束角度,两个角度的单位都是度数
    ,这个旋转动画围绕在2D空间的中心点执行.你可以用X轴坐标(叫做
    centerX)和Y轴(叫做centerY)坐标来定
    义这个中心点.当动画开始时,对于z轴(深度)的转换就会被执行.转换的长度和转换正向反向都可以指定.
         * @param fromDegrees the start angle of the 3D rotation 开始的角度
         * @param toDegrees the end angle of the 3D rotation 结束的角度
         * @param centerX the X center of the 3D rotation 中心点X轴坐标
         * @param centerY the Y center of the 3D rotation 中心点Y轴坐标
         * @param reverse true if the translation should be reversed, false otherwise true表示反向,false表示正向

         */

       
    public Rotate3dAnimation(float fromDegrees,float toDegrees,
               
    float centerX,float centerY,float depthZ,boolean reverse){
            mFromDegrees
    = fromDegrees;
            mToDegrees
    = toDegrees;
            mCenterX
    = centerX;
            mCenterY
    = centerY;
            mDepthZ
    = depthZ;
            mReverse
    = reverse;
       
    }

       
    @Override
       
    publicvoid initialize(int width,int height,int parentWidth,int parentHeight){
           
    super.initialize(width, height, parentWidth, parentHeight);
            mCamera
    =newCamera();
       
    }

       
    @Override
       
    protectedvoid applyTransformation(float interpolatedTime,Transformation t){
           
    finalfloat fromDegrees = mFromDegrees;
           
    float degrees = fromDegrees +((mToDegrees - fromDegrees)* interpolatedTime);

           
    finalfloat centerX = mCenterX;
           
    finalfloat centerY = mCenterY;
           
    finalCamera camera = mCamera;

           
    finalMatrix matrix = t.getMatrix();

            camera
    .save();
           
    if(mReverse){
                camera
    .translate(0.0f,0.0f, mDepthZ * interpolatedTime);
           
    }else{
                camera
    .translate(0.0f,0.0f, mDepthZ *(1.0f- interpolatedTime));
           
    }
            camera
    .rotateY(degrees);
            camera
    .getMatrix(matrix);
            camera
    .restore();

            matrix
    .preTranslate(-centerX,-centerY);
            matrix
    .postTranslate(centerX, centerY);
       
    }
    }

    http://www.cnblogs.com/olvo/archive/2012/04/25/2469218.html
  • 相关阅读:
    Learning to Segment Every Thing(偏监督学习)
    特征金字塔-Feature Pyramid Networks for Object Detection
    Mask R-CNN翻译
    04.卷积神经网络_第一周卷积神经网络
    对极几何
    hdu 3572 Task Schedule【 最大流 】
    uva 11624 Fire! 【 BFS 】
    hdu 3549 Flow Problem 【最大流】
    codeforces 277 A Learning Languages 【DFS 】
    poj 2828 Buy Tickets【线段树 单点更新】
  • 原文地址:https://www.cnblogs.com/shanzei/p/3113976.html
Copyright © 2011-2022 走看看