Android Open Source - NotATop Utils






From Project

Back to project page NotATop.

License

The source code is released under:

GNU General Public License

If you think the Android project NotATop 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.gg.util;
/*from  ww w. j  av  a 2 s  .co m*/
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.opengl.GLUtils;


final public class Utils {

  private static Matrix yFlipMatrix;
  
  static {
    yFlipMatrix = new Matrix();
    yFlipMatrix.postScale(-1, 1); // flip Y axis
  }
  
  public static Bitmap getTextureFromBitmapResource(Context context, int resourceId) {
    
    Bitmap bitmap = null;
    try {
      bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId);
      return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), yFlipMatrix, false);
    }
    finally  {
      if (bitmap != null) {
        bitmap.recycle();
      }
    }
  }  

  public static void generateMipmapsForBoundTexture(Bitmap texture) {
    
    // generate the full texture (mipmap level 0)
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, texture, 0);
    
    Bitmap currentMipmap = texture;
    
    int width = texture.getWidth();
    int height = texture.getHeight();
    int level = 0;
    
    boolean reachedLastLevel;
    do {
      
      // go to next mipmap level
      if (width > 1) width /= 2;
      if (height > 1) height /= 2;
      level++;
      reachedLastLevel = (width == 1 && height == 1);
      
      // generate next mipmap
      Bitmap mipmap = Bitmap.createScaledBitmap(currentMipmap, width, height, true);
      GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, mipmap, 0);
      
      // recycle last mipmap (but don't recycle original texture)
      if (currentMipmap != texture)
      {
        currentMipmap.recycle();
      }
      
      // remember last generated mipmap
      currentMipmap = mipmap;
      
    } while (!reachedLastLevel);
    
    // once again, recycle last mipmap (but don't recycle original texture)
    if (currentMipmap != texture) {
      currentMipmap.recycle();
    }
  }

  public static void setXYZ(float[] vector, int offset, float x, float y, float z) {
    vector[offset] = x;
    vector[offset + 1] = y;
    vector[offset + 2] = z;
  }

  public static void setXYZn(float[] vector, int offset, float x, float y, float z) {
    float r = (float)Math.sqrt(x * x + y * y + z * z);
    setXYZ(vector, offset, x / r, y / r, z / r);
  }
  
  public static void setXY(float[] vector, int offset, float x, float y) {
    vector[offset] = x;
    vector[offset + 1] = y;
  }
  
}




Java Source Code List

com.gg.game.ClassicGame.java
com.gg.game.ClassicGame.java
com.gg.game.GameFrame.java
com.gg.game.GameFrame.java
com.gg.game.TimeGame.java
com.gg.game.TimeGame.java
com.gg.module.DrawBackground.java
com.gg.module.DrawBackground.java
com.gg.module.DrawScore.java
com.gg.module.DrawScore.java
com.gg.module.DrawTrack.java
com.gg.module.DrawTrack.java
com.gg.module.SelectControl.java
com.gg.module.SelectControl.java
com.gg.module.SoundControl.java
com.gg.module.SoundControl.java
com.gg.module.VoiceControl.java
com.gg.module.VoiceControl.java
com.gg.top.BasicTop.java
com.gg.top.BasicTop.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCone.java
com.gg.top.DrawCone.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawTop.java
com.gg.top.DrawTop.java
com.gg.util.Circle.java
com.gg.util.Circle.java
com.gg.util.Constant.java
com.gg.util.Constant.java
com.gg.util.DateUtil.java
com.gg.util.DateUtil.java
com.gg.util.Direction.java
com.gg.util.Direction.java
com.gg.util.Line.java
com.gg.util.Line.java
com.gg.util.Point.java
com.gg.util.Point.java
com.gg.util.TextureRect.java
com.gg.util.TextureRect.java
com.gg.util.TrackPoint.java
com.gg.util.TrackPoint.java
com.gg.util.Track.java
com.gg.util.Track.java
com.gg.util.Utils.java
com.gg.util.Utils.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.MainActivity.java
com.gg.view.MainActivity.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.WelcomeSurfaceView.java
com.gg.view.WelcomeSurfaceView.java