1 | #include "WiiMote.h" |
---|
2 | #include "core/CoreIncludes.h" |
---|
3 | //#include "core/command/ConsoleCommand.h" |
---|
4 | #include <wiicpp/wiicpp/wiicpp.h> |
---|
5 | #include "core/command/CommandExecutor.h" |
---|
6 | |
---|
7 | |
---|
8 | namespace orxonox |
---|
9 | { |
---|
10 | |
---|
11 | const std::string WiiMote::deviceName = "WiiMote"; |
---|
12 | void WiiMote::update(const Clock& time) |
---|
13 | { |
---|
14 | if(p == NULL) |
---|
15 | exit(0); |
---|
16 | IntVector2 o(0,0); |
---|
17 | float r = 0; //roll variable |
---|
18 | if (p->ExpansionDevice.GetType()!=CExpansionDevice::TYPE_NUNCHUK) |
---|
19 | { |
---|
20 | p->UpdateStatus(); |
---|
21 | PWii->RefreshWiimotes(); |
---|
22 | } |
---|
23 | for (int i=0; i<4; i++) |
---|
24 | { |
---|
25 | if(PWii->Poll()) |
---|
26 | { |
---|
27 | switch (p->GetEvent()) |
---|
28 | { |
---|
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 |
---|
32 | { |
---|
33 | //orxout()<<"fak u dolan"<<endl; |
---|
34 | CommandExecutor::execute("fire 0", 0, 0); |
---|
35 | } |
---|
36 | if(p->Buttons.isPressed(CButtons::BUTTON_B)||p->Buttons.isJustPressed(CButtons::BUTTON_B)) |
---|
37 | CommandExecutor::execute("boost"); |
---|
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; |
---|
48 | break; |
---|
49 | } |
---|
50 | case CWiimote::EVENT_STATUS: |
---|
51 | { |
---|
52 | |
---|
53 | break; |
---|
54 | } |
---|
55 | default: |
---|
56 | break; |
---|
57 | |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | r/=4; |
---|
62 | std::stringstream temp; |
---|
63 | if (r>4.5) |
---|
64 | temp << "HumanController rotateRoll " << r/6 << ",1"; |
---|
65 | if (r<-4.5) |
---|
66 | temp << "HumanController rotateRoll "<< r/6 << ",-1"; |
---|
67 | if (r==0) |
---|
68 | temp << ""; |
---|
69 | string com = temp.str(); |
---|
70 | CommandExecutor::execute(com, 0, 0); |
---|
71 | |
---|
72 | IntVector2 abs(0,0); |
---|
73 | IntVector2 rel(0,0); |
---|
74 | IntVector2 clippingSize(1920, 1080); |
---|
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; |
---|
87 | |
---|
88 | } |
---|
89 | void WiiMote::clearBuffers() |
---|
90 | { |
---|
91 | |
---|
92 | } |
---|
93 | void WiiMote::test(int x, int y) |
---|
94 | { |
---|
95 | |
---|
96 | } |
---|
97 | WiiMote::WiiMote(unsigned int id, CWiimote & parent, CWii & parentWii) : InputDevice(id) |
---|
98 | { |
---|
99 | p = &parent; |
---|
100 | PWii = &parentWii; |
---|
101 | lastOrientation.yaw = 0; |
---|
102 | lastOrientation.roll = 0; |
---|
103 | lastOrientation.pitch = 0; |
---|
104 | lastCursor.x = 0; |
---|
105 | lastCursor.y = 0; |
---|
106 | } |
---|
107 | } |
---|