Android Open Source - DivisionByZero Circle






From Project

Back to project page DivisionByZero.

License

The source code is released under:

Apache License

If you think the Android project DivisionByZero 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.ggstudios.divisionbyzero;
//  w  ww  .  j a v a2 s  .  c om
import com.ggstudios.utils.BufferUtils;
import com.ggstudios.utils.DebugLog;

import android.opengl.GLES20;

import static fix.android.opengl.GLES20.glVertexAttribPointer;

public class Circle extends Drawable{
  private static final String TAG = "Circle";
  
  private static final float DEFAULT_RADIUS = 5.0f;
  
  private int handle = 0;
  
  float x, y;
  int points;
  
  private float radius;
  float scale;
  float[] vertices;
  
  float a, r, g, b;

  public boolean visible = true;
  
  private int textureHandle;
  
  /**
   * Creates a new circle object
   * 
   * @param x The x coordinate
   * @param y The y coordinate
   * @param radius The radius of the circle
   * @param points The number of points... The more the smoother the circle but also the slower
   */
  
  public Circle(int x, int y, float r, int points){
    vertices = new float[(points+2)*2];
    this.points = points;
    this.x = x;
    this.y = y;
    
    if(r < 0) {
      DebugLog.e(TAG, "Error. Negative radius set: " + r);
    }
    
    // CENTER OF CIRCLE
    vertices[0] = 0;
    vertices[1] = 0;

    radius = DEFAULT_RADIUS * Core.SDP;
    
    float rad;
    for (int i = 2; i<(points+2)*2; i+=2){
        rad = i*(2*Utils.PI)/(points*2);
        vertices[i] = (short) (Math.cos(rad)*radius);
        vertices[i+1] = (short) (Math.sin(rad)*radius);
    }
  
    handle = BufferUtils.copyToBuffer(vertices);
    
    scale = r / radius;
    
    this.a = 0.3f;
    this.r = 1.0f;
    this.g = 0.0f;
    this.b = 0.0f;
    
    textureHandle = Core.tm.get(R.drawable.white);
  }
  
  public void update(float x, float y, float r){
    this.x = x;
    this.y = y;
    scale = r / radius;
  }
  
  public void setPos(int x, int y){
    this.x = x;
    this.y = y;
  }
  
  @Override
  public void draw(float offX, float offY){
    if(!visible) return;
    
    final float finalX = offX + x;
    final float finalY = offY + y;
    
    Utils.resetMatrix();
    Utils.scale(scale);
    Utils.translateAndCommit(finalX, finalY);
    
    GLES20.glUniform4f(Core.U_TEX_COLOR_HANDLE, r, g, b, a);

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, handle);
    glVertexAttribPointer(Core.A_POSITION_HANDLE, 2, GLES20.GL_FLOAT, false, 0, 0);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, points+2);
    
    GLES20.glUniform4f(Core.U_TEX_COLOR_HANDLE, 1, 1, 1, 1);

  }

  @Override
  public void refresh() {
    handle = BufferUtils.copyToBuffer(vertices);
    
    textureHandle = Core.tm.get(R.drawable.white);
  }
}




Java Source Code List

com.ggstudios.divisionbyzero.ActivityAbout.java
com.ggstudios.divisionbyzero.ActivityLevelSelection.java
com.ggstudios.divisionbyzero.ActivityMainMenu.java
com.ggstudios.divisionbyzero.ActivitySettings.java
com.ggstudios.divisionbyzero.ActivitySplashScreen.java
com.ggstudios.divisionbyzero.ApplicationMain.java
com.ggstudios.divisionbyzero.BaseActivity.java
com.ggstudios.divisionbyzero.BaseDialog.java
com.ggstudios.divisionbyzero.BulletManager.java
com.ggstudios.divisionbyzero.Bullet.java
com.ggstudios.divisionbyzero.Button.java
com.ggstudios.divisionbyzero.Circle.java
com.ggstudios.divisionbyzero.ClickableCollection.java
com.ggstudios.divisionbyzero.Clickable.java
com.ggstudios.divisionbyzero.ConfirmDialog.java
com.ggstudios.divisionbyzero.Core.java
com.ggstudios.divisionbyzero.CustomGLSurfaceView.java
com.ggstudios.divisionbyzero.DialogManager.java
com.ggstudios.divisionbyzero.DrawableCollection.java
com.ggstudios.divisionbyzero.DrawableString.java
com.ggstudios.divisionbyzero.Drawable.java
com.ggstudios.divisionbyzero.EndDialog.java
com.ggstudios.divisionbyzero.Event.java
com.ggstudios.divisionbyzero.ExplosionGenerator.java
com.ggstudios.divisionbyzero.ExtrasManager.java
com.ggstudios.divisionbyzero.FontManager.java
com.ggstudios.divisionbyzero.GameRenderer.java
com.ggstudios.divisionbyzero.GameUpdater.java
com.ggstudios.divisionbyzero.Game.java
com.ggstudios.divisionbyzero.Grid.java
com.ggstudios.divisionbyzero.Hud.java
com.ggstudios.divisionbyzero.InGameMenu.java
com.ggstudios.divisionbyzero.InfoDialog.java
com.ggstudios.divisionbyzero.Label.java
com.ggstudios.divisionbyzero.LevelManager.java
com.ggstudios.divisionbyzero.LevelMap.java
com.ggstudios.divisionbyzero.LineGuide.java
com.ggstudios.divisionbyzero.MainActivity.java
com.ggstudios.divisionbyzero.Map.java
com.ggstudios.divisionbyzero.MessageDialog.java
com.ggstudios.divisionbyzero.ParticleEngine.java
com.ggstudios.divisionbyzero.PathFinder.java
com.ggstudios.divisionbyzero.PauseMenu.java
com.ggstudios.divisionbyzero.PictureBox.java
com.ggstudios.divisionbyzero.Player.java
com.ggstudios.divisionbyzero.PopupMenu.java
com.ggstudios.divisionbyzero.Rectangle.java
com.ggstudios.divisionbyzero.Shader.java
com.ggstudios.divisionbyzero.SpawnManager.java
com.ggstudios.divisionbyzero.SpriteAnimation.java
com.ggstudios.divisionbyzero.SpriteManager.java
com.ggstudios.divisionbyzero.Sprite.java
com.ggstudios.divisionbyzero.Statbar.java
com.ggstudios.divisionbyzero.StateManager.java
com.ggstudios.divisionbyzero.TargetRectangle.java
com.ggstudios.divisionbyzero.TextureManager.java
com.ggstudios.divisionbyzero.TowerInfoDialog.java
com.ggstudios.divisionbyzero.TowerLibrary.java
com.ggstudios.divisionbyzero.TowerManager.java
com.ggstudios.divisionbyzero.TowerMenu.java
com.ggstudios.divisionbyzero.Tower.java
com.ggstudios.divisionbyzero.UpdatableCollection.java
com.ggstudios.divisionbyzero.Updatable.java
com.ggstudios.divisionbyzero.UpgradeDialog.java
com.ggstudios.divisionbyzero.Utils.java
com.ggstudios.divisionbyzero.VBO.java
com.ggstudios.divisionbyzero.WaveControlDialog.java
com.ggstudios.divisionbyzero.WaveControlHud.java
com.ggstudios.divisionbyzero.ZoomControl.java
com.ggstudios.utils.BitmapUtils.java
com.ggstudios.utils.BufferUtils.java
com.ggstudios.utils.DebugLog.java
com.ggstudios.utils.ShaderUtils.java
com.ggstudios.widget.LevelMapBackground.java
fix.android.opengl.GLES20.java