我在 Android openGL 中创建了一个 3D 立方体,我可以使用 onTouch 事件打开 X 轴,但我想将它用作 UI,例如我试图获取它,以便当一张脸面向相机时如果您点击它作为 onClick 侦听器的表面,但我在使用 if 语句来检查面向相机的面时遇到问题,我的整个课程如下:
public class GLCubeEx extends Activity {
GLSurfaceView ourSurface;
GLCubeEx This = this;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
ourSurface = new GLSurfaceView(this);
ourSurface.setRenderer(new GLCubeRenderer());
setContentView(ourSurface);
}
public boolean onTouchEvent(MotionEvent event) {
float touchedX = 0;
float touchedY = 0;
Button btn = new Button(this);
LinearLayout.LayoutParams paramsd = new LinearLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsd.height = 60;
paramsd.width = 120;
btn.setLayoutParams(paramsd);
addContentView(btn, paramsd);
if (event.getAction() == MotionEvent.ACTION_DOWN){
GLCubeRenderer.xAngle = (touchedX - event.getX())/2f;
GLCubeRenderer.yAngle = (touchedY - event.getY())/2f;
} else if (event.getAction() == MotionEvent.ACTION_MOVE){
GLCubeRenderer.xAngle = (touchedX - event.getX())/2f;
GLCubeRenderer.yAngle = (touchedY - event.getY())/2f;
touchedX = event.getX();
touchedY = event.getY();
}
**EDIT here, thaks to Laurence pointing out**
if(GLCubeRenderer.xAngle > -118f && GLCubeRenderer.xAngle < -65f){
btn.setText("working");
}
String s = Float.toString(GLCubeRenderer.xAngle);
btn.setText(s);
return true;
}
public void onPause() {
super.onPause();
ourSurface.onPause();
}
public void onResume() {
super.onResume();
ourSurface.onResume();
}
}
我遇到的问题是我的运动事件中的 if 语句检查变量 xAngle (这是在滑动屏幕时创建并用于旋转立方体时创建的浮点数)是否在两个值之间没有被触发,btn 是应用程序中显示 xAngle 值的按钮,我不明白为什么它没有被触发任何我没见过的想法或明显的解决方案?