Student Student
Student Student

Reputation: 960

Difference between rotation methods?

My question is in about rotate methods in android.graphics.Camera.In Docs,I saw these comments:

public void rotateX (float deg) Since: API Level 1
Applies a rotation transform around the X axis.


public void rotate (float x, float y, float z) Since: API Level 12
Applies a rotation transform around all three axis.

There is my question:What is difference between using rotate (float x, float y, float z) and a sequence of rotate* methods,for example difference between these two snippets A and B:
A)

camera.rotate (x, y, z);


B)

camera.rotateX (x);
camera.rotateY (y);
camera.rotateZ (z);

Upvotes: 2

Views: 1010

Answers (2)

Jason Lim
Jason Lim

Reputation: 171

The importance lies in the order the rotations are applied in.

Consider for example, an aircraft flying forward which first rotates 90 degrees on its Z axis (roll) and then rotates 90 degrees on its X axis (pitch). The result is that the aircraft is now flying to the right with its right wing pointing downward. Now consider the operation in reverse order with a 90 degree pitch followed by a 90 degree roll. The aircraft is now flying up with its right wing pointing forward (these results may vary depending on your coordinate system).

camera.rotate provides a quick and easy function for applying all three rotations using one function. The reason for the remaining three rotation functions is to allow for situations in which the developer wants to apply one or more of the rotations in a specific order.

Upvotes: 1

Henry
Henry

Reputation: 43778

Looking at the source in frameworks/base/core/jni/android/graphics/Camera.cpp there is no difference:

static void Camera_rotate(JNIEnv* env, jobject obj, jfloat x, jfloat y, jfloat z) {
    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
    v->rotateX(SkFloatToScalar(x));
    v->rotateY(SkFloatToScalar(y));
    v->rotateZ(SkFloatToScalar(z));
}

Upvotes: 1

Related Questions