Android Open Source - OpenGLShadowDemo Shadows G L Surface View






From Project

Back to project page OpenGLShadowDemo.

License

The source code is released under:

MIT License

If you think the Android project OpenGLShadowDemo 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.projectI.openglshadowdemo;
/*  www  .j av a  2  s.co  m*/
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;

public class ShadowsGLSurfaceView extends GLSurfaceView {
  private ShadowsRenderer mRenderer;

    public ShadowsGLSurfaceView(Context context) {
        super(context);

        // Render the view only when there is a change in the drawing data
        //setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    }

    private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
    private float mPreviousX;
    private float mPreviousY;

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        // MotionEvent reports input details from the touch screen
        // and other input controls. In this case, you are only
        // interested in events where the touch position changed.

        float x = e.getX();
        float y = e.getY();

        switch (e.getAction()) {
            case MotionEvent.ACTION_MOVE:

                float dx = x - mPreviousX;
                float dy = y - mPreviousY;

                mRenderer.setRotationX(
                        mRenderer.getRotationX() +
                        (dx * TOUCH_SCALE_FACTOR));  // = 180.0f / 320
                
                mRenderer.setRotationY(
                        mRenderer.getRotationY() +
                        (dy * TOUCH_SCALE_FACTOR));  // = 180.0f / 320
                
                requestRender();
        }

        mPreviousX = x;
        mPreviousY = y;
        return true;
    }
    
    public void setRenderer(ShadowsRenderer renderer) {
      mRenderer = renderer;
    super.setRenderer(renderer); 
    }
}




Java Source Code List

com.projectI.openglshadowdemo.Cube.java
com.projectI.openglshadowdemo.Plane.java
com.projectI.openglshadowdemo.ShadowsActivity.java
com.projectI.openglshadowdemo.ShadowsGLSurfaceView.java
com.projectI.openglshadowdemo.ShadowsRenderer.java
com.projectI.openglshadowdemo.common.FPSCounter.java
com.projectI.openglshadowdemo.common.RenderConstants.java
com.projectI.openglshadowdemo.common.RenderProgram.java