Android NDK处理用户交互事件(3)

}
                        break;
                    case AMOTION_EVENT_ACTION_DOWN:
                        {
                            float x = AMotionEvent_getX(event,0);
                            float y = AMotionEvent_getY(event,0);
                            char  szBuf[64];
                            LOGI("x = %f  y = %f",x,y);
                            float3 pt;
                            pt.x = x;
                            pt.y = y;
                            pt.z = 0;
                            g_arVertex.push_back(pt);
                        }
                        break;
                    case AMOTION_EVENT_ACTION_UP:
                        break;
                    }
                }
                break;
            case AINPUT_SOURCE_TRACKBALL:
                break;
            }
        }
        break;
    }


    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);
        return 1;
    }
    return 0;
}

/**
 * Process the next main command.
 */
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
    struct engine* engine = (struct engine*)app->userData;
    switch (cmd) {
        case APP_CMD_SAVE_STATE:

break;
        case APP_CMD_INIT_WINDOW:
            // The window is being shown, get it ready.
            if (engine->app->window != NULL) {
                engine_init_display(engine);
            }
            break;
        case APP_CMD_TERM_WINDOW:
            // The window is being hidden or closed, clean it up.
            engine_term_display(engine);
            break;
        case APP_CMD_GAINED_FOCUS:

break;
        case APP_CMD_LOST_FOCUS:

break;
    }
}

/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(struct android_app* state) {
    struct engine engine;

// Make sure glue isn't stripped.
    app_dummy();

memset(&engine, 0, sizeof(engine));
    state->userData = &engine;
    state->onAppCmd = engine_handle_cmd;
    state->onInputEvent = engine_handle_input;
    engine.app = state;

// Prepare to monitor accelerometer
    engine.sensorManager = ASensorManager_getInstance();
    engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
            ASENSOR_TYPE_ACCELEROMETER);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/706aa2db62d972e5ef66183277443fa7.html