即使对于常规视图,手册也很模糊,甚至没有在UI事件概述页面中提到mGLSurfaceView。使用mGLSurfaceView处理UI事件
对于初学者来说,所有示例都不起作用,因为它们依赖于视图的Id(例如Button button = (Button)findViewById(R.id.corky);
)。我尝试来回发送UI事件的时间很糟糕。我使用了霰弹枪解决方案,并将mGLSurfaceView的每个输入事件附加到活动中......但我渴望更好的东西。
所以,任何有足够勇气的人都可以用一个活动,一个mGLSurfaceView和一个活动onTouch事件说出一个简单的例子,说明相对于屏幕大小的点击在哪里? (如W = 50%,H = 50%,在屏幕的中心,地理位置点击)
public class GlClick extends Activity implements OnTouchListener {
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
mGLSurfaceView = new GLSurfaceView(this);
mGLSurfaceView.setRenderer(new GlRenderer());
setContentView(mGLSurfaceView);
mGLSurfaceView.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
Log.d(TAG, "example output: click was on 234x211 for a 800x600 screen.")
}
}
class GlRenderer implements Renderer {
// here be lots of messy beginner GL code ...
// ... you'd have wished for dragons.
public void onSurfaceChanged(GL10 gl, int w, int h) {
screenWidth = w;
screenHeight = h;
//TODO: send that to the activity
}
}
更好的例子可能大家分享你如何“转换触摸从屏幕坐标到glworld坐标”? – gcb 2010-11-17 09:07:58
嗯,我的公式有点太复杂(我的触摸在我的glworld中不成比例),但是我用类似的东西编辑了我的代码。 – 2010-11-17 09:11:07
感谢您的更新。但是,Vect是什么?在文档中找不到它。 – gcb 2010-11-20 02:19:43