use of android.graphics.Camera in project UltimateAndroid by cymcsg.
the class AnimatorProxy method transformMatrix.
private void transformMatrix(Matrix m, View view) {
final float w = view.getWidth();
final float h = view.getHeight();
final boolean hasPivot = mHasPivot;
final float pX = hasPivot ? mPivotX : w / 2f;
final float pY = hasPivot ? mPivotY : h / 2f;
final float rX = mRotationX;
final float rY = mRotationY;
final float rZ = mRotationZ;
if ((rX != 0) || (rY != 0) || (rZ != 0)) {
final Camera camera = mCamera;
camera.save();
camera.rotateX(rX);
camera.rotateY(rY);
camera.rotateZ(-rZ);
camera.getMatrix(m);
camera.restore();
m.preTranslate(-pX, -pY);
m.postTranslate(pX, pY);
}
final float sX = mScaleX;
final float sY = mScaleY;
if ((sX != 1.0f) || (sY != 1.0f)) {
m.postScale(sX, sY);
final float sPX = -(pX / w) * ((sX * w) - w);
final float sPY = -(pY / h) * ((sY * h) - h);
m.postTranslate(sPX, sPY);
}
m.postTranslate(mTranslationX, mTranslationY);
}
use of android.graphics.Camera in project android_frameworks_base by ParanoidAndroid.
the class View method getCameraDistance.
/**
* Gets the distance along the Z axis from the camera to this view.
*
* @see #setCameraDistance(float)
*
* @return The distance along the Z axis.
*/
public float getCameraDistance() {
ensureTransformationInfo();
final float dpi = mResources.getDisplayMetrics().densityDpi;
final TransformationInfo info = mTransformationInfo;
if (info.mCamera == null) {
info.mCamera = new Camera();
info.matrix3D = new Matrix();
}
return -(info.mCamera.getLocationZ() * dpi);
}
use of android.graphics.Camera in project android_frameworks_base by ParanoidAndroid.
the class View method setCameraDistance.
/**
* <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which
* views are drawn) from the camera to this view. The camera's distance
* affects 3D transformations, for instance rotations around the X and Y
* axis. If the rotationX or rotationY properties are changed and this view is
* large (more than half the size of the screen), it is recommended to always
* use a camera distance that's greater than the height (X axis rotation) or
* the width (Y axis rotation) of this view.</p>
*
* <p>The distance of the camera from the view plane can have an affect on the
* perspective distortion of the view when it is rotated around the x or y axis.
* For example, a large distance will result in a large viewing angle, and there
* will not be much perspective distortion of the view as it rotates. A short
* distance may cause much more perspective distortion upon rotation, and can
* also result in some drawing artifacts if the rotated view ends up partially
* behind the camera (which is why the recommendation is to use a distance at
* least as far as the size of the view, if the view is to be rotated.)</p>
*
* <p>The distance is expressed in "depth pixels." The default distance depends
* on the screen density. For instance, on a medium density display, the
* default distance is 1280. On a high density display, the default distance
* is 1920.</p>
*
* <p>If you want to specify a distance that leads to visually consistent
* results across various densities, use the following formula:</p>
* <pre>
* float scale = context.getResources().getDisplayMetrics().density;
* view.setCameraDistance(distance * scale);
* </pre>
*
* <p>The density scale factor of a high density display is 1.5,
* and 1920 = 1280 * 1.5.</p>
*
* @param distance The distance in "depth pixels", if negative the opposite
* value is used
*
* @see #setRotationX(float)
* @see #setRotationY(float)
*/
public void setCameraDistance(float distance) {
invalidateViewProperty(true, false);
ensureTransformationInfo();
final float dpi = mResources.getDisplayMetrics().densityDpi;
final TransformationInfo info = mTransformationInfo;
if (info.mCamera == null) {
info.mCamera = new Camera();
info.matrix3D = new Matrix();
}
info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi);
info.mMatrixDirty = true;
invalidateViewProperty(false, false);
if (mDisplayList != null) {
mDisplayList.setCameraDistance(-Math.abs(distance) / dpi);
}
if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) {
// View was rejected last time it was drawn by its parent; this may have changed
invalidateParentIfNeeded();
}
}
use of android.graphics.Camera in project android_frameworks_base by ParanoidAndroid.
the class View method updateMatrix.
/**
* Recomputes the transform matrix if necessary.
*/
private void updateMatrix() {
final TransformationInfo info = mTransformationInfo;
if (info == null) {
return;
}
if (info.mMatrixDirty) {
// Figure out if we need to update the pivot point
if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) {
if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) {
info.mPrevWidth = mRight - mLeft;
info.mPrevHeight = mBottom - mTop;
info.mPivotX = info.mPrevWidth / 2f;
info.mPivotY = info.mPrevHeight / 2f;
}
}
info.mMatrix.reset();
if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) {
info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY);
info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY);
info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY);
} else {
if (info.mCamera == null) {
info.mCamera = new Camera();
info.matrix3D = new Matrix();
}
info.mCamera.save();
info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY);
info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation);
info.mCamera.getMatrix(info.matrix3D);
info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY);
info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, info.mPivotY + info.mTranslationY);
info.mMatrix.postConcat(info.matrix3D);
info.mCamera.restore();
}
info.mMatrixDirty = false;
info.mMatrixIsIdentity = info.mMatrix.isIdentity();
info.mInverseMatrixDirty = true;
}
}
use of android.graphics.Camera in project Anki-Android by Ramblurr.
the class Animation3D method applyTransformation.
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float centerX = 0;
float centerY = 0;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
float time;
switch(mAction) {
case ANIMATION_TURN:
if (mRealTurn) {
time = interpolatedTime >= 0.5f ? (interpolatedTime - 1.0f) : interpolatedTime;
} else {
time = interpolatedTime >= 0.5f ? -(interpolatedTime - 1.0f) : interpolatedTime;
}
float degrees = time * (mDirection ? -180 : 180);
if (interpolatedTime >= 0.5f && !mFlipped) {
mReviewer.fillFlashcard(false);
mFlipped = true;
}
camera.translate(0.0f, 0.0f, mDepthZ * Math.abs(degrees));
if (mDirection) {
centerX = mValueX / 2;
centerY = mValueY / (mRealTurn ? 2 : 3);
camera.rotateX(degrees);
} else {
centerX = mValueX / (mRealTurn ? 2 : 3);
centerY = mValueY / 2;
camera.rotateY(degrees);
}
break;
case ANIMATION_EXCHANGE_CARD:
if (mDirection) {
time = interpolatedTime >= 0.5f ? -(interpolatedTime - 1.0f) : -interpolatedTime;
} else {
time = interpolatedTime >= 0.5f ? (interpolatedTime - 1.0f) : interpolatedTime;
}
if (interpolatedTime >= 0.5f && !mFlipped) {
mReviewer.fillFlashcard(false);
mFlipped = true;
}
camera.translate(mValueX * time * 2, 0.0f, mDepthZ * Math.abs(time * 180));
centerX = mValueX / 2;
centerY = mValueY / 2;
break;
case ANIMATION_SLIDE_IN_CARD:
if (mDirection) {
time = 1 - interpolatedTime;
} else {
time = -1 + interpolatedTime;
}
if (interpolatedTime >= 0.0f && !mFlipped) {
mReviewer.showFlashcard(true);
mReviewer.fillFlashcard(false);
mFlipped = true;
}
camera.translate(mValueX * time * 2, 0.0f, mDepthZ * Math.abs(time * 180));
centerX = mValueX / 2;
centerY = mValueY / 2;
break;
case ANIMATION_SLIDE_OUT_CARD:
if (mDirection) {
time = -interpolatedTime;
} else {
time = interpolatedTime;
}
if (interpolatedTime == 1.0f && !mFlipped) {
mReviewer.showFlashcard(false);
mFlipped = true;
}
camera.translate(mValueX * time * 2, 0.0f, mDepthZ * Math.abs(time * 180));
centerX = mValueX / 2;
centerY = mValueY / 2;
break;
}
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
Aggregations