[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 |
---|
[9890] | 18 | for (int i=0; i<4; i++) |
---|
[9876] | 19 | { |
---|
[9890] | 20 | if(PWii->Poll()) |
---|
[9850] | 21 | { |
---|
[9890] | 22 | switch (p->GetEvent()) |
---|
[9876] | 23 | { |
---|
[9890] | 24 | case CWiimote::EVENT_EVENT: |
---|
| 25 | { |
---|
| 26 | if(p->Buttons.isPressed(CButtons::BUTTON_A)||p->Buttons.isJustPressed(CButtons::BUTTON_A)) //ugly hack to just do something on button press easily |
---|
[9911] | 27 | { |
---|
| 28 | //orxout()<<"fak u dolan"<<endl; |
---|
| 29 | CommandExecutor::execute("fire 0", 0, 0); |
---|
| 30 | } |
---|
[9917] | 31 | if(p->ExpansionDevice.GetType()==CExpansionDevice::TYPE_NUNCHUK) |
---|
| 32 | { |
---|
| 33 | if(p->ExpansionDevice.Nunchuk.Buttons.isPressed(CNunchukButtons::BUTTON_C)) |
---|
| 34 | CommandExecutor::execute("NewHumanController accelerate"); |
---|
| 35 | if(p->ExpansionDevice.Nunchuk.Buttons.isPressed(CNunchukButtons::BUTTON_Z)) |
---|
| 36 | CommandExecutor::execute("NewHumanController decelerate"); |
---|
| 37 | } |
---|
| 38 | float dummyPitch, dummyYaw, dummyRoll; |
---|
| 39 | p->Accelerometer.GetOrientation(dummyPitch, dummyRoll, dummyYaw); |
---|
| 40 | r += dummyRoll; |
---|
[9890] | 41 | break; |
---|
| 42 | } |
---|
| 43 | case CWiimote::EVENT_STATUS: |
---|
| 44 | { |
---|
| 45 | |
---|
| 46 | break; |
---|
| 47 | } |
---|
| 48 | default: |
---|
| 49 | break; |
---|
| 50 | |
---|
[9876] | 51 | } |
---|
[9850] | 52 | } |
---|
[9890] | 53 | } |
---|
[9917] | 54 | r/=4; |
---|
| 55 | std::stringstream temp; |
---|
[9911] | 56 | // temp << "scale "; |
---|
[9917] | 57 | if (r>0) |
---|
| 58 | temp << "HumanController rotateRoll 1,1"; |
---|
| 59 | if (r<0) |
---|
| 60 | temp << "HumanController rotateRoll -1,-1"; |
---|
| 61 | if (r==0) |
---|
| 62 | temp << ""; |
---|
[9911] | 63 | // temp << " rotateRoll"; |
---|
| 64 | |
---|
[9917] | 65 | string com = temp.str(); |
---|
| 66 | //orxout()<<com<<endl; |
---|
| 67 | CommandExecutor::execute(com, 0, 0); |
---|
| 68 | |
---|
[9890] | 69 | IntVector2 abs(0,0); |
---|
[9911] | 70 | IntVector2 rel(0,0); |
---|
[9890] | 71 | IntVector2 clippingSize(1920, 1080); |
---|
[9911] | 72 | p->IR.GetCursorPosition(o.x, o.y); |
---|
[9917] | 73 | //orxout() << "y: " << o.y << " x: " << o.x << endl; |
---|
| 74 | //orxout() << p->IR.GetNumDots() << endl; |
---|
[9911] | 75 | rel.x = (o.x-lastCursor.x); |
---|
| 76 | rel.y = (o.y-lastCursor.y); |
---|
| 77 | abs.x = o.x; |
---|
| 78 | abs.y = o.y; |
---|
| 79 | if((rel.x!=0 || rel.y!=0)) |
---|
| 80 | { |
---|
| 81 | for (unsigned int i = 0; i < inputStates_.size(); ++i) |
---|
| 82 | inputStates_[i]->mouseMoved(abs, rel, clippingSize); //pass random mouse movements to all input states |
---|
| 83 | } |
---|
| 84 | lastCursor.x = o.x; |
---|
| 85 | lastCursor.y = o.y; |
---|
| 86 | lastOrientation.roll = r; |
---|
[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 | } |
---|