Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/libraries/core/input/WiiMote.cc @ 9917

Last change on this file since 9917 was 9917, checked in by georgr, 10 years ago

HumanController rotateRoll needs a vector as argument… the moar you know

File size: 2.6 KB
Line 
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
8namespace 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                for (int i=0; i<4; i++)
19                {
20                        if(PWii->Poll())
21                                {
22                                        switch (p->GetEvent())
23                                        {
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
27                                                        {
28                                                                //orxout()<<"fak u dolan"<<endl;
29                                                                CommandExecutor::execute("fire 0", 0, 0);
30                                                        }
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;
41                                                        break;
42                                                }
43                                                case CWiimote::EVENT_STATUS:
44                                                {
45
46                                                        break;
47                                                }
48                                                default:
49                                                        break;
50
51                                        }
52                                }
53                }
54                r/=4;
55                std::stringstream temp;
56//              temp << "scale ";
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 << "";
63//              temp << " rotateRoll";
64
65                string com = temp.str();
66                //orxout()<<com<<endl;
67                CommandExecutor::execute(com, 0, 0);
68
69                IntVector2 abs(0,0);
70                IntVector2 rel(0,0);
71                IntVector2 clippingSize(1920, 1080);
72                p->IR.GetCursorPosition(o.x, o.y);
73                //orxout() << "y: " << o.y << " x: " << o.x << endl;
74                //orxout() << p->IR.GetNumDots() << endl;
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;
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}
Note: See TracBrowser for help on using the repository browser.