In android, I adopted an example of a rotating sphere given here . He creates a simple application showing a rotating sphere (earth).
Now, I want to do something if the spinning sphere is pressed on the phone display. I do not want to respond to events outside the spinning sphere. Here is what I have tried so far using a derived version of GLSurfaceView
:
public class MyGLSurfaceView extends GLSurfaceView { MyGLSurfaceView(Context context) { super(context); } public boolean onTouchEvent(MotionEvent event) { int x = (int)event.getX(); int y = (int)event.getY(); Log.d("onTouchEvent",String.format("keyCode: %d coords: %d %d", event.getActionMasked(), x, y)); Renderer renderer = this.Renderer.getRenderer();
Without the ERROR line, this code works, and when I click on the display, I get the x / y coordinate.
However, to evaluate if the event was within the scope, my approach was to get a renderer that has a Sphere
object to determine if the x / y coordinates are within the scope.
But the ERROR line is not working, I get an error
Error:(26, 56) error: cannot find symbol method getRenderer()
How can I fix this error; or is there a smarter way to automatically find out if there was an event on a Sphere
graphic object?
It might be nice to change the constructor and pass the instance of the visualization to MyGLSurfaceView
, eh? ADDENDUM: this idea does not seem to work. I get a constructor error that I don't understand ...
source share