// // WiiMoteOpenGLDemoAppDelegate.m // // Created by Matthias Ringwald on 8/2/09. // #import "WiiMoteOpenGLDemoAppDelegate.h" #import "BTDevice.h" #import "EAGLView.h" #import "EAGLViewController.h" #import "BTInquiryViewController.h" #import #import #import BTDevice *device; uint16_t wiiMoteConHandle = 0; WiiMoteOpenGLDemoAppDelegate * theMainApp; @implementation WiiMoteOpenGLDemoAppDelegate @synthesize window; @synthesize glView; @synthesize navControl; @synthesize glViewControl; @synthesize inqViewControl; #define SIZE 5 static void bt_data_cb(uint8_t x, uint8_t y, uint8_t z){ // NSLog(@"BT data: %u %u %u", x , y ,z); // [[theMainApp status] setText:[NSString stringWithFormat:@"X:%03u Y:%03u Z:%03u", x, y, z]]; float ax = x - 128; float ay = y - 128; float az = z - 128; int roll = atan2(ax, sqrt(ay*ay+az*az)) * 180 / M_PI; int pitch = atan2(ay, sqrt(ax*ax+az*az)) * 180 / M_PI; #if 1 // moving average of size SIZE static int pos = 0; static int historyRoll[SIZE]; static int historyPitch[SIZE]; historyRoll[pos] = roll; historyPitch[pos] = pitch; pos++; if (pos==SIZE) pos = 0; pitch = roll = 0; int i; for (i=0;i