Android Open Source - OpenGlDraw_Android G L Surface View Draw






From Project

Back to project page OpenGlDraw_Android.

License

The source code is released under:

GNU General Public License

If you think the Android project OpenGlDraw_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.opengldraw.gl;
/* w w  w.  ja v  a  2  s. c o  m*/
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;

public class GLSurfaceViewDraw extends GLSurfaceView {

  private RendererDraw myRenderer;
  private float touchX;
  private float touchY;
  private final float rotationFactorX = 180.0f / 320;
  private final float rotationFactorY = 180.0f / 320;
  
  public GLSurfaceViewDraw(Context context) {
    super(context);
    
    //setEGLContextClientVersion(1);
    myRenderer = new RendererDraw(context);
    setRenderer(myRenderer);
    
    /* Draw only when told to with requestRender. This is used for touch enabled interaction. */
    //setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);    
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent e) {
    float tx = e.getX();
    float ty = e.getY();
    
    if(e.getAction() == MotionEvent.ACTION_MOVE) {
      float dx = tx - touchX;
            float dy = ty - touchY;

            myRenderer.myAngleY += dx * rotationFactorX; //180.0f / 320;
            myRenderer.myAngleX += dy * rotationFactorY; //180.0f / 320;
            requestRender();
    }
    
    touchX = tx;
    touchY = ty;
    
    return true;
  };
}




Java Source Code List

com.example.opengldraw.MainActivity.java
com.example.opengldraw.gl.GLSurfaceViewDraw.java
com.example.opengldraw.gl.RendererDraw.java
com.example.opengldraw.gl.ShapeDrawer.java
com.example.opengldraw.shapes.FireEngine.java
com.example.opengldraw.shapes.ShapeCube.java
com.example.opengldraw.shapes.ShapeCup10Verts.java
com.example.opengldraw.shapes.ShapeCup64Verts.java
com.example.opengldraw.shapes.ShapeSquare.java
com.example.opengldraw.utils.IndexOrderObj.java
com.example.opengldraw.utils.ShapeDataInterface.java
com.example.opengldraw.utils.WavefrontObj.java