|
@@ -27,21 +27,19 @@ import android.util.Log;
|
|
*/
|
|
*/
|
|
|
|
|
|
public class ThreatIndicatorGLRenderer implements Renderer {
|
|
public class ThreatIndicatorGLRenderer implements Renderer {
|
|
- public static final int kThreatLevelNotMonitoring = 0;
|
|
|
|
- public static final int kThreatLevelNoThreat = 1;
|
|
|
|
- public static final int kThreatLevelPastThreat = 2;
|
|
|
|
- public static final int kThreatLevelPersistentThreat = 3;
|
|
|
|
-
|
|
|
|
- private static boolean sPlayGreetingAnimation = true; // greet the first time
|
|
|
|
|
|
+ public enum ThreatLevel {
|
|
|
|
+ NOT_MONITORING,
|
|
|
|
+ NO_THREAT,
|
|
|
|
+ PAST_THREAT,
|
|
|
|
+ LIVE_THREAT
|
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
/**
|
|
* Set the threat level which should be indicated
|
|
* Set the threat level which should be indicated
|
|
- * @param level 0 to 3 but better use the constants
|
|
|
|
|
|
+ * @param threatLevel
|
|
*/
|
|
*/
|
|
- public static void setThreatLevel(int level) {
|
|
|
|
- assert(level >= 0 && level <= 3);
|
|
|
|
- nextThreatLevel = level;
|
|
|
|
- Log.i("threat indicator", "next threat level = " + level);
|
|
|
|
|
|
+ public static void setThreatLevel(ThreatLevel threatLevel) {
|
|
|
|
+ mNextThreatLevel = threatLevel;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -73,15 +71,17 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
private int beeTexture;
|
|
private int beeTexture;
|
|
|
|
|
|
// threat state
|
|
// threat state
|
|
- private static int nextThreatLevel = kThreatLevelNoThreat;
|
|
|
|
|
|
+ private static ThreatLevel mNextThreatLevel = ThreatLevel.NO_THREAT;
|
|
|
|
|
|
- private int currentThreatLevel = kThreatLevelNoThreat;
|
|
|
|
- private int targetThreatLevel = kThreatLevelNoThreat;
|
|
|
|
- private float threatLevelTransition = 1.0f; // 1.0 means transition is complete
|
|
|
|
|
|
+ private ThreatLevel mCurrentThreatLevel = ThreatLevel.NO_THREAT;
|
|
|
|
+ private ThreatLevel mTargetThreatLevel = ThreatLevel.NO_THREAT;
|
|
|
|
+ private float mThreatLevelTransition = 1.0f; // 1.0 means transition is complete
|
|
|
|
+
|
|
|
|
+ private static boolean sPlayGreetingAnimation = true; // greet the first time
|
|
|
|
|
|
- private long startTimeMillis; // for animation
|
|
|
|
|
|
+ private long mStartTimeMillis; // for animation
|
|
public ThreatIndicatorGLRenderer() {
|
|
public ThreatIndicatorGLRenderer() {
|
|
- startTimeMillis = System.currentTimeMillis();
|
|
|
|
|
|
+ mStartTimeMillis = System.currentTimeMillis();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -139,25 +139,25 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
* Tries to render at 30 Hz (see bottom part)
|
|
* Tries to render at 30 Hz (see bottom part)
|
|
*/
|
|
*/
|
|
public void onDrawFrame(GL10 arg0) {
|
|
public void onDrawFrame(GL10 arg0) {
|
|
- long timeMillis = System.currentTimeMillis() - startTimeMillis;
|
|
|
|
|
|
+ long timeMillis = System.currentTimeMillis() - mStartTimeMillis;
|
|
double animTime = 0.001 * (double)timeMillis; // in seconds
|
|
double animTime = 0.001 * (double)timeMillis; // in seconds
|
|
|
|
|
|
// threat level state machine
|
|
// threat level state machine
|
|
- if (targetThreatLevel != currentThreatLevel) {
|
|
|
|
|
|
+ if (mTargetThreatLevel != mCurrentThreatLevel) {
|
|
boolean blocked = false; // block until current action is completed
|
|
boolean blocked = false; // block until current action is completed
|
|
- if (threatLevelTransition == 0.0f) {
|
|
|
|
|
|
+ if (mThreatLevelTransition == 0.0f) {
|
|
if (androidMesh.isActionDone()) {
|
|
if (androidMesh.isActionDone()) {
|
|
- switch (targetThreatLevel) {
|
|
|
|
- case kThreatLevelNotMonitoring:
|
|
|
|
|
|
+ switch (mTargetThreatLevel) {
|
|
|
|
+ case NOT_MONITORING:
|
|
androidMesh.startAction("sleep", false, false);
|
|
androidMesh.startAction("sleep", false, false);
|
|
break;
|
|
break;
|
|
- case kThreatLevelNoThreat:
|
|
|
|
|
|
+ case NO_THREAT:
|
|
androidMesh.startAction("happy", true, false);
|
|
androidMesh.startAction("happy", true, false);
|
|
break;
|
|
break;
|
|
- case kThreatLevelPastThreat:
|
|
|
|
|
|
+ case PAST_THREAT:
|
|
androidMesh.startAction("fear", true, false);
|
|
androidMesh.startAction("fear", true, false);
|
|
break;
|
|
break;
|
|
- case kThreatLevelPersistentThreat:
|
|
|
|
|
|
+ case LIVE_THREAT:
|
|
androidMesh.startAction("panic", true, false);
|
|
androidMesh.startAction("panic", true, false);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -165,19 +165,19 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
}
|
|
}
|
|
|
|
|
|
if (!blocked) {
|
|
if (!blocked) {
|
|
- threatLevelTransition += 0.016f;
|
|
|
|
- if (threatLevelTransition >= 1.0f) {
|
|
|
|
- currentThreatLevel = targetThreatLevel;
|
|
|
|
- threatLevelTransition = 1.0f;
|
|
|
|
|
|
+ mThreatLevelTransition += 0.016f;
|
|
|
|
+ if (mThreatLevelTransition >= 1.0f) {
|
|
|
|
+ mCurrentThreatLevel = mTargetThreatLevel;
|
|
|
|
+ mThreatLevelTransition = 1.0f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (nextThreatLevel != targetThreatLevel) {
|
|
|
|
- targetThreatLevel = nextThreatLevel;
|
|
|
|
- threatLevelTransition = 0.0f;
|
|
|
|
|
|
+ if (mNextThreatLevel != mTargetThreatLevel) {
|
|
|
|
+ mTargetThreatLevel = mNextThreatLevel;
|
|
|
|
+ mThreatLevelTransition = 0.0f;
|
|
|
|
|
|
// HACK!!! reverses the sleep animation to create smooth transition into other states
|
|
// HACK!!! reverses the sleep animation to create smooth transition into other states
|
|
- if (currentThreatLevel == kThreatLevelNotMonitoring)
|
|
|
|
|
|
+ if (mCurrentThreatLevel == ThreatLevel.NOT_MONITORING)
|
|
androidMesh.startAction("sleep", false, true);
|
|
androidMesh.startAction("sleep", false, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -200,44 +200,44 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
|
|
|
float[] currentColor = whiteColor;
|
|
float[] currentColor = whiteColor;
|
|
float blink = 0.5f + 0.5f * (float)Math.sin(12.0 * animTime);
|
|
float blink = 0.5f + 0.5f * (float)Math.sin(12.0 * animTime);
|
|
- switch (currentThreatLevel) {
|
|
|
|
- case kThreatLevelNotMonitoring:
|
|
|
|
|
|
+ switch (mCurrentThreatLevel) {
|
|
|
|
+ case NOT_MONITORING:
|
|
currentColor = greyColor;
|
|
currentColor = greyColor;
|
|
break;
|
|
break;
|
|
- case kThreatLevelPastThreat:
|
|
|
|
|
|
+ case PAST_THREAT:
|
|
currentColor = mixColor(blink, whiteColor, yellowColor);
|
|
currentColor = mixColor(blink, whiteColor, yellowColor);
|
|
break;
|
|
break;
|
|
- case kThreatLevelPersistentThreat:
|
|
|
|
|
|
+ case LIVE_THREAT:
|
|
currentColor = mixColor(blink, whiteColor, redColor);
|
|
currentColor = mixColor(blink, whiteColor, redColor);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- if (targetThreatLevel != currentThreatLevel) {
|
|
|
|
|
|
+ if (mTargetThreatLevel != mCurrentThreatLevel) {
|
|
float[] targetColor = whiteColor;
|
|
float[] targetColor = whiteColor;
|
|
- switch (targetThreatLevel) {
|
|
|
|
- case kThreatLevelNotMonitoring:
|
|
|
|
|
|
+ switch (mTargetThreatLevel) {
|
|
|
|
+ case NOT_MONITORING:
|
|
targetColor = greyColor;
|
|
targetColor = greyColor;
|
|
break;
|
|
break;
|
|
- case kThreatLevelPastThreat:
|
|
|
|
|
|
+ case PAST_THREAT:
|
|
targetColor = mixColor(blink, whiteColor, yellowColor);
|
|
targetColor = mixColor(blink, whiteColor, yellowColor);
|
|
break;
|
|
break;
|
|
- case kThreatLevelPersistentThreat:
|
|
|
|
|
|
+ case LIVE_THREAT:
|
|
targetColor = mixColor(blink, whiteColor, redColor);
|
|
targetColor = mixColor(blink, whiteColor, redColor);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- currentColor = mixColor(threatLevelTransition, currentColor, targetColor);
|
|
|
|
|
|
+ currentColor = mixColor(mThreatLevelTransition, currentColor, targetColor);
|
|
}
|
|
}
|
|
GLES20.glUniform4fv(colorUniformLoc, 1, currentColor, 0);
|
|
GLES20.glUniform4fv(colorUniformLoc, 1, currentColor, 0);
|
|
GLES20.glUniform1i(textureUniformLoc, 0);
|
|
GLES20.glUniform1i(textureUniformLoc, 0);
|
|
|
|
|
|
// animate camera
|
|
// animate camera
|
|
Matrix.setIdentityM(modelview, 0);
|
|
Matrix.setIdentityM(modelview, 0);
|
|
- if (currentThreatLevel == kThreatLevelPersistentThreat || targetThreatLevel == kThreatLevelPersistentThreat) {
|
|
|
|
|
|
+ if (mCurrentThreatLevel == ThreatLevel.LIVE_THREAT || mTargetThreatLevel == ThreatLevel.LIVE_THREAT) {
|
|
float delta = 1.0f;
|
|
float delta = 1.0f;
|
|
- if (threatLevelTransition < 0.4f) { // animate only during the first 40% of the transition
|
|
|
|
- delta = threatLevelTransition / 0.4f;
|
|
|
|
|
|
+ if (mThreatLevelTransition < 0.4f) { // animate only during the first 40% of the transition
|
|
|
|
+ delta = mThreatLevelTransition / 0.4f;
|
|
delta = -2.0f * delta * delta * delta + 3.0f * delta * delta; // ease in/out
|
|
delta = -2.0f * delta * delta * delta + 3.0f * delta * delta; // ease in/out
|
|
}
|
|
}
|
|
- if (targetThreatLevel != kThreatLevelPersistentThreat)
|
|
|
|
|
|
+ if (mTargetThreatLevel != ThreatLevel.LIVE_THREAT)
|
|
delta = 1.0f - delta;
|
|
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.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.rotateM(modelview, 0, -85.0f + 5.0f * delta, 1.0f, 0.0f, 0.0f); // -80.0f
|
|
@@ -255,11 +255,11 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
// restore color
|
|
// restore color
|
|
GLES20.glUniform4fv(colorUniformLoc, 1, whiteColor, 0);
|
|
GLES20.glUniform4fv(colorUniformLoc, 1, whiteColor, 0);
|
|
|
|
|
|
- if (currentThreatLevel == kThreatLevelPersistentThreat || targetThreatLevel == kThreatLevelPersistentThreat) {
|
|
|
|
|
|
+ if (mCurrentThreatLevel == ThreatLevel.LIVE_THREAT || mTargetThreatLevel == ThreatLevel.LIVE_THREAT) {
|
|
// draw a bee rotating around the android
|
|
// draw a bee rotating around the android
|
|
|
|
|
|
- float fadeIn = threatLevelTransition;
|
|
|
|
- if (targetThreatLevel != kThreatLevelPersistentThreat) fadeIn = 1.0f - fadeIn; // fade out
|
|
|
|
|
|
+ float fadeIn = mThreatLevelTransition;
|
|
|
|
+ if (mTargetThreatLevel != ThreatLevel.LIVE_THREAT) fadeIn = 1.0f - fadeIn; // fade out
|
|
float beePositionZ = 2.0f * (1.0f - fadeIn) * (1.0f - fadeIn); // animate the bee going in/out
|
|
float beePositionZ = 2.0f * (1.0f - fadeIn) * (1.0f - fadeIn); // animate the bee going in/out
|
|
|
|
|
|
final float beeSize = 0.2f;
|
|
final float beeSize = 0.2f;
|
|
@@ -275,7 +275,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
beeMesh.draw(program);
|
|
beeMesh.draw(program);
|
|
}
|
|
}
|
|
|
|
|
|
- long deltaTime = System.currentTimeMillis() - startTimeMillis - timeMillis; // time for one frame
|
|
|
|
|
|
+ long deltaTime = System.currentTimeMillis() - mStartTimeMillis - timeMillis; // time for one frame
|
|
if (deltaTime < 33) {
|
|
if (deltaTime < 33) {
|
|
try {
|
|
try {
|
|
Thread.sleep(33 - deltaTime); // sleep remaining time for 30 Hz
|
|
Thread.sleep(33 - deltaTime); // sleep remaining time for 30 Hz
|