You'll want to attach an OnTouchListener event to your view. In this event you can get rotation using the 'event' variable that gets passed to the input listener, I used something like this in my game engine to retrieve a value that equals the amount of change in whatever direction, (so if you swipe your finger vertically an inch, or about 50 units, the code gets the original mouse down position, and subtracts this from the new position)
- Code: Select all
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
origX = event.getX();
origY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
changeX = event.getX() - origX;
changeY = event.getY() - origY;
origX = event.getX();
origY = event.getY();
break;
case MotionEvent.ACTION_UP:
changeX = 0;
changeY = 0;
break;
}
return false;
}
// These are used to retrieve any change in screen touch 'move' events
public static float GetChangeX() { return changeX; }
public static float GetChangeY() { return changeY; }
And then simply use this code in your games render() method to change rotation:
- Code: Select all
rotationX = Input.GetChangeX();
rotationY = Input.GetChangeY();
myModel.Rotate(rotationX, rotationY, 0);
You may have to tweak the render code a little, my games all use landscape orientation so its a slightly altered version of this, but you'll figure it out. Good luck, hope this helps!
p.s. - I strongly suggest checking out these resources:
http://developer.android.com/guide/topics/ui/ui-events.htmlhttp://developer.android.com/reference/android/view/View.OnTouchListener.html