void resize_window(GLint new_width, GLint new_height) { int wm; width = new_width; height = new_height; if (new_height == 0) new_height = 1; SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL); glViewport(0, 0, new_width, new_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (render_mode == IR) gluOrtho2D(0, width, height, 0); else gluPerspective(60.0f, (float)new_width/(float)new_height, 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); width = new_width; height = new_height; for (wm = 0; wm < MAX_WIIMOTES; ++wm) wiiuse_set_ir_vres(wiimotes[wm], width, height); }
/** * Set virtual screen resolution. It is used to automatically * compute the position of a cursor on this virtual screen * using the sensor bar. These results come in the IREvent. * @param id the id of the wiimote concerned * @param x x resolution. * @param y y resolution. */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution (JNIEnv *env, jobject obj, jint id, jint x, jint y) { wiiuse_set_ir_vres(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), x, y); }
int main(int argc, char** argv) { #else int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #endif int found, connected; int wm; //printf("wiiuse version = %s\n", wiiuse_version()); wiimotes = wiiuse_init(MAX_WIIMOTES); found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5); if (!found) return 0; connected = wiiuse_connect(wiimotes, MAX_WIIMOTES); if (connected) printf("Connected to %i wiimotes (of %i found).\n", connected, found); else { printf("Failed to connect to any wiimote.\n"); return 0; } wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1 | WIIMOTE_LED_4); wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4); wiiuse_rumble(wiimotes[0], 1); #ifndef WIN32 usleep(200000); #else Sleep(200); #endif wiiuse_rumble(wiimotes[0], 0); /* enable IR and motion sensing for all wiimotes */ for (wm = 0; wm < MAX_WIIMOTES; ++wm) { wiiuse_motion_sensing(wiimotes[wm], 1); wiiuse_set_ir(wiimotes[wm], 1); } if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Failed to initialize SDL: %s\n", SDL_GetError()); return 0; } SDL_WM_SetCaption("wiiuse SDL IR Example", "wiiuse SDL IR Example"); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); /* set window size */ width = wiimotes[0]->ir.vres[0]; height = wiimotes[0]->ir.vres[1]; SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL); for (wm = 0; wm < MAX_WIIMOTES; ++wm) wiiuse_set_ir_vres(wiimotes[wm], width, height); /* set OpenGL stuff */ glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); glClearColor(0, 0, 0, 0); /* set the size of the window */ resize_window(width, height); display(); #ifdef WIN32 last_render = GetTickCount(); #endif while (1) { SDL_Event event; if (SDL_PollEvent(&event)) { switch (event.type) { case SDL_VIDEORESIZE: { /* resize the window */ resize_window(event.resize.w, event.resize.h); break; } case SDL_QUIT: { /* shutdown */ SDL_Quit(); wiiuse_cleanup(wiimotes, MAX_WIIMOTES); return 0; } default: { } } } if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) { /* * This happens if something happened on any wiimote. * So go through each one and check if anything happened. */ int i = 0; for (; i < MAX_WIIMOTES; ++i) { switch (wiimotes[i]->event) { case WIIUSE_EVENT: /* a generic event occured */ handle_event(wiimotes[i]); break; default: break; } } } display(); } }
void Wiimote::setIrVres(unsigned int x, unsigned int y) { wiiuse_set_ir_vres(this->wm, x, y); }