public class

VelocityMatrix

extends java.lang.Object

 java.lang.Object

↳androidx.constraintlayout.core.motion.utils.VelocityMatrix

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout-core', version: '1.1.0-alpha01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout-core
  • version: 1.1.0-alpha01

Artifact androidx.constraintlayout:constraintlayout-core:1.1.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

This is used to calculate the related velocity matrix for a post layout matrix

Summary

Constructors
publicVelocityMatrix()

Methods
public voidapplyTransform(float locationX, float locationY, int width, int height, float[] mAnchorDpDt[])

Apply the transform a velocity vector

public voidclear()

public voidsetRotationVelocity(KeyCycleOscillator oscR, float position)

public voidsetRotationVelocity(SplineSet rot, float position)

public voidsetScaleVelocity(KeyCycleOscillator oscSx, KeyCycleOscillator oscSy, float position)

public voidsetScaleVelocity(SplineSet scaleX, SplineSet scaleY, float position)

public voidsetTranslationVelocity(KeyCycleOscillator oscX, KeyCycleOscillator oscY, float position)

public voidsetTranslationVelocity(SplineSet transX, SplineSet transY, float position)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public VelocityMatrix()

Methods

public void clear()

public void setRotationVelocity(SplineSet rot, float position)

public void setTranslationVelocity(SplineSet transX, SplineSet transY, float position)

public void setScaleVelocity(SplineSet scaleX, SplineSet scaleY, float position)

public void setRotationVelocity(KeyCycleOscillator oscR, float position)

public void setTranslationVelocity(KeyCycleOscillator oscX, KeyCycleOscillator oscY, float position)

public void setScaleVelocity(KeyCycleOscillator oscSx, KeyCycleOscillator oscSy, float position)

public void applyTransform(float locationX, float locationY, int width, int height, float[] mAnchorDpDt[])

Apply the transform a velocity vector

Source

/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.constraintlayout.core.motion.utils;

/**
 * This is used to calculate the related velocity matrix for a post layout matrix
 *
 * @DoNotShow
 */
public class VelocityMatrix {
    float mDScaleX, mDScaleY, mDTranslateX, mDTranslateY, mDRotate;
    float mRotate;
    private static String sTag = "VelocityMatrix";

    /**
     * @TODO: add description
     */
    public void clear() {
        mDScaleX = mDScaleY = mDTranslateX = mDTranslateY = mDRotate = 0;
    }

    /**
     * @TODO: add description
     */
    public void setRotationVelocity(SplineSet rot, float position) {
        if (rot != null) {
            mDRotate = rot.getSlope(position);
            mRotate = rot.get(position);
        }
    }

    /**
     * @TODO: add description
     */
    public void setTranslationVelocity(SplineSet transX, SplineSet transY, float position) {

        if (transX != null) {
            mDTranslateX = transX.getSlope(position);
        }
        if (transY != null) {
            mDTranslateY = transY.getSlope(position);
        }
    }

    /**
     * @TODO: add description
     */
    public void setScaleVelocity(SplineSet scaleX, SplineSet scaleY, float position) {

        if (scaleX != null) {
            mDScaleX = scaleX.getSlope(position);
        }
        if (scaleY != null) {
            mDScaleY = scaleY.getSlope(position);
        }
    }

    /**
     * @TODO: add description
     */
    public void setRotationVelocity(KeyCycleOscillator oscR, float position) {
        if (oscR != null) {
            mDRotate = oscR.getSlope(position);
        }
    }

    /**
     * @TODO: add description
     */
    public void setTranslationVelocity(KeyCycleOscillator oscX,
            KeyCycleOscillator oscY,
            float position) {

        if (oscX != null) {
            mDTranslateX = oscX.getSlope(position);
        }

        if (oscY != null) {
            mDTranslateY = oscY.getSlope(position);
        }
    }

    /**
     * @TODO: add description
     */
    public void setScaleVelocity(KeyCycleOscillator oscSx,
            KeyCycleOscillator oscSy,
            float position) {
        if (oscSx != null) {
            mDScaleX = oscSx.getSlope(position);
        }
        if (oscSy != null) {
            mDScaleY = oscSy.getSlope(position);
        }
    }

    /**
     * Apply the transform a velocity vector
     *
     * @DoNotShow
     */
    public void applyTransform(float locationX,
            float locationY,
            int width,
            int height,
            float[] mAnchorDpDt) {
        float dx = mAnchorDpDt[0];
        float dy = mAnchorDpDt[1];
        float offx = 2 * (locationX - 0.5f);
        float offy = 2 * (locationY - 0.5f);
        dx += mDTranslateX;
        dy += mDTranslateY;
        dx += offx * mDScaleX;
        dy += offy * mDScaleY;
        float r = (float) Math.toRadians(mRotate);
        float dr = (float) Math.toRadians(mDRotate);
        dx += dr * (float) (-width * offx * Math.sin(r) - height * offy * Math.cos(r));
        dy += dr * (float) (width * offx * Math.cos(r) - height * offy * Math.sin(r));
        mAnchorDpDt[0] = dx;
        mAnchorDpDt[1] = dy;
    }
}