2
\$\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\$
  • \$\begingroup\$ Have you tried the standard Android way of implementing a gesture listener with a motiondetector on your activity? \$\endgroup\$ – MLProgrammer-CiM Oct 18 '13 at 9:55
  • \$\begingroup\$ Yes I have implemented that but how to scale GLSurfaceView? do you have any reference link or code? \$\endgroup\$ – mayank_droid Oct 19 '13 at 5:23
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\$
  • \$\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\$ – mayank_droid Nov 8 '13 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 '13 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\$ – mayank_droid Nov 22 '13 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 '13 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\$ – mayank_droid Nov 22 '13 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.