Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6647703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:34:07+00:00 2026-05-26T00:34:07+00:00

i have an application that shows a simple square polygon represented on a GLSurfaceView.

  • 0

i have an application that shows a simple square polygon represented on a GLSurfaceView. Actually i can do zoomIn and zoomOut with two buttons.

But now i want to implemente the iphone multitouch style zoomIn and zoomOut. It means that when the user presses with two fingers the screen and move one finger into another, the user is doing zoomOut, and when the user separates the fingers makes zoomIn.

How can i implement this with Android, openglES, and GLsurfaceView?

the class:

public class MySurfaceView extends GLSurfaceView implements Renderer {  
    private Context context;
    private Square square;
    /* Rotation values */
    private float xrot;                 //X Rotation
    private float yrot;                 //Y Rotation
    /* Rotation speed values */
    private float xspeed;               //X Rotation Speed ( NEW )
    private float yspeed;               //Y Rotation Speed ( NEW )
    private float z = -5.0f;            //Depth Into The Screen ( NEW )
    /*
     * These variables store the previous X and Y
     * values as well as a fix touch scale factor.
     * These are necessary for the rotation transformation
     * added to this lesson, based on the screen touches. ( NEW )
     */
    private float oldX;
    private float oldY;
    private final float TOUCH_SCALE = 0.2f;     //Proved to be good for normal rotation ( NEW )

    public MySurfaceView(Context context) {
        super(context);
        this.context = context;
        setEGLConfigChooser(8, 8, 8, 8, 16, 0); //fondo transparente
        getHolder().setFormat(PixelFormat.TRANSLUCENT); //fondo transparente
        //Set this as Renderer
        this.setRenderer(this);
        //Request focus, otherwise buttons won't react
        this.requestFocus();
        this.setFocusableInTouchMode(true);
        square = new Square();
    }

    public void onSurfaceCreated(GL10 gl, EGLConfig config) {       
        gl.glDisable(GL10.GL_DITHER);               //Disable dithering ( NEW )
        gl.glEnable(GL10.GL_TEXTURE_2D);            //Enable Texture Mapping
        gl.glShadeModel(GL10.GL_SMOOTH);            //Enable Smooth Shading
        gl.glClearDepthf(1.0f);                     //Depth Buffer Setup
        gl.glEnable(GL10.GL_DEPTH_TEST);            //Enables Depth Testing
        gl.glDepthFunc(GL10.GL_LEQUAL);             //The Type Of Depth Testing To Do
        gl.glClearColor(0,0,0,0); //fondo transparente

        gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); 

        //Load the texture for the cube once during Surface creation
        square.loadGLTexture(gl, this.context);
    }

    public void onDrawFrame(GL10 gl) {

        //Clear Screen And Depth Buffer
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);    
        gl.glLoadIdentity();                    //Reset The Current Modelview Matrix

        //Drawing
        gl.glTranslatef(0.0f, 0.0f, z);         //Move z units into the screen
        gl.glScalef(0.8f, 0.8f, 0.8f);          //Scale the Cube to 80 percent, otherwise it would be too large for the screen

        //Rotate around the axis based on the rotation matrix (rotation, x, y, z)
        gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f);   //X
        gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);   //Y

        square.draw(gl);                    //Draw the Cube 

        //Change rotation factors
        xrot += xspeed;
        yrot += yspeed;
    }

    /**
     * If the surface changes, reset the view
     */
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        if(height == 0) {                       //Prevent A Divide By Zero By
            height = 1;                         //Making Height Equal One
        }
        gl.glViewport(0, 0, width, height);     //Reset The Current Viewport
        gl.glMatrixMode(GL10.GL_PROJECTION);    //Select The Projection Matrix
        gl.glLoadIdentity();                    //Reset The Projection Matrix
        //Calculate The Aspect Ratio Of The Window
        GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
        gl.glMatrixMode(GL10.GL_MODELVIEW);     //Select The Modelview Matrix
        gl.glLoadIdentity();                    //Reset The Modelview Matrix
    }

    public boolean onTouchEvent(MotionEvent event) {
        float x = event.getX();
        float y = event.getY();
        //If a touch is moved on the screen
        if(event.getAction() == MotionEvent.ACTION_MOVE) {
            //Calculate the change
            float dx = x - oldX;
            float dy = y - oldY;
            //Define an upper area of 10% on the screen
            //int upperArea = this.getHeight() / 10;
            //Zoom in/out if the touch move has been made in the upper
            //if(y < upperArea) {
                //z -= dx * TOUCH_SCALE / 2;
            //Rotate around the axis otherwise
            //} else {              
            xrot += dy * TOUCH_SCALE;
            yrot += dx * TOUCH_SCALE;
            //}        
        //A press on the screen
        } else if(event.getAction() == MotionEvent.ACTION_UP) {
            //Define an upper area of 10% to define a lower area
            //int upperArea = this.getHeight() / 10;
            //int lowerArea = this.getHeight() - upperArea;
            //Change the light setting if the lower area has been pressed 
            //if(y > lowerArea) {       }
        }

        //Remember the values
        oldX = x;
        oldY = y;
        //We handled the event
        return true;
    }

    public void zoomIn(){ z=z+0.2f; }
    public void zoomOut(){ z=z-0.2f; }
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:34:08+00:00Added an answer on May 26, 2026 at 12:34 am

    done using this method: http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-6-implementing-the-pinch-zoom-gesture/1847

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple application, that shows list of many items, where user can display
I have a simple HTML (as HTA) application that shows strange behavior on Windows
I have an application that shows a list of items. The user can click
I am using PHP and Smarty. I have a simple application that: Shows page
Basically i have an application for Android 1.5 with a GLSurfaceView class that shows
I have a wpf application with a simple window that shows a text in
I have a simple application that shows the user an image (in a UIImageView)
I have application that is up more than 3 days. I can see in
I have a fairly simple iPhone application that I want to have run on
I have an application that can be used without authentication on computers in public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.