// handles firing the Machine Gun static void PFireMachineGun(int level) { Object *shot; int x, y; int dir = (player->look) ? player->look : player->dir; if (level == 0) { // level 1 is real easy! no frickin' layers!! shot = FireSimpleBullet(OBJ_POLAR_SHOT, B_MGUN_L1, 0, 0); shot->dir = dir; if (player->look) shot->xinertia = random(-0xAA, 0xAA); else shot->yinertia = random(-0xAA, 0xAA); rumble(0.2,200); } else { // drop an OBJ_MGUN_SHOOTER object to fire the layers (trail) of the MGun blast. GetPlayerShootPoint(&x, &y); FireLevel23MGun(x, y, level, dir); rumble(0.3,200); } // do machine-gun flying if (player->look==DOWN && level==2) { PMgunFly(); } }
static void PFirePolarStar(int level) { // at level 3 only two shots per screen permitted if (level < 2 || CountObjectsOfType(OBJ_POLAR_SHOT) < 2) { int xoff; if (level == 2) xoff = -5<<CSF; else xoff = -4<<CSF; FireSimpleBulletOffset(OBJ_POLAR_SHOT, B_PSTAR_L1+level, xoff, 0); rumble(0.2,200); } }
//------------------------------------------------------------------------------ void Controller::update( float dt ) { for ( int i = 0; i < static_cast<int>( XPAD_NUM_BUTTONS ); ++i ) { m_buttons[i] = m_pad.button[i].isPressed; } XenonPad()->UpdateState(); m_pad = XenonPad()->GetState(); if ( m_duration > 0.0f ) { m_duration -= dt; if ( m_duration <= 0.0f ) { rumble( 0.0f, 0.0f, 0.0f ); } } }
void level::play() { ScoreBasedEvents(); TimeBasedEvents(); if (playerShip->isAlive()) { std::list<game_object *> newdrawList; int prlife = playerShip->get_life(); newdrawList = playerShip->collisions(enemyList); if (prlife>playerShip->get_life()) { playerShip->downgradeWeapons(); rumble(); } drawableList.insert(drawableList.end(),newdrawList.begin(),newdrawList.end()); } moveAll(); playStick(); }
//------------------------------------------------------------------------------ void Controller::fini() { rumble( 0.0f, 0.0f, 0.0f ); XenonPad()->Release(); }
void DualShock::silenceRumblers() { rumble(Weak, 0); rumble(Strong, 0); }
void DualShock3::rumble(Rumbler rumbler, unsigned char intensity) { rumble(rumbler, intensity, 0xFF); }
//============================================================================= // コンストラクタ //============================================================================= CWiiController::CWiiController() : accel(0.0f, 0.0f, 0.0f), accelPrev(0.0f, 0.0f, 0.0f), accelN(0.0f, 0.0f, 0.0f), accelNPrev(0.0f, 0.0f, 0.0f), rot(0.0f, 0.0f, 0.0f), rotPrev(0.0f, 0.0f, 0.0f), rotSpeed(0.0f, 0.0f, 0.0f), rotSpeedPrev(0.0f, 0.0f, 0.0f), rotN(0.0f, 0.0f, 0.0f), rotNPrev(0.0f, 0.0f, 0.0f), joystick(0.0f, 0.0f), joystickPrev(0.0f, 0.0f), IR(0.0f, 0.0f), IRPrev(0.0f, 0.0f), LEDType(LED_0), LEDTypePrev(LED_0), LEDCounter(0), motionConnect(false), motionConnectPrev(false), rotSpeedCalibrationFlag(false), rotResetFlag(false), rotSpeedCalibrationCount(0) { // 本体を生成 wiiRemote = new wiimote(); // 試行回数 int connectTryCount = 0; std::cerr << "waiting connection... \t"; // コントローラの本体が、接続できるまでループ(回数制限あり) while (!wiiRemote->Connect()) { Sleep(10); // 一定回数、接続に失敗したら if (connectTryCount >= CONNECT_TRY_NUM) { // エラー値格納 connectTryCount = -1; MessageBox(NULL, "wiiリモコンの接続はされませんでした", "Message", MB_ICONWARNING); return; } connectTryCount++; } // リピートカウンタの初期化 for(int count = 0;count < WC_ALL;count++) repeatCount[count] = 0; // 使用するセンサを設定(ボタン、加速度、IR、エクステンション(外部接続-ヌンチャクとか)) wiiRemote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR_EXT); // スピーカーを有効にする wiiRemote->MuteSpeaker(false); wiiRemote->EnableSpeaker(true); // LEDをとりあえず全部点灯させる wiiRemote->SetLEDs(0x000F); // テスト用 rumble(true); std::cerr << "connection success" << std::endl; }
C_RESULT update_wiimote(void) { C_RESULT res = C_OK; static struct cwiid_state state,previous_state; static int control_mode = 1; static int valid_domain = 0; int8_t x, y; static int start=0; static int select=0; static vec3 a={0,0,0},s={0,0,0}; static vec3sph r={0,0,0},pr={0,0,0},rref={0,0,0}; static float pitch=0.0f,roll=0.0f,gaz=0.0f,yaw=0.0f; float tmp; static int fly=0; if (cwiid_get_state(wiimote, &state)) { fprintf(stderr, "Error getting state\n"); res = C_FAIL; } #define SWITCHING(X) ((state.buttons&X) && !(previous_state.buttons&X)) #define RELEASING(X) ((!state.buttons&X) && (previous_state.buttons&X)) #define PRESSED(X) ((state.buttons&X)) static int flag_rumble=0; #define RUMBLE_ON { if (!flag_rumble) {flag_rumble=1; } } /* Sets how to use the wiimote */ #define MAXMODE 4 if (SWITCHING(CWIID_BTN_MINUS)) { control_mode--; if (control_mode<1) control_mode=MAXMODE; leds(1<<(control_mode-1)); } if (SWITCHING(CWIID_BTN_PLUS)) { control_mode++; if (control_mode>MAXMODE) control_mode=1; leds(1<<(control_mode-1)); } /* Gets gravitation G projection on x,y,z axis */ a.x = - (float32_t) ((((double)state.acc[CWIID_X] - wm_cal.zero[CWIID_X]) / (wm_cal.one[CWIID_X] - wm_cal.zero[CWIID_X]))); a.y = - (float32_t) ((((double)state.acc[CWIID_Y] - wm_cal.zero[CWIID_Y]) / (wm_cal.one[CWIID_Y] - wm_cal.zero[CWIID_Y]))); a.z = + (float32_t) ((((double)state.acc[CWIID_Z] - wm_cal.zero[CWIID_Z]) / (wm_cal.one[CWIID_Z] - wm_cal.zero[CWIID_Z]))); s.x = (a.x<0.0f)?(1.0f):(-1.0f); s.y = (a.y<0.0f)?(1.0f):(-1.0f); s.z = (a.z<0.0f)?(1.0f):(-1.0f); float ax2 = a.x*a.x; float ay2 = a.y*a.y; float az2 = a.z*a.z; r.r = sqrtf((ax2+ay2)+az2); switch(control_mode) { case 1: case 2: if (r.r==0.0f) { r.p=r.t=0.0f; } else { // Angle gauche/droite r.p = asin(a.y); if (isnan(r.p)) r.p=0.0f; // Sur plan vertical radial r.t = acos(a.z/(sqrtf(az2+ax2))); if (isnan(r.t)) r.t=0.0f; r.t*=s.x; } break; case 3: case 4: if (r.r==0.0f) { r.p=r.t=0.0f; } else { // Angle entre le projete de G sur le plan vertical longitudinal (yz) et l'axe z r.p = acos(a.z/(sqrtf(az2+ay2))); if (isnan(r.p)) r.p=0.0f; /* If wiimote faces the ground */ //if (a.z<0.0f) r.p= M_PI-r.p; r.p*=s.y; // Idem sur le plan vertical radial r.t = acos(a.z/(sqrtf(az2+ax2))); if (isnan(r.t)) r.t=0.0f; r.t*=s.x; } break; } r.r = (r.r+pr.r)/2.0f; r.t = (r.t+pr.t)/2.0f; r.p = (r.p+pr.p)/2.0f; switch(control_mode) { case 1: case 2: /* Wiimote is handled horizontally. * '2' button under left thumb * directionnal cross under right thumb */ /* 0 -> buttons facing sky */ if ((SWITCHING(CWIID_BTN_1)||SWITCHING(CWIID_BTN_2)||SWITCHING(CWIID_BTN_B))){ rref=r; } if (PRESSED(CWIID_BTN_1)||PRESSED(CWIID_BTN_2)||PRESSED(CWIID_BTN_B)) { /* If wiimote facing ground */ if (a.z<0 && a.x>0) { rumble(1); } else { rumble(0); leds(1<<(control_mode-1)); pitch = (r.t-rref.t)*1.0f; if (pitch<-1.0f) pitch=-1.0f; if (pitch>1.0f) pitch=1.0f; roll = -(r.p-rref.p)*0.75f; if (roll<-1.0f) roll=-1.0f; if (roll>1.0f) roll=1.0f; fly=1; } } else { pitch=roll=0; rumble(0); leds(1<<(control_mode-1)); fly=0; } gaz = (PRESSED(CWIID_BTN_LEFT))? 1.0f: (PRESSED(CWIID_BTN_RIGHT)) ? -1.0f : 0.0f; yaw = (PRESSED(CWIID_BTN_DOWN))? -1.0f: (PRESSED(CWIID_BTN_UP)) ? 1.0f : (control_mode==2) ? (-pitch*roll) : 0.0f; break; case 3: case 4: if (PRESSED(CWIID_BTN_B)) { if (a.z<-0.5f) { rumble(1); } else { rumble(0); leds(1<<(control_mode-1)); pitch = -(r.p-rref.p)*1.5f; if (pitch<-1.0f) pitch=-1.0f; if (pitch>1.0f) pitch=1.0f; roll = (r.t-rref.t)*1.5f; if (roll<-1.0f) roll=-1.0f; if (roll>1.0f) roll=1.0f; fly=1; } } else { rumble(0); leds(1<<(control_mode-1)); fly=0; pitch=roll=0; } if (SWITCHING(CWIID_BTN_B)) { rref = r; } gaz = (PRESSED(CWIID_BTN_DOWN))? -1.0f: (PRESSED(CWIID_BTN_UP)) ? +1.0f : 0.0f; yaw = (PRESSED(CWIID_BTN_LEFT))? -1.0f: (PRESSED(CWIID_BTN_RIGHT)) ? 1.0f : (control_mode==4) ? (-pitch*roll) : 0.0f; } /* Buttons common to all modes */ if (SWITCHING(CWIID_BTN_A)) { start^=1; ardrone_tool_set_ui_pad_start(start); } if (SWITCHING(CWIID_BTN_HOME)) { select^=1; ardrone_tool_set_ui_pad_select(select); ardrone_tool_set_ui_pad_start(0); } // //printf("Wiimote mode 2 [ax %f][ay %f][az %f]\n\033[1A", a.x,a.y,a.z); printf("Wiimode %i [rr %3.2f][rp %3.2f][rt %3.2f]\n", control_mode,r.r,r.p,r.t); printf("[Fly %i][Ptc %3.2f][Rl %3.2f][Yw %3.2f][Gz %3.2f][Strt. %i][Sel. %i]\n\033[2A", fly,pitch,roll,yaw,gaz,start,select); ardrone_at_set_progress_cmd( fly,/*roll*/roll,/*pitch*/pitch,/*gaz*/gaz,/*yaw*/yaw); /*api_set_iphone_acceleros( (state.buttons&CWIID_BTN_2 ? 1 : 0)|(state.buttons&CWIID_BTN_A ? 2 : 0), a_x, a_y, a_z);*/ previous_state = state; pr=r; return C_OK; }