浏览代码

applied intelliJ suggestions

Fabio Arnold 11 年之前
父节点
当前提交
4303353071
共有 1 个文件被更改,包括 40 次插入44 次删除
  1. 40 44
      src/de/tudarmstadt/informatik/hostage/ui2/fragment/opengl/ThreatIndicatorGLRenderer.java

+ 40 - 44
src/de/tudarmstadt/informatik/hostage/ui2/fragment/opengl/ThreatIndicatorGLRenderer.java

@@ -47,23 +47,19 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 	 * @param color 32 bit integer encoding the color
 	 */
 	public static void setBackgroundColor(int color) {
-		backgroundColor[0] = (float)Color.red(color) / 255.0f;
-		backgroundColor[1] = (float)Color.green(color) / 255.0f;
-		backgroundColor[2] = (float)Color.blue(color) / 255.0f;
+		mBackgroundColor[0] = (float)Color.red(color) / 255.0f;
+		mBackgroundColor[1] = (float)Color.green(color) / 255.0f;
+		mBackgroundColor[2] = (float)Color.blue(color) / 255.0f;
 	}
-	private static float[] backgroundColor = new float[3];
+	private static float[] mBackgroundColor = new float[3];
 	
 	public static AssetManager assets = null; // needs to be set by the Activity using this class
-	
-	private int width;
-	private int height;
-	private float aspectRatio;
-	
+
 	// OpenGL data
-	private int program;
-	private float [] modelview;
-	private float [] projection;
-	private float [] mvp;
+	private int mProgram;
+	private float [] mModelview;
+	private float [] mProjection;
+	private float [] mMVP;
 	
 	private AnimatedMesh androidMesh = null;
 	private AnimatedMesh beeMesh = null;
@@ -88,7 +84,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 	 * Initialization will be called after GL context is created and is current
 	 */
 	public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
-		GLES20.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], 1.0f);
+		GLES20.glClearColor(mBackgroundColor[0], mBackgroundColor[1], mBackgroundColor[2], 1.0f);
 		GLES20.glEnable(GLES20.GL_DEPTH_TEST);
 		GLES20.glEnable(GLES20.GL_CULL_FACE);
 		GLES20.glEnable(GLES20.GL_TEXTURE_2D);
@@ -115,10 +111,10 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		}
 		beeTexture = loadTexture("textures/bee-tex.png");
 		
-		modelview = new float[16];
-		Matrix.setIdentityM(modelview, 0);
-		projection = new float[16];
-		mvp = new float[16];
+		mModelview = new float[16];
+		Matrix.setIdentityM(mModelview, 0);
+		mProjection = new float[16];
+		mMVP = new float[16];
 		
 		// default shader
 		String vertexSource = "attribute vec3 position; void main() {gl_Position = vec4(position, 1.0);}";
@@ -132,7 +128,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
-		program = loadProgram(vertexSource, fragmentSource);
+		mProgram = loadProgram(vertexSource, fragmentSource);
 	}
 	
 	/**
@@ -187,10 +183,10 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		// OpenGL drawing
 		GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
 		
-		GLES20.glUseProgram(program);
-		int colorUniformLoc = GLES20.glGetUniformLocation(program, "color");
-		int textureUniformLoc = GLES20.glGetUniformLocation(program, "texture");
-		int mvpUniformLoc = GLES20.glGetUniformLocation(program, "mvp");
+		GLES20.glUseProgram(mProgram);
+		int colorUniformLoc = GLES20.glGetUniformLocation(mProgram, "color");
+		int textureUniformLoc = GLES20.glGetUniformLocation(mProgram, "texture");
+		int mvpUniformLoc = GLES20.glGetUniformLocation(mProgram, "mvp");
 
 		//  animate color
 		final float[] whiteColor = {1.0f, 1.0f, 1.0f, 1.0f};
@@ -230,7 +226,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		GLES20.glUniform1i(textureUniformLoc, 0);
 		
 		// animate camera
-		Matrix.setIdentityM(modelview, 0);
+		Matrix.setIdentityM(mModelview, 0);
 		if (mCurrentThreatLevel == ThreatLevel.LIVE_THREAT || mTargetThreatLevel == ThreatLevel.LIVE_THREAT) {
 			float delta = 1.0f;
 			if (mThreatLevelTransition < 0.4f) { // animate only during the first 40% of the transition
@@ -239,18 +235,18 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 			}
 			if (mTargetThreatLevel != ThreatLevel.LIVE_THREAT)
 				delta = 1.0f - delta;
-			Matrix.translateM(modelview, 0, 0.0f, -0.6f - 0.2f * delta, -1.6f - 0.4f * delta); // 0.0f, -0.8f, -2.0f
-			Matrix.rotateM(modelview, 0, -85.0f + 5.0f * delta, 1.0f, 0.0f, 0.0f); // -80.0f
+			Matrix.translateM(mModelview, 0, 0.0f, -0.6f - 0.2f * delta, -1.6f - 0.4f * delta); // 0.0f, -0.8f, -2.0f
+			Matrix.rotateM(mModelview, 0, -85.0f + 5.0f * delta, 1.0f, 0.0f, 0.0f); // -80.0f
 			
 		} else {
-			Matrix.translateM(modelview, 0, 0.0f, -0.6f, -1.6f);
-			Matrix.rotateM(modelview, 0, -85.0f, 1.0f, 0.0f, 0.0f);
+			Matrix.translateM(mModelview, 0, 0.0f, -0.6f, -1.6f);
+			Matrix.rotateM(mModelview, 0, -85.0f, 1.0f, 0.0f, 0.0f);
 		}
-		Matrix.multiplyMM(mvp, 0, projection, 0, modelview, 0);
-		GLES20.glUniformMatrix4fv(mvpUniformLoc, 1, false, mvp, 0);
+		Matrix.multiplyMM(mMVP, 0, mProjection, 0, mModelview, 0);
+		GLES20.glUniformMatrix4fv(mvpUniformLoc, 1, false, mMVP, 0);
 		
 		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, androidTexture);
-		androidMesh.draw(program);
+		androidMesh.draw(mProgram);
 		
 		// restore color
 		GLES20.glUniform4fv(colorUniformLoc, 1, whiteColor, 0);
@@ -263,16 +259,16 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 			float beePositionZ = 2.0f * (1.0f - fadeIn) * (1.0f - fadeIn); // animate the bee going in/out
 			
 			final float beeSize = 0.2f;
-			Matrix.rotateM(modelview, 0, (float)((-240.0 * animTime) % 360.0), 0.0f, 0.0f, 1.0f); // rotate around android
-			Matrix.translateM(modelview, 0, 0.6f, 0.0f, 0.7f + 0.1f * (float)Math.sin(12.0 * animTime) + beePositionZ); // go up and down
-			Matrix.rotateM(modelview, 0, 20.0f * (float)Math.cos(12.0 * animTime), 1.0f, 0.0f, 0.0f); // rock back and forth
-			Matrix.scaleM(modelview, 0, beeSize, beeSize, beeSize);
-			Matrix.multiplyMM(mvp, 0, projection, 0, modelview, 0);
-			GLES20.glUniformMatrix4fv(mvpUniformLoc, 1, false, mvp, 0);
+			Matrix.rotateM(mModelview, 0, (float)((-240.0 * animTime) % 360.0), 0.0f, 0.0f, 1.0f); // rotate around android
+			Matrix.translateM(mModelview, 0, 0.6f, 0.0f, 0.7f + 0.1f * (float)Math.sin(12.0 * animTime) + beePositionZ); // go up and down
+			Matrix.rotateM(mModelview, 0, 20.0f * (float)Math.cos(12.0 * animTime), 1.0f, 0.0f, 0.0f); // rock back and forth
+			Matrix.scaleM(mModelview, 0, beeSize, beeSize, beeSize);
+			Matrix.multiplyMM(mMVP, 0, mProjection, 0, mModelview, 0);
+			GLES20.glUniformMatrix4fv(mvpUniformLoc, 1, false, mMVP, 0);
 	
 			GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, beeTexture);
 			beeMesh.tick();
-			beeMesh.draw(program);
+			beeMesh.draw(mProgram);
 		}
 		
 		long deltaTime = System.currentTimeMillis() - mStartTimeMillis - timeMillis; // time for one frame
@@ -289,13 +285,13 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 	 * Informs renderer of changed surface dimensions
 	 */
 	public void onSurfaceChanged(GL10 arg0, int w, int h) {
-		width = w;
-		height = h;
-		aspectRatio = (float)w / (float)h;
-		Matrix.orthoM(projection, 0, -aspectRatio, aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f);
+		int width = w;
+		int height = h;
+		float aspectRatio = (float) w / (float) h;
+		//Matrix.orthoM(mProjection, 0, -aspectRatio, aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f);
 		float near = 0.1f;
 		float fov = 2.0f;
-		Matrix.frustumM(projection, 0, near * -aspectRatio, near * aspectRatio, -near, near, fov * near, 100.0f);
+		Matrix.frustumM(mProjection, 0, near * -aspectRatio, near * aspectRatio, -near, near, fov * near, 100.0f);
 		GLES20.glViewport(0, 0, width, height);
 	}
 	
@@ -311,7 +307,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 	}
 	
 	private int loadTexture(String filePath) {
-		Bitmap bitmap = null;
+		Bitmap bitmap;
 		try {
 			bitmap = BitmapFactory.decodeStream(assets.open(filePath));
 		} catch (IOException e) {