Reputation: 11211
I created a OpenGL Renderer
public class OpenGLRenderer implements Renderer {
And now I want to get data from onTouchEvent. Unfortunately, it doesn't work:
public boolean onTouchEvent(MotionEvent event){
//eyeX += 0.2f;
//eyeY = 0.2f;
eyeZ -= 0.2f;
Log.v("OpenGLRenderer", "TouchEvent works");
return true;
}
When I change my class to:
public class OpenGLRenderer extends GLSurfaceView implements Renderer {
and my onTouchEvent function to:
@Override
public boolean onTouchEvent(MotionEvent event){
//eyeX += 0.2f;
//eyeY = 0.2f;
eyeZ -= 0.2f;
Log.v("OpenGLRenderer", "TouchEvent works");
return true;
}
still not works :/ What's wrong?
Upvotes: 0
Views: 844
Reputation: 1945
This is for MyGLSurfaceview class.. when you touch the screen, you will get the that position x,y position range.
@Override
public boolean onTouchEvent(MotionEvent ev) {
// Normal touch
xPosition = ev.getX();
yPosition = ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:{
dx = ev.getX();
dy = ev.getY();
}
return ;
}
}
Upvotes: 0
Reputation: 5322
From the GLSurfaceView documentation: "When handling the event, you may need to communicate with the Renderer object that's running in the rendering thread."
Use queueEvent(Runnable)
to pass the event to the rendering Thread:
@override
public boolean onTouchEvent(MotionEvent event){
queueEvent(new Runnable() {
// This method will be called on the rendering
// thread:
public void run() {
eyeZ -= 0.2f;
Log.v("OpenGLRenderer", "TouchEvent works");
}});
return true;
}
Upvotes: 1