1
\$\begingroup\$

I want to apply pinch zoom and panning effect on GLSurfaceView. It is Image editor, so It would not be 3D object. I tried to implement using these following links:
https://groups.google.com/forum/#!topic/android-developers/EVNRDNInVRU
Want to apply pinch and zoom to GLSurfaceView(3d Object) http://www.learnopengles.com/android-lesson-one-getting-started/

These all are links for 3D object rendering. I can not use ImageView as I need to work out with OpenGL so, had to implement it on GLSurfaceView.

Suggest me or any reference links are there for such implementation. **I need it for 2D only.

I am able to do both now, but where I am getting problem is to set the pivot point while panning can any one help me to set the translation respective to pivot point?

Matrix.setIdentityM(mScaleMatrix, 0);
        Matrix.scaleM(mScaleMatrix, 0, scaleX, scaleY, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mScaleMatrix, 0);
Matrix.setIdentityM(mTranslateMatrix, 0);
        Matrix.translateM(mTranslateMatrix, 0, deltaX, deltaY, 0);
Matrix.multiplyMM(mProjectionMatrix, 0, mProjectionMatrix, 0,
                    mTranslateMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
\$\endgroup\$
2
  • \$\begingroup\$ Have you tried the standard Android way of implementing a gesture listener with a motiondetector on your activity? \$\endgroup\$ Oct 18, 2013 at 9:55
  • \$\begingroup\$ Yes I have implemented that but how to scale GLSurfaceView? do you have any reference link or code? \$\endgroup\$ Oct 19, 2013 at 5:23

1 Answer 1

1
\$\begingroup\$

You don't have to scale your GLSurfaceView; instead you should adjust your projection matrix in order to achieve "zooming".

You are most likely using an orthographic projection for your 2D view, so have a look at this thread for a discussion on how to achieve zooming using glOrtho().

\$\endgroup\$
9
  • \$\begingroup\$ Thanks a ton, @free3dom ! but I implemented ortho at Matrix level and its working fine and got success on pinch zoom but confused on panning it, It is possible by using Matrix.translateM() too. But dont know what the exactly translate values to be passed, can u help me on this? thanks in advance \$\endgroup\$ Nov 8, 2013 at 11:23
  • \$\begingroup\$ For panning it would probably be easiest to do that with the MODEL VIEW matrix, instead of the projection matrix. So instead of using an identity matrix as the starting point you use your "panned" coordinates as a TRANSLATION matrix, which all your "models" would then be transformed by - think of it as a global transform for all the objects in your world, i.e. their world coordinates transformed by your "pan coordinates". \$\endgroup\$
    – free3dom
    Nov 8, 2013 at 20:38
  • \$\begingroup\$ hey free3dom can you tell me how could i set the pivot point while scaling, cos i need to translate with pivot point in scaling. Currently, when i scale matrix it does center point scaling because in translation matrix the pivot point always stays at center point, how can set pivot in translation matrix?? \$\endgroup\$ Nov 22, 2013 at 10:22
  • \$\begingroup\$ To set the pivot point you FIRST translate (to change the current position to your desired pivot point), then perform scaling. This should be done in model (local) space of the object you are scaling. \$\endgroup\$
    – free3dom
    Nov 22, 2013 at 14:19
  • \$\begingroup\$ i m scaling the view matrix and then applying translation to projection matrix, it is working fine in this matter but setting pivot is not possible. Do you want to say i should apply translation to view matrix if i m doing scaling only. can both translation work this way? \$\endgroup\$ Nov 22, 2013 at 16:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .