CompassGLSurfaceView.java :  » Graphics-3D-2D-OpenGL » kryptonitecompass » kryptonite » compass » Android Open Source

Android Open Source » Graphics 3D 2D OpenGL » kryptonitecompass 
kryptonitecompass » kryptonite » compass » CompassGLSurfaceView.java
/**
 * Kryptonite Compass
 *
 *    Copyright (C) 2010  Jorge Villalta.
 *
 *
 * This file is part of Kryptonite Compass project.
 *
 * Kryptonite Compass is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Kryptonite Compass is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Kryptonite Compass.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package kryptonite.compass;

import android.content.Context;
import android.graphics.Color;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class CompassGLSurfaceView extends GLSurfaceView {

  private CompassRenderer mRenderer;

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

    mRenderer = new CompassRenderer(false, Color.GREEN);
    setRenderer(mRenderer);
  }

  public CompassGLSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mRenderer = new CompassRenderer(false, Color.GREEN);
    setRenderer(mRenderer);
  }

  @Override
  public boolean onTouchEvent(final MotionEvent event) {
    final int height = getHeight(); // Y
    final int width = getWidth(); // X
    final float PERSPECTIVA = 4.5f;

    queueEvent(new Runnable() {
      public void run() {

        float despX = event.getX() - (width / 2);
        float despY = event.getY() - (height / 2);

        float camX = (-despX * PERSPECTIVA) / (width / 2);
        float camY = (despY * PERSPECTIVA) / (height / 2);

        // float camZ = 0;

        /*
         * if (event.getX() > width / 2) camZ = -camX; else camZ = camX;
         */

        mRenderer.setCameraXY(camX, camY);
      }

    });

    return true;
  }

  public void setCompassColor(int color) {
    mRenderer.setColor(color);
  }

  public int getColor() {
    return mRenderer.getColor();
  }

  public void setCompassAngle(float angle) {
    mRenderer.setRotationAngle(angle);
  }

  public void increaseCompassAngle(float angle) {
    mRenderer.increaseRotationAngle(angle);
  }

  public int getFrames() {
    return mRenderer.getFrameCount();
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.