void Psp2Ui::ProcessEvents() { SceCtrlData input; sceCtrlPeekBufferPositive(0, &input, 1); keys[Input::Keys::Z] = (input.buttons & SCE_CTRL_CROSS); keys[Input::Keys::X] = (input.buttons & SCE_CTRL_CIRCLE); keys[Input::Keys::N2] = (input.buttons & SCE_CTRL_TRIANGLE); keys[Input::Keys::LSHIFT] = (input.buttons & SCE_CTRL_SQUARE); keys[Input::Keys::F12] = (input.buttons & SCE_CTRL_SELECT); keys[Input::Keys::ESCAPE] = (input.buttons & SCE_CTRL_START); keys[Input::Keys::RIGHT] = (input.buttons & SCE_CTRL_RIGHT); keys[Input::Keys::LEFT] = (input.buttons & SCE_CTRL_LEFT); keys[Input::Keys::UP] = (input.buttons & SCE_CTRL_UP); keys[Input::Keys::DOWN] = (input.buttons & SCE_CTRL_DOWN); keys[Input::Keys::F2] = (input.buttons & SCE_CTRL_LTRIGGER); //Resolution changing support bool old_state = trigger_state; trigger_state = (input.buttons & SCE_CTRL_RTRIGGER); if ((trigger_state != old_state) && trigger_state) zoom_state = ((zoom_state + 1) % 3); // Left analog support keys[Input::Keys::JOY_AXIS_X_LEFT] = (input.lx < 50); keys[Input::Keys::JOY_AXIS_X_RIGHT] = (input.lx > 170); keys[Input::Keys::JOY_AXIS_Y_DOWN] = (input.ly > 170); keys[Input::Keys::JOY_AXIS_Y_UP] = (input.ly < 50); // Right analog support for extra buttons keys[Input::Keys::N1] = (input.ry > 170); keys[Input::Keys::N3] = (input.ry < 50); keys[Input::Keys::N5] = (input.rx > 170); keys[Input::Keys::N9] = (input.rx < 50); // Touchpad support for shaders changes SceTouchData data; sceTouchPeek(SCE_TOUCH_PORT_FRONT, &data, 1); if (data.reportNum > 0){ if (touch_x_start == -1) touch_x_start = data.report[0].x; }else if (touch_x_start > 0){ int xdiff = data.report[0].x - touch_x_start; if (xdiff > 400){ set_shader = true; touch_x_start = -2; in_use_shader++; if (in_use_shader >= SHADERS_NUM) in_use_shader = 0; }else if (xdiff < -400){ set_shader = true; touch_x_start = -2; in_use_shader--; if (in_use_shader < 0) in_use_shader = SHADERS_NUM - 1; } }else touch_x_start = -1; }
static int lua_touchpad(lua_State *L) { if (lua_gettop(L) != 0) return luaL_error(L, "wrong number of arguments."); SceTouchData touch; sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch, 1); for (SceUInt32 i=0;i<touch.reportNum;i++){ lua_pushinteger(L, lerp(touch.report[i].x, 1920, 960)); lua_pushinteger(L, lerp(touch.report[i].y, 1088, 544)); } return touch.reportNum<<1; }
void IN_Move (usercmd_t *cmd) { // ANALOGS if ((in_speed.state & 1) || always_run.value){ cl_forwardspeed.value = 400; cl_backspeed.value = 400; cl_sidespeed.value = 700; }else{ cl_forwardspeed.value = 200; cl_backspeed.value = 200; cl_sidespeed.value = 300; } sceCtrlPeekBufferPositive(0, &analogs, 1); int left_x = analogs.lx - 127; int left_y = analogs.ly - 127; int right_x = analogs.rx - 127; int right_y = analogs.ry - 127; // Left analog support for player movement int x_mov = abs(left_x) < 30 ? 0 : (left_x * cl_sidespeed.value) * 0.01; int y_mov = abs(left_y) < 30 ? 0 : (left_y * (left_y > 0 ? cl_backspeed.value : cl_forwardspeed.value)) * 0.01; cmd->forwardmove -= y_mov; cmd->sidemove += x_mov; // Right analog support for camera movement int x_cam = abs(right_x) < 50 ? 0 : right_x * sensitivity.value * 0.008; int y_cam = abs(right_y) < 50 ? 0 : right_y * sensitivity.value * 0.008; cl.viewangles[YAW] -= x_cam; V_StopPitchDrift(); if (inverted.value) cl.viewangles[PITCH] -= y_cam; else cl.viewangles[PITCH] += y_cam; // TOUCH SUPPORT // Retrotouch support for camera movement SceTouchData touch; if (retrotouch.value){ sceTouchPeek(SCE_TOUCH_PORT_BACK, &touch, 1); if (touch.reportNum > 0) { int raw_x = lerp(touch.report[0].x, 1919, 960); int raw_y = lerp(touch.report[0].y, 1087, 544); int touch_x = raw_x - 480; int touch_y = raw_y - 272; x_cam = abs(touch_x) < 20 ? 0 : touch_x * psvita_back_sensitivity_x.value * 0.008; y_cam = abs(touch_y) < 20 ? 0 : touch_y * psvita_back_sensitivity_x.value * 0.008; cl.viewangles[YAW] -= x_cam; V_StopPitchDrift(); if (inverted.value) cl.viewangles[PITCH] -= y_cam; else cl.viewangles[PITCH] += y_cam; } } if (psvita_touchmode.value == 1) { sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch, 1); if (touch.reportNum > 0) { int raw_x = lerp(touch.report[0].x, 1919, 960); int raw_y = lerp(touch.report[0].y, 1087, 544); int touch_x = raw_x - 480; int touch_y = raw_y - 272; x_cam = abs(touch_x) < 20 ? 0 : touch_x * psvita_front_sensitivity_x.value * 0.008; y_cam = abs(touch_y) < 20 ? 0 : touch_y * psvita_front_sensitivity_y.value * 0.008; cl.viewangles[YAW] -= x_cam; V_StopPitchDrift(); if (inverted.value) cl.viewangles[PITCH] -= y_cam; else cl.viewangles[PITCH] += y_cam; } } if (pq_fullpitch.value) cl.viewangles[PITCH] = COM_Clamp(cl.viewangles[PITCH], -90, 90); else cl.viewangles[PITCH] = COM_Clamp(cl.viewangles[PITCH], -70, 80); }
int main() { init_video(); /* Enable analog stick */ sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); /* Enable front touchscreen */ sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, 1); /* FPS counting */ SceUInt64 cur_micros = 0, delta_micros = 0, last_micros = 0; uint32_t frames = 0; float fps = 0.0f; /* Square variables */ int w = 60; int h = 60; int x = SCREEN_W/2 - w/2; int y = SCREEN_H/2 - h/2; int speed = 2; uint32_t color = RGBA8(255, 0, 0, 255); /* Input variables */ SceCtrlData pad; SceTouchData touch; signed char lx, ly, rx, ry; while (1) { clear_screen(); /* Read controls and touchscreen */ sceCtrlPeekBufferPositive(0, &pad, 1); sceTouchPeek(0, &touch, 1); if (pad.buttons & SCE_CTRL_START) { break; } font_draw_string(10, 10, RGBA8(0, 0, 255, 255), "PSVita sample by xerpi!"); font_draw_stringf(SCREEN_W - 160, 10, RGBA8(0, 255, 0, 255), "FPS: %.2f", fps); font_draw_stringf(10, 30, RGBA8(255, 0, 0, 255), "(%3d, %3d) size: (%d, %d) speed: %d\n", x, y, w, h, speed); /* Move the rectangle */ if (pad.buttons & SCE_CTRL_UP) { y -= speed; } else if (pad.buttons & SCE_CTRL_DOWN) { y += speed; } if (pad.buttons & SCE_CTRL_LEFT) { x -= speed; } else if (pad.buttons & SCE_CTRL_RIGHT) { x += speed; } if (pad.buttons & SCE_CTRL_LTRIGGER) { speed--; if (speed < 0) speed = 0; } else if (pad.buttons & SCE_CTRL_RTRIGGER) { speed++; if (speed > 100) speed = 100; } if (pad.buttons & SCE_CTRL_CROSS) { color = RGBA8(rand()%255, rand()%255, rand()%255, 255); } /* Update joystick values */ lx = (signed char)pad.lx - 128; ly = (signed char)pad.ly - 128; rx = (signed char)pad.rx - 128; ry = (signed char)pad.ry - 128; /* Move using the left yoystick */ if (abs(lx) > 50) { x += speed * lx/50.0f; } if (abs(ly) > 50) { y += speed * ly/50.0f; } /* Resize using the right yoystick */ if (abs(rx) > 50) { w += rx/15.0f; if (w < 5) { w = 5; } else if (w > SCREEN_W) { w = SCREEN_W; } } if (abs(ry) > 50) { h += ry/15.0f; if (h < 5) { h = 5; } if (h > SCREEN_H) { h = SCREEN_H; } } /* Move using the touchscreen! */ if (touch.reportNum > 0) { /* Front touchscreen: 1920x1088 */ x = lerp(touch.report[0].x, 1920, SCREEN_W) - w/2; y = lerp(touch.report[0].y, 1088, SCREEN_H) - h/2; } /* Check left and right collisions */ if (x < 0) { x = 0; } else if ((x + w) > SCREEN_W) { x = SCREEN_W - w; } /* Check top and bottom collisions */ if (y < 0) { y = 0; } else if ((y + h) > SCREEN_H) { y = SCREEN_H - h; } /* Draw the rectangle */ draw_rectangle(x, y, w, h, color); /* Draw a circle */ draw_circle(SCREEN_W / 2, SCREEN_H / 2, 50, RGBA8(0,0,255,255)); /* Calculate FPS */ cur_micros = sceKernelGetProcessTimeWide(); if (cur_micros >= (last_micros + 1000000)) { delta_micros = cur_micros - last_micros; last_micros = cur_micros; fps = (frames/(double)delta_micros)*1000000.0f; frames = 0; } swap_buffers(); sceDisplayWaitVblankStart(); frames++; } end_video(); sceKernelExitProcess(0); return 0; }