Sign in to follow this  
polyfrag

Android engine_handle_input

Recommended Posts

polyfrag    2502

Have I got this code right for pointer up and down events? How do I know if it was a movement rather than up or down?

 

// http://stackoverflow.com/questions/12500825/android-ndk-multitouch
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) 
{
    struct engine* engine = (struct engine*)app->userData;
    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) 
	{
        //engine->animating = 1;
        //engine->state.x = AMotionEvent_getX(event, 0);
        //engine->state.y = AMotionEvent_getY(event, 0);

		int action = AKeyEvent_getAction(event);

		switch(action)
		{
		case AMOTION_EVENT_ACTION_POINTER_DOWN:
			return 1;
		case AMOTION_EVENT_ACTION_POINTER_UP:
			return 1;
		default:
			break;
		}

        return 1;
    }


    return 0;
}

 

 

Share this post


Link to post
Share on other sites
polyfrag    2502

Found it https://bitbucket.org/runhello/jumpcore/src/2641f6910f3386d74e3401a16a32f4888631cf35/android/jumpcore-eclipse/jni/gl_code.cpp

 

So it keeps track of all the pointers and it tells me about each one individually using indices?

 

	unsigned int index = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK;

Share this post


Link to post
Share on other sites
frob    44908

Keep in mind that these are mutlitouch devices.  

 

There can be many touches simultaneously.

 

They need to provide an index so you know which of the touches it is telling you about.

 

The index is stored in the high bits so you will need to shift by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT to convert the bits into the correct index.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this