[9723] | 1 | #include "WiiMote.h" |
---|
| 2 | #include "core/CoreIncludes.h" |
---|
[9850] | 3 | //#include "core/command/ConsoleCommand.h" |
---|
[9780] | 4 | #include <wiicpp/wiicpp/wiicpp.h> |
---|
[9853] | 5 | #include "core/command/CommandExecutor.h" |
---|
[9723] | 6 | |
---|
[9850] | 7 | |
---|
[9723] | 8 | namespace orxonox |
---|
| 9 | { |
---|
| 10 | |
---|
| 11 | const std::string WiiMote::deviceName = "WiiMote"; |
---|
| 12 | void WiiMote::update(const Clock& time) |
---|
| 13 | { |
---|
[9819] | 14 | if(p == NULL) |
---|
| 15 | exit(0); |
---|
[9911] | 16 | IntVector2 o(0,0); |
---|
| 17 | float r = 0; //roll variable |
---|
[9919] | 18 | if (p->ExpansionDevice.GetType()!=CExpansionDevice::TYPE_NUNCHUK) |
---|
| 19 | { |
---|
| 20 | p->UpdateStatus(); |
---|
| 21 | PWii->RefreshWiimotes(); |
---|
| 22 | } |
---|
[9890] | 23 | for (int i=0; i<4; i++) |
---|
[9876] | 24 | { |
---|
[9890] | 25 | if(PWii->Poll()) |
---|
[9850] | 26 | { |
---|
[9890] | 27 | switch (p->GetEvent()) |
---|
[9876] | 28 | { |
---|
[9890] | 29 | case CWiimote::EVENT_EVENT: |
---|
| 30 | { |
---|
| 31 | if(p->Buttons.isPressed(CButtons::BUTTON_A)||p->Buttons.isJustPressed(CButtons::BUTTON_A)) //ugly hack to just do something on button press easily |
---|
[9911] | 32 | { |
---|
| 33 | //orxout()<<"fak u dolan"<<endl; |
---|
| 34 | CommandExecutor::execute("fire 0", 0, 0); |
---|
| 35 | } |
---|
[9919] | 36 | if(p->Buttons.isPressed(CButtons::BUTTON_B)||p->Buttons.isJustPressed(CButtons::BUTTON_B)) |
---|
| 37 | CommandExecutor::execute("boost"); |
---|
[9917] | 38 | if(p->ExpansionDevice.GetType()==CExpansionDevice::TYPE_NUNCHUK) |
---|
| 39 | { |
---|
| 40 | if(p->ExpansionDevice.Nunchuk.Buttons.isPressed(CNunchukButtons::BUTTON_C)) |
---|
| 41 | CommandExecutor::execute("NewHumanController accelerate"); |
---|
| 42 | if(p->ExpansionDevice.Nunchuk.Buttons.isPressed(CNunchukButtons::BUTTON_Z)) |
---|
| 43 | CommandExecutor::execute("NewHumanController decelerate"); |
---|
| 44 | } |
---|
| 45 | float dummyPitch, dummyYaw, dummyRoll; |
---|
| 46 | p->Accelerometer.GetOrientation(dummyPitch, dummyRoll, dummyYaw); |
---|
| 47 | r += dummyRoll; |
---|
[9890] | 48 | break; |
---|
| 49 | } |
---|
| 50 | case CWiimote::EVENT_STATUS: |
---|
| 51 | { |
---|
| 52 | |
---|
| 53 | break; |
---|
| 54 | } |
---|
| 55 | default: |
---|
| 56 | break; |
---|
| 57 | |
---|
[9876] | 58 | } |
---|
[9850] | 59 | } |
---|
[9890] | 60 | } |
---|
[9917] | 61 | r/=4; |
---|
| 62 | std::stringstream temp; |
---|
[9919] | 63 | if (r>4.5) |
---|
| 64 | temp << "HumanController rotateRoll " << r/6 << ",1"; |
---|
| 65 | if (r<-4.5) |
---|
| 66 | temp << "HumanController rotateRoll "<< r/6 << ",-1"; |
---|
[9917] | 67 | if (r==0) |
---|
| 68 | temp << ""; |
---|
| 69 | string com = temp.str(); |
---|
| 70 | CommandExecutor::execute(com, 0, 0); |
---|
| 71 | |
---|
[9890] | 72 | IntVector2 abs(0,0); |
---|
[9911] | 73 | IntVector2 rel(0,0); |
---|
[9890] | 74 | IntVector2 clippingSize(1920, 1080); |
---|
[9911] | 75 | p->IR.GetCursorPosition(o.x, o.y); |
---|
| 76 | rel.x = (o.x-lastCursor.x); |
---|
| 77 | rel.y = (o.y-lastCursor.y); |
---|
| 78 | abs.x = o.x; |
---|
| 79 | abs.y = o.y; |
---|
| 80 | if((rel.x!=0 || rel.y!=0)) |
---|
| 81 | { |
---|
| 82 | for (unsigned int i = 0; i < inputStates_.size(); ++i) |
---|
| 83 | inputStates_[i]->mouseMoved(abs, rel, clippingSize); //pass random mouse movements to all input states |
---|
| 84 | } |
---|
| 85 | lastCursor.x = o.x; |
---|
| 86 | lastCursor.y = o.y; |
---|
[9856] | 87 | |
---|
[9723] | 88 | } |
---|
| 89 | void WiiMote::clearBuffers() |
---|
| 90 | { |
---|
| 91 | |
---|
| 92 | } |
---|
| 93 | void WiiMote::test(int x, int y) |
---|
| 94 | { |
---|
| 95 | |
---|
| 96 | } |
---|
[9838] | 97 | WiiMote::WiiMote(unsigned int id, CWiimote & parent, CWii & parentWii) : InputDevice(id) |
---|
[9723] | 98 | { |
---|
[9790] | 99 | p = &parent; |
---|
[9838] | 100 | PWii = &parentWii; |
---|
[9813] | 101 | lastOrientation.yaw = 0; |
---|
| 102 | lastOrientation.roll = 0; |
---|
| 103 | lastOrientation.pitch = 0; |
---|
[9911] | 104 | lastCursor.x = 0; |
---|
| 105 | lastCursor.y = 0; |
---|
[9723] | 106 | } |
---|
| 107 | } |
---|