Controlling 3D object rotation using the touch screen in openGL

I am a 4th year student in computer engineering and have some experience with Android dev.

I am working on an application that has a 3D component that requires me to be able to rotate it. I watched an example on an Android resource site.

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchRotateActivity.html

This example does not talk about rotation around the z axis. I already tried using Quaternion for rotation, but I don’t understand how to get rotation around the z axis.

As soon as you rotate something, the axis ceases to be the same (x, y), since you can find out how much to rotate on which axis?

I was wondering if anyone could help me learn how to just turn around the object. as an example above, but also around the z axis. I have already spent about 24 hours searching and trying to figure it out.

The big problem is that as soon as you rotate 90 degrees around the y axis, how can you find that the next rotation (moving vertically on the touch screen) should be around the z axis.

Thanks in advance.

+3
source share
4 answers

Add xAngle and yAngle to the current matrix.

Matrix.rotateM(matrix, 0, xAngleADD, matrix[1], matrix[5], matrix[9]);
Matrix.rotateM(matrix, 0, yAngleADD, matrix[0], matrix[4], matrix[8]);
gl.glMultMatrixf(matrix, 0);
+1
source

You can also rotate the camera around the center instead of rotating the object.

0
source

. : " -, (x, y), , ?", " , ?". , x x, x . - , , .

, , , , rotX, rotY rotZ, glRotatef ? , . , , . gimbal lock, . , . .

OpenGL, , M. , . .

, x. x, R. , OpenGL , glRotatef (, 1, 0, 0).

: M MR M RM. , . , OpenGL , 40 , 40 , .

R , MR , RM . , , , . , , , , , . , , . , . . M.

, . , GL-, :

// ... I assume the modelview stack is active, M is an array of 16 floats ...

// ensure whatever on the stack currently is kept safe
glPushMatrix();

    // but we don't actually care what it was, so load the identity
    glLoadIdentity();

    // build our rotation matrix first
    glRotatef(changeAroundX, 1, 0, 0);
    glRotatef(changeAroundY, 0, 1, 0);

    // multiply by M. OpenGL postmultiplies by the newer matrix, so this
    // is premultiplying M by whatever we just loaded
    glMultMatrixf(M);

    // read the new M back
    glGetFloatv(GL_MODELVIEW_MATRIX, M);

// and pretend we never touched the stack
glPopMatrix();

glMultMatrixf (M) glRotatef, . , M, , . M, , , , . .

0

, : . 3.3.1

-1

Source: https://habr.com/ru/post/1787865/


All Articles